ShowTextStatusMessage txt = new ShowTextStatusMessage("Game is beginning. ");
server.sendAll(txt);
DrawPawnsMessage msg = (DrawPawnsMessage) event.getMessage();
for(CharacterName name : msg.getNames()){
HallwayName hallway = BoardView.getDefaultHall(name);
for(Location space : game.getSpaces()){
if(space.getLocationType()==LocationType.HALLWAY_TYPE){
if(((Hallway)space).getHallwayName() == hallway){
space.setCharacterName(name);
break;
}
}
}
}
}
}else if(event.getMessage() instanceof SendClientPlayerMessage) {
client.setPlayer(((SendClientPlayerMessage) event.getMessage()).getPlayer());
return;
}else if(event.getMessage() instanceof CharactersAvailableMessage) {
fireCharactersAvailableEvent(new CharactersAvailableEvent(this,
((CharactersAvailableMessage) event.getMessage()).getNames()));
return;
}else if(event.getMessage() instanceof CharactersRequestMessage) {
fireCharactersRequestEvent(new CharactersRequestEvent(this));
return;
}else if(event.getMessage() instanceof TakeCharacterMessage) {
if (isServer){
//TODO: Make setPlayerCharacter return boolean for success (non duplicate)
TakeCharacterMessage msg = (TakeCharacterMessage)event.getMessage();
game.setPlayerCharacter(msg.getPlayer(), msg.getCharacterName());
server.sendAll(new CharactersAvailableMessage(game));
characterNames.add(msg.getCharacterName());
if(characterNames.size() == this.numPlayers){
// All of the players have selected their characters.
// Tell everyone to draw their board and determine who goes first.
server.sendAll(new DrawPawnsMessage(characterNames));
Player firstPlayer = null;
for(Player player : game.getPlayers()){
if(player.getCharacter()== CharacterName.MISS_SCARLET){
// Miss scarlet always goes first according to Clue rules.
firstPlayer = player;
}
}
if(firstPlayer == null){
// Miss Scarlet is not in play so just choose someone to go first.
firstPlayer = game.getPlayers().get(0);
}
currentPlayer = firstPlayer;
this.fireTextStatusEvent(new TextStatusEvent(this, "Player "+ firstPlayer.getCharacter().toString() + " will go first. "));
// Game on - start first turn.
HallwayName hallwy = BoardView.getDefaultHall(currentPlayer.getCharacter());
Hallway currHallwy = null;
for(Location space : game.getSpaces()){
if(space.getLocationType() == LocationType.HALLWAY_TYPE){
if(((Hallway)space).getHallwayName() == hallwy){
currHallwy = (Hallway)space;