Game Development Reference
In-Depth Information
}
}
6. The other method that does some work in the Game class is applyMove . This
takes FireActionMessage as input, checking the supplied tile to see whether
there is a ship in that spot. It then checks whether the supposed ship is sunk, and
whether the player has any ships left. If a ship is hit, it returns the Ship object to
the calling method, as follows:
public Ship applyMove(FireActionMessage action){
int x = action.getX();
int y = action.getY();
Ship ship = null;
if(action.getPlayerId() == playerOne.getId()){
ship = boardTwo[x][y];
if(ship != null){
ship.hit();
if(ship.isSunk()){
playerTwo.decreaseShips();
}
}
} else {
[replicate for playerTwo]
}
if(playerTwo.getShips() < 1 || playerOne.getShips()
< 1){
status = GAME_ENDED;
}
if(action.getPlayerId() == playerTwo.getId()){
turn++;
}
return ship;
}
Now, let's have a look at the server side of things. In the previous chapters, we had a look
at connecting the clients, but a full game requires a bit more communication to set things
up as we will see. This section will have the following eight steps:
Search WWH ::




Custom Search