コード例 #1
0
 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));
   }
 }
コード例 #2
0
 public void waterResponse(String response) {
   StringTokenizer st = new StringTokenizer(response);
   String side = null;
   int k = 0;
   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++;
   }
   gameData.shootAtField(side, x, y, 2, false, null, null, -1, -1);
 }
コード例 #3
0
 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));
 }