Game Development Reference
In-Depth Information
should be broadcasted to both the players letting them know whether the action
was a hit or not.
8. Finally, we switch the active player and send another
TurnMessage
to both the
players as follows:
TurnMessage turnMessage = new
TurnMessage();
turnMessage.setGameId(game.getId());
game.setCurrentPlayerId(game.getCurrentPlayerId() ==
1 ? 2 : 1);
turnMessage.setActivePlayer(game.getCurrentPlayerId());
gameServer.sendMessage(turnMessage);
}
9. This flow will continue until one of the players has run out of ships. Then, we
should simply send
GameStatusMessage
with the
END
status to the players
and disconnect them.