diff --git a/src/server/ServerGame.java b/src/server/ServerGame.java index 656df03..8156338 100644 --- a/src/server/ServerGame.java +++ b/src/server/ServerGame.java @@ -29,7 +29,7 @@ int movesLeft; boolean won; boolean lost; - + List sockets; @@ -48,7 +48,7 @@ public ServerGame() { } - + protected void establishConnection(){ port = 1337; sockets = new ArrayList<>(); @@ -62,7 +62,7 @@ sendToClient(CONNECTION_VALID, connectionJson.toString(), socket); nrOfPlayers++; System.out.println(nrOfPlayers + " players connected!"); - // TODO do this somewhere else + // TODO do this somewhere else System.out.println("Creating new Socket Listener for #" + (sockets.size()-1)); System.out.println("Socket id: " + socket); new Thread(new SocketListenerThread(socket)).start(); @@ -179,13 +179,13 @@ // e.printStackTrace(); System.err.println("Exception is currently suppressed"); } - + // TODO check Protocol // switch(proto){ // case VIBE_DUMB: // break; // } - + String msg = null; JSONObject jo = null; boolean isValid = true; @@ -248,14 +248,14 @@ } return null; } - + protected boolean placeCard(Card c) { int[] index = new int[1]; Card card = getRealCard(c, index); if(card == null) return false; int color = card.getColorInt(); int value = card.getValue(); - + int deckValue = deckCounter[color]; if(deckValue == value){ //place card possible @@ -270,11 +270,11 @@ dealCard(index[0], currentPlayer); return true; } - + protected boolean moveCardToTrash(Card c){ return moveCardToTrash(c, false); } - + protected boolean moveCardToTrash(Card c, boolean receivedFlash) { int[] index = new int[1]; Card card = getRealCard(c, index); @@ -285,7 +285,7 @@ dealCard(index[0], currentPlayer); return true; } - + protected boolean giveHint(int type, int value, int playerId){ if(!hintAvailable()) return false; if(currentPlayer == playerId) return false; @@ -332,17 +332,17 @@ p = randomPosition(); } while (tmp_cards[p[0]][p[1]] == 0); tmp_cards[p[0]][p[1]]--; - cards.add(new Card(p[0], (p[1] + 1), i)); + cards.add(new Card(p[0], p[1], i)); } } - + private int[] randomPosition(){ int[] p = new int[2]; p[0] = random(5); p[1] = random(5); return p; } - + private int random(int max){ return rand.nextInt(max); } @@ -385,11 +385,11 @@ this.won = won; this.lost = lost; } - + protected void sendToClient(byte msgType, Socket s){ sendToClient(msgType, null, s); } - + protected void sendToClient(byte msgType, String msg, Socket s){ DataOutputStream os = null; try { @@ -409,11 +409,11 @@ e.printStackTrace(); } } - + protected void sendToAll(byte msgType){ sendToAll(msgType, null); } - + protected void sendToAll(byte msgType, String msg){ int i=0; for(Socket s : sockets){ @@ -440,14 +440,14 @@ /** * Stores the current state of the game in the history - * + * * @param json * the current state as json object */ protected void addToHistory(String json) { history.add(json); } - + protected JSONObject toJson(){ JSONObject root = new JSONObject(); root.put("cardsInDeck", cardsInDeck); @@ -459,7 +459,7 @@ trashArray.put(c.toJson()); } root.put("trash", trashArray); - + JSONObject deckRow = new JSONObject(); for(int i=0; i