public void hitResponse(String response) {
   StringTokenizer st = new StringTokenizer(response);
   int k = 0;
   String side = null;
   int x = -1;
   int y = -1;
   while (st.hasMoreTokens()) {
     if (k == 0) st.nextToken();
     if (k == 1) side = st.nextToken();
     if (k == 2) x = Integer.parseInt(st.nextToken());
     if (k == 3) y = Integer.parseInt(st.nextToken());
     k++;
   }
   System.out.println(gameData.getPlayerSide());
   System.out.println(side);
   if (gameData.getPlayerSide().equals(side)) {
     System.out.println("player field hit");
     gameData.shootAtField(side, x, y, 3, false, null, null, -1, -1);
     mw.v.enqueEvent(new CustomEvent(CustomEvent.PLAYER_FIELD_HIT, x, y));
   } else {
     System.out.println("enemy field hit");
     gameData.shootAtField(side, x, y, 3, false, null, null, -1, -1);
     mw.v.enqueEvent(new CustomEvent(CustomEvent.OPPONENT_FIELD_HIT, x, y));
   }
 }
 public void chat(String message) {
   message = message.substring(5);
   if (isServer) {
     for (ServerService s : services)
       s.sendMessageToClients(
           "chat " + gameData.getPlayerName() + " " + gameData.getPlayerSide() + " " + message);
     parseChatMessage(
         "chat " + gameData.getPlayerName() + " " + gameData.getPlayerSide() + " " + message);
   }
   if (!isServer)
     requestToServer.println(
         "chat " + gameData.getPlayerName() + " " + gameData.getPlayerSide() + " " + message);
 }
 public void shoot(int x, int y) {
   if (!isServer)
     requestToServer.println(
         "fire "
             + gameData.getPlayerSide()
             + " "
             + new Integer(x).toString()
             + " "
             + new Integer(y).toString());
   if (isServer) elaborateShootRequest(x, y, "host");
 }
 public void allShipsDestroyed(String response) {
   StringTokenizer st = new StringTokenizer(response);
   st.nextToken();
   String result;
   if ((st.nextToken().equals(gameData.getPlayerSide()))) result = "You Lose";
   else result = "You Win!";
   mw.v.enqueEvent(new CustomEvent(CustomEvent.GAME_OVER, result));
   try {
     Thread.sleep(10000);
   } catch (InterruptedException e) {
   }
   System.exit(0);
 }
 public void shipPlacedResponse(String response) {
   int i = 0;
   StringTokenizer st = new StringTokenizer(response);
   String field = null;
   String alignment = null;
   String shipName = null;
   int xStartCoordinate = -1;
   int yStartCoordinate = -1;
   while (st.hasMoreTokens()) {
     if (i == 0) st.nextToken();
     if (i == 1) field = st.nextToken();
     if (i == 2) alignment = st.nextToken();
     if (i == 3) shipName = st.nextToken();
     if (i == 4) xStartCoordinate = Integer.parseInt(st.nextToken());
     if (i == 5) yStartCoordinate = Integer.parseInt(st.nextToken());
     i++;
   }
   if (field.equals(gameData.getPlayerSide()))
     gameData.placeShipsOnField(alignment, shipName, xStartCoordinate, yStartCoordinate);
 }
 public void destroyedResponse(String response) {
   StringTokenizer st = new StringTokenizer(response);
   String side = null;
   String shipName = null;
   String alignment = null;
   int size = 0;
   int k = 0;
   int xStartCoord = -1;
   int yStartCoord = -1;
   int hostPoints = -1;
   int guestPoints = -1;
   int x = -1;
   int y = -1;
   while (st.hasMoreTokens()) {
     if (k == 0) st.nextToken();
     if (k == 1) side = st.nextToken();
     if (k == 2) shipName = st.nextToken();
     if (k == 3) alignment = st.nextToken();
     if (k == 4) xStartCoord = Integer.parseInt(st.nextToken());
     if (k == 5) yStartCoord = Integer.parseInt(st.nextToken());
     if (k == 6) hostPoints = Integer.parseInt(st.nextToken());
     if (k == 7) guestPoints = Integer.parseInt(st.nextToken());
     if (k == 8) x = Integer.parseInt(st.nextToken());
     if (k == 9) y = Integer.parseInt(st.nextToken());
     k++;
   }
   if (shipName.equals("aircraft")) size = 5;
   if (shipName.equals("battleship")) size = 4;
   if (shipName.equals("destroyer")) size = 3;
   if (shipName.equals("submarine")) size = 2;
   if (gameData.getPlayerSide().equals("guest")) {
     gameData.setMyPoints(guestPoints);
     gameData.setEnemyPoints(hostPoints);
   } else {
     gameData.setMyPoints(hostPoints);
     gameData.setEnemyPoints(guestPoints);
   }
   gameData.shootAtField(side, x, y, 3, true, shipName, alignment, xStartCoord, yStartCoord);
   mw.v.enqueEvent(
       new CustomEvent(CustomEvent.SHIP_EXPLODE, xStartCoord, yStartCoord, size, alignment, side));
 }