diff --git a/README.md b/README.md index 2f7250c..a996b69 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,9 @@ -hanabi +Hanabi =============== -hanabi game, written in java \ No newline at end of file +Description +--------------- +Hanabi game client written in java. +It currently only supports playing on the same machine. + +For the future a network based client is planned. \ No newline at end of file diff --git a/src/Card.java b/src/Card.java new file mode 100644 index 0000000..99c50f9 --- /dev/null +++ b/src/Card.java @@ -0,0 +1,50 @@ +import java.awt.Color; + +/* + * COLORS: + * GREEN + * RED + * YELLOW + * WHITE + * BLUE + * (COLORED) + */ +public class Card { + private int color; + private int value; + + public Card(int color, int value){ + this.color = color; + this.value = value; + } + + public Color getColor(){ + Color c = null; + switch(color){ + case 0: + c = Color.green; + break; + case 1: + c = Color.red; + break; + case 2: + c = Color.yellow; + break; + case 3: + c = Color.white; + break; + case 4: + c = Color.blue; + break; + } + return c; + } + + public int getColorInt(){ + return color; + } + + public int getValue(){ + return value; + } +} diff --git a/src/Game.java b/src/Game.java new file mode 100644 index 0000000..6e61910 --- /dev/null +++ b/src/Game.java @@ -0,0 +1,415 @@ +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.FlowLayout; +import java.awt.Font; +import java.awt.Point; +import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.util.ArrayList; + +import javax.swing.BorderFactory; +import javax.swing.Box; +import javax.swing.BoxLayout; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.SwingConstants; +import javax.swing.UIManager; +import javax.swing.UnsupportedLookAndFeelException; +import javax.swing.border.Border; + + +public class Game { + /* + * COLORS: + * GREEN + * RED + * YELLOW + * WHITE + * BLUE + * (COLORED) + */ + final static int GREEN = 0; + final static int RED = 1; + final static int YELLOW = 2; + final static int WHITE = 3; + final static int BLUE = 4; + final static int COLORS = 5; + final static int NR_PLAYERS = 2; + static int CARDS_PER_PLAYER; + final static int NR_OF_CARDS = 50; + static int CARDS_IN_DECK; + final static int MAX_HINTS = 8; + final static int MAX_THUNDERS = 3; + int hints; + int thunders; + static ArrayList cards; + static Card[][] deck; + static int[] deckCounter; + static ArrayList trash; + static Player[] players; + static JPanel[] playersUI; + static int currentPlayer; + static boolean won; + static boolean moveFinished; + + static int selectedPlayer; + static int selectedCards; + static int chosenColor; + static int chosenValue; + static boolean useColor; + static boolean useValue; + + //UI STUFF + JFrame mainFrame; + + + public static void main(String[] args) { + Game game = new Game(); + System.out.println("Player " + currentPlayer + "'s turn"); + } + + public Game(){ + init(); + } + + private void init(){ + CARDS_PER_PLAYER = (NR_PLAYERS < 3) ? 5 : 4; + hints = MAX_HINTS; + thunders = 0; + createPlayers(); + currentPlayer = 0; + won = false; + resetMoveValues(); + addCards(); + CARDS_IN_DECK = cards.size(); + createUI(); + dealCards(); + } + + private void resetMoveValues(){ + moveFinished = false; + selectedPlayer = -1; + chosenColor = -1; + chosenValue = -1; + selectedCards = 0; + useColor = useValue = false; + } + + private void createPlayers(){ + players = new Player[NR_PLAYERS]; + playersUI = new JPanel[NR_PLAYERS]; + for(int i=0; i(); + deck = new Card[COLORS][5]; + deckCounter = new int[5]; + trash = new ArrayList<>(); + int[] dist = new int[]{3, 2, 2, 2, 1}; + int[][] tmp_cards = new int[][]{ + dist.clone(), + dist.clone(), + dist.clone(), + dist.clone(), + dist.clone() + }; + for(int i=0; i select all 4's + } else if(chosenValue != clickedValue && chosenColor == clickedColor){ + //chosenValue = -2; + useColor = true; + //TODO same color => select all reds + } + } + if(label.getBackground() == Color.pink){ + selectedCards--; + label.setBackground(Color.black); + System.out.println("Removed card #" + clickedCard + "(" + card.getColorInt() + ", " + card.getValue() + ")"); + if(selectedCards == 0){ + resetMoveValues(); + } else if(selectedCards == 1){ + useColor = useValue = false; + } + } else { + if(useColor){ + if(chosenColor == clickedColor){ + //TODO add card + //selectedCards.add(clickedCard); + if(label.getBackground() != Color.pink){ + selectedCards++; + label.setBackground(Color.pink); + System.out.println("Added card #" + clickedCard + "(" + card.getColorInt() + ", " + card.getValue() + ")"); + } + } + } else if(useValue){ + if(chosenValue == clickedValue){ + //TODO add card + //selectedCards.add(clickedCard); + if(label.getBackground() != Color.pink){ + selectedCards++; + label.setBackground(Color.pink); + System.out.println("Added card #" + clickedCard + "(" + card.getColorInt() + ", " + card.getValue() + ")"); + } + } + } + } + } + + @Override + public void mousePressed(MouseEvent e) { + } + + @Override + public void mouseExited(MouseEvent e) { + } + + @Override + public void mouseEntered(MouseEvent e) { + } + + @Override + public void mouseClicked(MouseEvent e) { + } + }); + playerContainer.add(curr, playerSide); + playerContainer.add(Box.createRigidArea(new Dimension(15,15))); + } + mainFrame.add(playerContainer, playerSide); + } + } + + private Point randomPosition(){ + Point p = new Point(); + p.x = random(5); + p.y = random(5); + return p; + } + + private int random(int max){ + return (int) (Math.random() * max); + } + + private void printArray(int[][] arr){ + for(int j=0; j