diff --git a/src/card/SwingCard.java b/src/card/SwingCard.java index b2432cb..1079316 100644 --- a/src/card/SwingCard.java +++ b/src/card/SwingCard.java @@ -1,8 +1,10 @@ package card; import game.SwingGame; +import game.AbstractGame.MSG_TYPES; import java.awt.Color; +import java.awt.Font; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; @@ -19,7 +21,7 @@ public void setFace(JLabel face){ this.face = face; face.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); - face.setFont(g.getFont().deriveFont(g.getFontSize()*2)); + face.setFont(((Font) g.getFont()).deriveFont(g.getFontSize()*2)); addMouseListener(); } @@ -40,19 +42,19 @@ } } if(!g.isUseColor() && !g.isUseValue() && !g.isTrashCard() && !g.isPlaceCard()){ - g.printMessage("Please choose move type first", 0); + g.printMessage("Please choose move type first", MSG_TYPES.ERROR); return; } if(playerId == g.getCurrentPlayerIndex()){ if(g.isUseColor() || g.isUseValue()){ - g.printMessage("Please don't select your own cards!", 0); + g.printMessage("Please don't select your own cards!", MSG_TYPES.ERROR); return; } else if((g.isTrashCard() || g.isPlaceCard()) && g.getSelectedCards() == 1){ - g.printMessage("You already selected a card!", 0); + g.printMessage("You already selected a card!", MSG_TYPES.ERROR); return; } } else if(playerId != g.getCurrentPlayerIndex() && (g.isTrashCard() || g.isPlaceCard())){ - g.printMessage("Please select your own cards", 0); + g.printMessage("Please select your own cards", MSG_TYPES.ERROR); return; } if(g.getSelectedPlayer() == -1){ @@ -64,7 +66,7 @@ return; } if(g.getSelectedPlayer() != playerId){ - g.printMessage("Please choose a card of the selected player or unselect all cards and choose another player.", 0); + g.printMessage("Please choose a card of the selected player or unselect all cards and choose another player.", MSG_TYPES.ERROR); return; } if(g.getChosenColor() == -1){ diff --git a/src/game/AbstractGame.java b/src/game/AbstractGame.java index 2fedc1b..248e22b 100644 --- a/src/game/AbstractGame.java +++ b/src/game/AbstractGame.java @@ -1,7 +1,6 @@ package game; import player.AbstractPlayer; -import java.awt.Font; import java.awt.Point; import java.io.DataInputStream; import java.io.DataOutputStream; @@ -27,16 +26,20 @@ * BLUE * (COLORED) */ + + public enum MSG_TYPES {ERROR, WARNING, INFORMATION, QUESTION}; + 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 COLORED = 5; final static int COLORS = 5; - int NR_PLAYERS = 2; + int N_PLAYERS = 2; static int CARDS_PER_PLAYER; - final static int NR_OF_CARDS = 50; - static int CARDS_IN_DECK; + final static int N_CARDS = 50; + int CARDS_IN_DECK; final static int MAX_HINTS = 8; final static int MAX_THUNDERS = 3; int hints; @@ -47,6 +50,7 @@ ArrayList trash; AbstractPlayer[] players; int currentPlayer; + int roundsLeft; int selectedPlayer; int selectedCards; @@ -59,8 +63,6 @@ boolean won; boolean lost; - Font font; - //Options stuff final File options = new File("options.json"); JSONObject root; @@ -85,10 +87,11 @@ protected void init(){ loadOptions(); loadFont(); - establishConnection(); - CARDS_PER_PLAYER = (NR_PLAYERS < 3) ? 5 : 4; + //establishConnection(); + CARDS_PER_PLAYER = (N_PLAYERS < 3) ? 5 : 4; hints = MAX_HINTS; thunders = 0; + roundsLeft = -1; createPlayers(); currentPlayer = 0; resetMoveValues(); @@ -123,7 +126,7 @@ try { if(isHost){ server = new ServerSocket(8765); - printMessage("Your server is running on port 8765", 2); + printMessage("Your server is running on port 8765", MSG_TYPES.INFORMATION); s = server.accept(); DataInputStream inStream = new DataInputStream(s.getInputStream()); String str = inStream.readUTF(); @@ -139,9 +142,9 @@ s.close(); } } catch(UnknownHostException uhe){ - printMessage("Unknown host '???'", 0); + printMessage("Unknown host '???'", MSG_TYPES.ERROR); } catch (IOException e) { - printMessage(e.getLocalizedMessage(), 0); + printMessage(e.getLocalizedMessage(), MSG_TYPES.ERROR); System.exit(0); //TODO status code } @@ -156,7 +159,7 @@ } protected void createPlayers(){ - players = new AbstractPlayer[NR_PLAYERS]; + players = new AbstractPlayer[N_PLAYERS]; /*for(int i=0; i 0){ - printMessage("Please deselect all cards first", 0); + printMessage("Please deselect all cards first", MSG_TYPES.ERROR); return; } useColor = true; @@ -151,11 +153,11 @@ @Override public void mouseReleased(MouseEvent e) { if(!hintAvailable()){ - printMessage("No hints left!", 0); + printMessage("No hints left!", MSG_TYPES.ERROR); return; } if(selectedCards > 0){ - printMessage("Please deselect all cards first", 0); + printMessage("Please deselect all cards first", MSG_TYPES.ERROR); return; } useValue = true; @@ -180,9 +182,10 @@ @Override public void mouseReleased(MouseEvent e) { if(!checkValidMove()){ - printMessage("Please select all cards of the selected color/value", 0); + printMessage("Please select all cards of the selected color/value", MSG_TYPES.ERROR); return; } + if(roundsLeft >= 0) roundsLeft--; int selCardIndex = 0; for(int i=0; i 0){ - printMessage("Please deselect all cards first", 0); + printMessage("Please deselect all cards first", MSG_TYPES.ERROR); return; } useColor = false; @@ -290,7 +292,7 @@ @Override public void mouseReleased(MouseEvent e) { if(selectedCards > 0){ - printMessage("Please deselect all cards first", 0); + printMessage("Please deselect all cards first", MSG_TYPES.ERROR); return; } useColor = false; @@ -322,7 +324,7 @@ * PLAYER 2: NORTH * PLAYER 3: WEST */ - for(int i=0; i