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 boolean placeShipsOnField( String field, String alignment, String shipName, int xStartCoordinate, int yStartCoordinate) { if (!gameData.shipAlreadyPlaced(shipName, alignment, xStartCoordinate, yStartCoordinate)) { if (!isServer) { requestToServer.println( "placeShip " + field + " " + alignment + " " + shipName + " " + xStartCoordinate + " " + yStartCoordinate); return true; } if (isServer) { boolean controllerQuery = cont.addShip(shipName, alignment, field, xStartCoordinate, yStartCoordinate); if (controllerQuery) { gameData.placeShipsOnField(alignment, shipName, xStartCoordinate, yStartCoordinate); for (ServerService s : services) { s.sendMessageToClients( "placeShip " + field + " " + alignment + " " + shipName + " " + xStartCoordinate + " " + yStartCoordinate); } return true; } } } return false; }