diff --git a/src/card/Card.java b/src/card/Card.java index 83c2c26..0eabbad 100644 --- a/src/card/Card.java +++ b/src/card/Card.java @@ -1,5 +1,5 @@ package card; -import game.Game; +import game.AbstractGame; import java.awt.Color; @@ -16,9 +16,9 @@ protected int color; protected int value; protected int playerId; - protected Game g; + protected AbstractGame g; - public Card(int color, int value, int playerId, Game g){ + public Card(int color, int value, int playerId, AbstractGame g){ this.color = color; this.value = value; this.playerId = playerId; diff --git a/src/card/SwingCard.java b/src/card/SwingCard.java index e6ebd31..b2432cb 100644 --- a/src/card/SwingCard.java +++ b/src/card/SwingCard.java @@ -1,6 +1,6 @@ package card; -import game.Game; +import game.SwingGame; import java.awt.Color; import java.awt.event.MouseEvent; @@ -12,14 +12,13 @@ public class SwingCard extends Card { JLabel face; - public SwingCard(int color, int value, int playerId, Game g) { - super(color, value, playerId, g); + public SwingCard(int color, int value, int playerId, SwingGame swingGame) { + super(color, value, playerId, swingGame); } public void setFace(JLabel face){ this.face = face; face.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); - //uiCards[i].setHorizontalAlignment(SwingConstants.CENTER); face.setFont(g.getFont().deriveFont(g.getFontSize()*2)); addMouseListener(); } @@ -27,7 +26,6 @@ public JLabel getFace(){ return face; } - private void addMouseListener(){ face.addMouseListener(new MouseListener() { @@ -42,19 +40,19 @@ } } if(!g.isUseColor() && !g.isUseValue() && !g.isTrashCard() && !g.isPlaceCard()){ - //System.out.println("Please choose move type first"); + g.printMessage("Please choose move type first", 0); return; } if(playerId == g.getCurrentPlayerIndex()){ if(g.isUseColor() || g.isUseValue()){ - //System.out.println("Please don't select your own cards!"); + g.printMessage("Please don't select your own cards!", 0); return; } else if((g.isTrashCard() || g.isPlaceCard()) && g.getSelectedCards() == 1){ - //System.out.println("You already selected a card!"); + g.printMessage("You already selected a card!", 0); return; } } else if(playerId != g.getCurrentPlayerIndex() && (g.isTrashCard() || g.isPlaceCard())){ - //System.out.println("Please select your own cards"); + g.printMessage("Please select your own cards", 0); return; } if(g.getSelectedPlayer() == -1){ @@ -66,7 +64,7 @@ return; } if(g.getSelectedPlayer() != playerId){ - //System.out.println("Please choose a card of the selected player or unselect all cards and choose another player."); + g.printMessage("Please choose a card of the selected player or unselect all cards and choose another player.", 0); return; } if(g.getChosenColor() == -1){ diff --git a/src/game/AbstractGame.java b/src/game/AbstractGame.java index a591202..983b29f 100644 --- a/src/game/AbstractGame.java +++ b/src/game/AbstractGame.java @@ -1,5 +1,324 @@ package game; +import player.AbstractPlayer; -public class AbstractGame { +import java.awt.Font; +import java.awt.Point; +import java.io.File; +import java.io.IOException; +import java.net.MalformedURLException; +import java.util.ArrayList; -} +import org.json.*; + +import card.Card; + +public abstract class AbstractGame { + /* + * 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; + 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; + ArrayList cards; + Card[][] deck; + int[] deckCounter; + ArrayList trash; + AbstractPlayer[] players; + int currentPlayer; + + int selectedPlayer; + int selectedCards; + int chosenColor; + int chosenValue; + boolean useColor; + boolean useValue; + boolean placeCard; + boolean trashCard; + boolean won; + boolean lost; + + Font font; + + //Options stuff + final File options = new File("options.json"); + JSONObject root; + int difficulty; + int fontSize; + + /*public static void main(String[] args) { + AbstractGame game = new AbstractGame(); + game.getPlayer(game.currentPlayer).deactiveCards(); + System.out.println("Player " + game.currentPlayer + "'s turn"); + }*/ + + public AbstractGame(){ + init(); + } + + protected void init(){ + loadOptions(); + loadFont(); + CARDS_PER_PLAYER = (NR_PLAYERS < 3) ? 5 : 4; + hints = MAX_HINTS; + thunders = 0; + createPlayers(); + currentPlayer = 0; + resetMoveValues(); + addCards(); + CARDS_IN_DECK = cards.size(); + createUI(); + dealCards(); + } + + protected void loadOptions(){ + try { + JSONTokener tokener = new JSONTokener(options.toURI().toURL().openStream()); + root = new JSONObject(tokener); + difficulty = root.getInt("difficulty"); + fontSize = root.getInt("fontSize"); + if(difficulty < 0) difficulty = 0; + if(fontSize <= 0) fontSize = 20; + System.out.println("FontSize: " + fontSize); + System.out.println("Difficulty: " + difficulty); + } catch (JSONException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (MalformedURLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + public void resetMoveValues(){ + selectedPlayer = -1; + chosenColor = -1; + chosenValue = -1; + selectedCards = 0; + useColor = useValue = trashCard = placeCard = false; + } + + protected void createPlayers(){ + players = new AbstractPlayer[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 0){ + int index = random(CARDS_IN_DECK--); + card = cards.remove(index); + } else { + card = new Card(3, -1, playerID, this); + } + players[playerID].setCard(cardID, card); + } + + protected void dealCards(){ + int dealtCards = 0; + for(; dealtCards < CARDS_PER_PLAYER; ++dealtCards){ + for(int i=0; i 0); + } + + void setWonOrLost(){ + won = true; + lost = false; + for(int i=0; i cards; - Card[][] deck; - int[] deckCounter; - ArrayList trash; - AbstractPlayer[] players; - int currentPlayer; - - int selectedPlayer; - int selectedCards; - int chosenColor; - int chosenValue; - boolean useColor; - boolean useValue; - boolean placeCard; - boolean trashCard; - boolean won; - boolean lost; - - //UI STUFF - JFrame mainFrame; - JPanel gamePanel; - JPanel hintPanel; - JPanel thunderPanel; - JPanel buttonPanel; - JPanel deckPanel; - JLabel[][] deckUI; - JButton colorButton; - JButton valueButton; - JButton nextMove; - JButton placeCardButton; - JButton trashCardButton; - JLabel[] hintUI; - JLabel[] thunderUI; - JPanel[] playersUI; - Font font; - - //Options stuff - final File options = new File("options.json"); - JSONObject root; - int difficulty; - int fontSize; - - public static void main(String[] args) { - Game game = new Game(); - game.getPlayer(game.currentPlayer).deactiveCards(); - System.out.println("Player " + game.currentPlayer + "'s turn"); - } - - public Game(){ - init(); - } - - private void init(){ - loadOptions(); - font = new Font("Shanghai", Font.PLAIN, fontSize); - CARDS_PER_PLAYER = (NR_PLAYERS < 3) ? 5 : 4; - hints = MAX_HINTS; - thunders = 0; - createPlayers(); - currentPlayer = 0; - resetMoveValues(); - addCards(); - CARDS_IN_DECK = cards.size(); - createUI(); - dealCards(); - } - - private void loadOptions(){ - try { - JSONTokener tokener = new JSONTokener(options.toURI().toURL().openStream()); - root = new JSONObject(tokener); - difficulty = root.getInt("difficulty"); - fontSize = root.getInt("fontSize"); - if(difficulty < 0) difficulty = 0; - if(fontSize <= 0) fontSize = 20; - System.out.println("FontSize: " + fontSize); - System.out.println("Difficulty: " + difficulty); - } catch (JSONException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (MalformedURLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - public void resetMoveValues(){ - selectedPlayer = -1; - chosenColor = -1; - chosenValue = -1; - selectedCards = 0; - useColor = useValue = trashCard = placeCard = false; - } - - private void createPlayers(){ - players = new AbstractPlayer[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 0){ - System.out.println("Please deselect all cards first"); - return; - } - useColor = true; - useValue = false; - placeCard = false; - trashCard = false; - } - @Override - public void mousePressed(MouseEvent e) { - } - @Override - public void mouseExited(MouseEvent e) { - } - @Override - public void mouseEntered(MouseEvent e) { - } - @Override - public void mouseClicked(MouseEvent e) { - } - }); - valueButton.addMouseListener(new MouseListener(){ - @Override - public void mouseReleased(MouseEvent e) { - if(!hintAvailable()){ - System.out.println("No hints left!"); - return; - } - if(selectedCards > 0){ - System.out.println("Please deselect all cards first"); - return; - } - useValue = true; - useColor = false; - placeCard = false; - trashCard = false; - } - @Override - public void mousePressed(MouseEvent e) { - } - @Override - public void mouseExited(MouseEvent e) { - } - @Override - public void mouseEntered(MouseEvent e) { - } - @Override - public void mouseClicked(MouseEvent e) { - } - }); - nextMove.addMouseListener(new MouseListener(){ - @Override - public void mouseReleased(MouseEvent e) { - if(!checkValidMove()){ - System.out.println("Please select all cards of the selected color/value"); - return; - } - int selCardIndex = 0; - for(int i=0; i MAX_HINTS) hints = MAX_HINTS; - } - } else if(placeCard){ - Card c = players[currentPlayer].getCard(selCardIndex); - int color = c.getColorInt(); - int value = c.getValue(); - int deckValue = deckCounter[color] + 1; - if(deckValue == value){ //place card possible - deckCounter[color]++; - deck[color][value-1] = c; - deckUI[color][value-1].setText(value + ""); - deckUI[color][value-1].setForeground(c.getColor()); - setWonOrLost(); - } else { //card too high or too low - thunderUI[thunders++].setText("1"); - moveCardToTrash(selCardIndex); - setWonOrLost(); - if(lost) return; - } - //dealCard(selCardIndex, currentPlayer); - updateCards(selCardIndex); - } - players[currentPlayer].activeCards(); - System.out.println("Player " + currentPlayer + " has finished his move!"); - currentPlayer++; - if(currentPlayer == NR_PLAYERS) currentPlayer = 0; - players[currentPlayer].deactiveCards(); - resetMoveValues(); - System.out.println(CARDS_IN_DECK + " cards left."); - System.out.println(trash.size() + " cards in trash"); - System.out.println("Player " + currentPlayer + "'s turn"); - } - @Override - public void mousePressed(MouseEvent e) { - } - @Override - public void mouseExited(MouseEvent e) { - } - @Override - public void mouseEntered(MouseEvent e) { - } - @Override - public void mouseClicked(MouseEvent e) { - } - }); - trashCardButton.addMouseListener(new MouseListener(){ - @Override - public void mouseReleased(MouseEvent e) { - if(selectedCards > 0){ - System.out.println("Please deselect all cards first"); - return; - } - useColor = false; - useValue = false; - placeCard = false; - trashCard = true; - } - @Override - public void mousePressed(MouseEvent e) { - } - @Override - public void mouseExited(MouseEvent e) { - } - @Override - public void mouseEntered(MouseEvent e) { - } - @Override - public void mouseClicked(MouseEvent e) { - } - }); - placeCardButton.addMouseListener(new MouseListener(){ - @Override - public void mouseReleased(MouseEvent e) { - if(selectedCards > 0){ - System.out.println("Please deselect all cards first"); - return; - } - useColor = false; - useValue = false; - placeCard = true; - trashCard = false; - } - @Override - public void mousePressed(MouseEvent e) { - } - @Override - public void mouseExited(MouseEvent e) { - } - @Override - public void mouseEntered(MouseEvent e) { - } - @Override - public void mouseClicked(MouseEvent e) { - } - }); - } - - private void moveCardToTrash(int index){ - trash.add(players[currentPlayer].getCard(index)); - updateCards(index); - } - - private void updateCards(int index){ - dealCard(index, currentPlayer); - players[currentPlayer].setCardInfo(index, ""); - Card c = players[currentPlayer].getCard(index); - //JLabel card = ((SwingPlayer) players[currentPlayer]).getUiCard(index); - AbstractPlayer card = players[currentPlayer]; - if(c.getValue() == -1){ //dummy card, no more cards - card.setColor(index, 255, 122, 0); - card.setText(index, "No Cards left"); - card.unsetListeners(index); - } - } - - private void dealCard(int cardID, int playerID){ - SwingCard card; - if(CARDS_IN_DECK > 0){ - int index = random(CARDS_IN_DECK--); - card = (SwingCard) cards.remove(index); - } else { - card = new SwingCard(3, -1, playerID, this); - } - players[playerID].setCard(cardID, card); - } - - private void dealCards(){ - int dealtCards = 0; - for(; dealtCards < CARDS_PER_PLAYER; ++dealtCards){ - for(int i=0; i 0); - } - - private void setWonOrLost(){ - won = true; - lost = false; - for(int i=0; i cards; +// Card[][] deck; +// int[] deckCounter; +// ArrayList trash; +// AbstractPlayer[] players; +// int currentPlayer; +// +// int selectedPlayer; +// int selectedCards; +// int chosenColor; +// int chosenValue; +// boolean useColor; +// boolean useValue; +// boolean placeCard; +// boolean trashCard; +// boolean won; +// boolean lost; +// +// //UI STUFF +// JFrame mainFrame; +// JPanel gamePanel; +// JPanel hintPanel; +// JPanel thunderPanel; +// JPanel buttonPanel; +// JPanel deckPanel; +// JLabel[][] deckUI; +// JButton colorButton; +// JButton valueButton; +// JButton nextMove; +// JButton placeCardButton; +// JButton trashCardButton; +// JLabel[] hintUI; +// JLabel[] thunderUI; +// JPanel[] playersUI; +// Font font; +// +// //Options stuff +// final File options = new File("options.json"); +// JSONObject root; +// int difficulty; +// int fontSize; +// +// public static void main(String[] args) { +// Game game = new Game(); +// game.getPlayer(game.currentPlayer).deactiveCards(); +// System.out.println("Player " + game.currentPlayer + "'s turn"); +// } +// +// public Game(){ +// init(); +// } +// +// private void init(){ +// loadOptions(); +// font = new Font("Shanghai", Font.PLAIN, fontSize); +// CARDS_PER_PLAYER = (NR_PLAYERS < 3) ? 5 : 4; +// hints = MAX_HINTS; +// thunders = 0; +// createPlayers(); +// currentPlayer = 0; +// resetMoveValues(); +// addCards(); +// CARDS_IN_DECK = cards.size(); +// createUI(); +// dealCards(); +// } +// +// private void loadOptions(){ +// try { +// JSONTokener tokener = new JSONTokener(options.toURI().toURL().openStream()); +// root = new JSONObject(tokener); +// difficulty = root.getInt("difficulty"); +// fontSize = root.getInt("fontSize"); +// if(difficulty < 0) difficulty = 0; +// if(fontSize <= 0) fontSize = 20; +// System.out.println("FontSize: " + fontSize); +// System.out.println("Difficulty: " + difficulty); +// } catch (JSONException e) { +// // TODO Auto-generated catch block +// e.printStackTrace(); +// } catch (MalformedURLException e) { +// // TODO Auto-generated catch block +// e.printStackTrace(); +// } catch (IOException e) { +// // TODO Auto-generated catch block +// e.printStackTrace(); +// } +// } +// +// public void resetMoveValues(){ +// selectedPlayer = -1; +// chosenColor = -1; +// chosenValue = -1; +// selectedCards = 0; +// useColor = useValue = trashCard = placeCard = false; +// } +// +// private void createPlayers(){ +// players = new AbstractPlayer[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 0){ +// System.out.println("Please deselect all cards first"); +// return; +// } +// useColor = true; +// useValue = false; +// placeCard = false; +// trashCard = false; +// } +// @Override +// public void mousePressed(MouseEvent e) { +// } +// @Override +// public void mouseExited(MouseEvent e) { +// } +// @Override +// public void mouseEntered(MouseEvent e) { +// } +// @Override +// public void mouseClicked(MouseEvent e) { +// } +// }); +// valueButton.addMouseListener(new MouseListener(){ +// @Override +// public void mouseReleased(MouseEvent e) { +// if(!hintAvailable()){ +// System.out.println("No hints left!"); +// return; +// } +// if(selectedCards > 0){ +// System.out.println("Please deselect all cards first"); +// return; +// } +// useValue = true; +// useColor = false; +// placeCard = false; +// trashCard = false; +// } +// @Override +// public void mousePressed(MouseEvent e) { +// } +// @Override +// public void mouseExited(MouseEvent e) { +// } +// @Override +// public void mouseEntered(MouseEvent e) { +// } +// @Override +// public void mouseClicked(MouseEvent e) { +// } +// }); +// nextMove.addMouseListener(new MouseListener(){ +// @Override +// public void mouseReleased(MouseEvent e) { +// if(!checkValidMove()){ +// System.out.println("Please select all cards of the selected color/value"); +// return; +// } +// int selCardIndex = 0; +// for(int i=0; i MAX_HINTS) hints = MAX_HINTS; +// } +// } else if(placeCard){ +// Card c = players[currentPlayer].getCard(selCardIndex); +// int color = c.getColorInt(); +// int value = c.getValue(); +// int deckValue = deckCounter[color] + 1; +// if(deckValue == value){ //place card possible +// deckCounter[color]++; +// deck[color][value-1] = c; +// deckUI[color][value-1].setText(value + ""); +// deckUI[color][value-1].setForeground(c.getColor()); +// setWonOrLost(); +// } else { //card too high or too low +// thunderUI[thunders++].setText("1"); +// moveCardToTrash(selCardIndex); +// setWonOrLost(); +// if(lost) return; +// } +// //dealCard(selCardIndex, currentPlayer); +// updateCards(selCardIndex); +// } +// players[currentPlayer].activeCards(); +// System.out.println("Player " + currentPlayer + " has finished his move!"); +// currentPlayer++; +// if(currentPlayer == NR_PLAYERS) currentPlayer = 0; +// players[currentPlayer].deactiveCards(); +// resetMoveValues(); +// System.out.println(CARDS_IN_DECK + " cards left."); +// System.out.println(trash.size() + " cards in trash"); +// System.out.println("Player " + currentPlayer + "'s turn"); +// } +// @Override +// public void mousePressed(MouseEvent e) { +// } +// @Override +// public void mouseExited(MouseEvent e) { +// } +// @Override +// public void mouseEntered(MouseEvent e) { +// } +// @Override +// public void mouseClicked(MouseEvent e) { +// } +// }); +// trashCardButton.addMouseListener(new MouseListener(){ +// @Override +// public void mouseReleased(MouseEvent e) { +// if(selectedCards > 0){ +// System.out.println("Please deselect all cards first"); +// return; +// } +// useColor = false; +// useValue = false; +// placeCard = false; +// trashCard = true; +// } +// @Override +// public void mousePressed(MouseEvent e) { +// } +// @Override +// public void mouseExited(MouseEvent e) { +// } +// @Override +// public void mouseEntered(MouseEvent e) { +// } +// @Override +// public void mouseClicked(MouseEvent e) { +// } +// }); +// placeCardButton.addMouseListener(new MouseListener(){ +// @Override +// public void mouseReleased(MouseEvent e) { +// if(selectedCards > 0){ +// System.out.println("Please deselect all cards first"); +// return; +// } +// useColor = false; +// useValue = false; +// placeCard = true; +// trashCard = false; +// } +// @Override +// public void mousePressed(MouseEvent e) { +// } +// @Override +// public void mouseExited(MouseEvent e) { +// } +// @Override +// public void mouseEntered(MouseEvent e) { +// } +// @Override +// public void mouseClicked(MouseEvent e) { +// } +// }); +// } +// +// private void moveCardToTrash(int index){ +// trash.add(players[currentPlayer].getCard(index)); +// updateCards(index); +// } +// +// private void updateCards(int index){ +// dealCard(index, currentPlayer); +// players[currentPlayer].setCardInfo(index, ""); +// Card c = players[currentPlayer].getCard(index); +// //JLabel card = ((SwingPlayer) players[currentPlayer]).getUiCard(index); +// AbstractPlayer card = players[currentPlayer]; +// if(c.getValue() == -1){ //dummy card, no more cards +// card.setColor(index, 255, 122, 0); +// card.setText(index, "No Cards left"); +// card.unsetListeners(index); +// } +// } +// +// private void dealCard(int cardID, int playerID){ +// SwingCard card; +// if(CARDS_IN_DECK > 0){ +// int index = random(CARDS_IN_DECK--); +// card = (SwingCard) cards.remove(index); +// } else { +// card = new SwingCard(3, -1, playerID, this); +// } +// players[playerID].setCard(cardID, card); +// } +// +// private void dealCards(){ +// int dealtCards = 0; +// for(; dealtCards < CARDS_PER_PLAYER; ++dealtCards){ +// for(int i=0; i 0); +// } +// +// private void setWonOrLost(){ +// won = true; +// lost = false; +// for(int i=0; i 0){ + printMessage("Please deselect all cards first", 0); + return; + } + useColor = true; + useValue = false; + placeCard = false; + trashCard = false; + } + @Override + public void mousePressed(MouseEvent e) { + } + @Override + public void mouseExited(MouseEvent e) { + } + @Override + public void mouseEntered(MouseEvent e) { + } + @Override + public void mouseClicked(MouseEvent e) { + } + }); + valueButton.addMouseListener(new MouseListener(){ + @Override + public void mouseReleased(MouseEvent e) { + if(!hintAvailable()){ + printMessage("No hints left!", 1); + return; + } + if(selectedCards > 0){ + printMessage("Please deselect all cards first", 0); + return; + } + useValue = true; + useColor = false; + placeCard = false; + trashCard = false; + } + @Override + public void mousePressed(MouseEvent e) { + } + @Override + public void mouseExited(MouseEvent e) { + } + @Override + public void mouseEntered(MouseEvent e) { + } + @Override + public void mouseClicked(MouseEvent e) { + } + }); + nextMove.addMouseListener(new MouseListener(){ + @Override + public void mouseReleased(MouseEvent e) { + if(!checkValidMove()){ + printMessage("Please select all cards of the selected color/value", 0); + return; + } + int selCardIndex = 0; + for(int i=0; i MAX_HINTS) hints = MAX_HINTS; + } + } else if(placeCard){ + Card c = players[currentPlayer].getCard(selCardIndex); + int color = c.getColorInt(); + int value = c.getValue(); + int deckValue = deckCounter[color] + 1; + if(deckValue == value){ //place card possible + deckCounter[color]++; + deck[color][value-1] = c; + deckUI[color][value-1].setText(value + ""); + deckUI[color][value-1].setForeground(c.getColor()); + setWonOrLost(); + } else { //card too high or too low + thunderUI[thunders++].setText("1"); + moveCardToTrash(selCardIndex); + setWonOrLost(); + if(lost) return; + } + //dealCard(selCardIndex, currentPlayer); + updateCards(selCardIndex); + } + players[currentPlayer].activeCards(); + printMessage("Player " + currentPlayer + " has finished his move!", 1); + currentPlayer++; + if(currentPlayer == NR_PLAYERS) currentPlayer = 0; + players[currentPlayer].deactiveCards(); + resetMoveValues(); + //System.out.println(CARDS_IN_DECK + " cards left."); + //System.out.println(trash.size() + " cards in trash"); + //System.out.println("Player " + currentPlayer + "'s turn"); + } + @Override + public void mousePressed(MouseEvent e) { + } + @Override + public void mouseExited(MouseEvent e) { + } + @Override + public void mouseEntered(MouseEvent e) { + } + @Override + public void mouseClicked(MouseEvent e) { + } + }); + trashCardButton.addMouseListener(new MouseListener(){ + @Override + public void mouseReleased(MouseEvent e) { + if(selectedCards > 0){ + printMessage("Please deselect all cards first", 0); + return; + } + useColor = false; + useValue = false; + placeCard = false; + trashCard = true; + } + @Override + public void mousePressed(MouseEvent e) { + } + @Override + public void mouseExited(MouseEvent e) { + } + @Override + public void mouseEntered(MouseEvent e) { + } + @Override + public void mouseClicked(MouseEvent e) { + } + }); + placeCardButton.addMouseListener(new MouseListener(){ + @Override + public void mouseReleased(MouseEvent e) { + if(selectedCards > 0){ + printMessage("Please deselect all cards first", 0); + return; + } + useColor = false; + useValue = false; + placeCard = true; + trashCard = false; + } + @Override + public void mousePressed(MouseEvent e) { + } + @Override + public void mouseExited(MouseEvent e) { + } + @Override + public void mouseEntered(MouseEvent e) { + } + @Override + public void mouseClicked(MouseEvent e) { + } + }); + } + + @Override + protected void dealCards(){ + /* + * PLAYER 0: SOUTH + * PLAYER 1: EAST + * PLAYER 2: NORTH + * PLAYER 3: WEST + */ + for(int i=0; i