} else if(event.getMessage() instanceof DrawPawnsMessage){
if(isServer){
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;
}
}
}
server.send(currentPlayer, new AvailableMoveMessage(game.getValidMoves(currHallwy), currentPlayer.getCharacter()));
}
}
}else if(event.getMessage() instanceof EndTurnMessage){
if(isServer){
//Move to the next player when we receive this message
this.getNextPlayer();
//TODO: Send available move message? This still needs to be tested
for(Location location : game.getSpaces()){
Player player = location.getPlayer();
if(player != null){
if(player.getUUID().equals(currentPlayer.getUUID())){
server.send(currentPlayer, new AvailableMoveMessage(game.getValidMoves(location), currentPlayer.getCharacter()));
fireTextStatusEvent(new TextStatusEvent(this, "It is now " + currentPlayer.getCharacter() + "'s turn."));
}
}
}
}
return;
}else if(event.getMessage() instanceof TextStatusMessage && !(event.getMessage() instanceof ShowTextStatusMessage)){
//Text status message sent from server
ShowTextStatusMessage msg = new ShowTextStatusMessage(((TextStatusMessage) event.getMessage()).getMessageText());
if(isServer)
{
server.sendAll(msg);
}
}else if(event.getMessage() instanceof CharacterSelectedMessage) {
fireCharacterSelectedEvent(new CharacterSelectedEvent(this,
((CharacterSelectedMessage) event.getMessage()).getCharacter()));
return;
}else if(event.getMessage() instanceof AccusationMessage){
AccusationMessage msg = ((AccusationMessage)event.getMessage());
this.fireMakeAccusationEvent(new MakeAccusationEvent(event, msg.getTheory()));
return;
}else if(event.getMessage() instanceof SuggestionMessage){
SuggestionMessage msg = ((SuggestionMessage)event.getMessage());
this.fireMakeSuggestionEvent(new MakeSuggestionEvent(event, msg.getTheory()));
return;
}else if (event.getMessage() instanceof SuggestionDisprovedMessage)
{
}else if(event.getMessage() instanceof SuggestionDisprovedNeedFeedBackMessage){
this.fireSuggestionDisprovedNeedFeedBackEvent(new SuggestionDisprovedNeedFeedBackEvent(this, ((SuggestionDisprovedNeedFeedBackMessage)event.getMessage()).getSuggestion(), ((SuggestionDisprovedNeedFeedBackMessage)event.getMessage()).getCards()));
}else if(event.getMessage() instanceof SuggestionDisprovedCardMessage){
if(isServer && !(client.getPlayer().getUUID().equals(currentPlayer.getUUID())))
{
//Forward the message onto the client
server.send(currentPlayer, event.getMessage());
//fireDisproveCardEvent(new DisproveCardEvent(this, ((SuggestionDisprovedCardMessage)event.getMessage()).getDisprovedCard()));
}
//Show a message box indicating what card was disproved
String card = "";
if(((SuggestionDisprovedCardMessage)event.getMessage()).getDisprovedCard() instanceof WeaponCard)
card = ((WeaponCard)((SuggestionDisprovedCardMessage)event.getMessage()).getDisprovedCard()).getWeaponType().toString();
else if(((SuggestionDisprovedCardMessage)event.getMessage()).getDisprovedCard() instanceof LocationCard)
card = ((LocationCard)((SuggestionDisprovedCardMessage)event.getMessage()).getDisprovedCard()).getLocationName().toString();
else if (((SuggestionDisprovedCardMessage)event.getMessage()).getDisprovedCard() instanceof CharacterCard)
card = ((CharacterCard)((SuggestionDisprovedCardMessage)event.getMessage()).getDisprovedCard()).getCharacterName().toString();
JOptionPane.showMessageDialog(null, card + " has been disproven.");
}else if(event.getMessage() instanceof EndGameMessage){
EndGameMessage msg = (EndGameMessage) event.getMessage();
JOptionPane.showMessageDialog(null, "Game Over! " + msg.getWinner().getCharacter().toString() + " has solved the case!");
mainView.quitGame();
client.disconnect();
if(isServer)
{
server.disconnect();