You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1234567891011121314151617181920212223242526272829303132333435363738
  1. package events;
  2. import com.fasterxml.jackson.databind.JsonNode;
  3. import akka.actor.ActorRef;
  4. import structures.GameState;
  5. /**
  6. * Indicates that the user has clicked an object on the game canvas, in this case
  7. * the end-turn button.
  8. *
  9. * {
  10. * messageType = “endTurnClicked”
  11. * }
  12. *
  13. * @author Dr. Richard McCreadie
  14. *
  15. */
  16. public class EndTurnClicked implements EventProcessor{
  17. @Override
  18. public void processEvent(ActorRef out, GameState gameState, JsonNode message) {
  19. // see if we have a "player" field in the message to indicate AI player:
  20. String player = (message.has("player")) ? message.get("player").asText() : "human";
  21. // now we check if the game thinks it is the player who clicked end turn's actual turn:
  22. if (gameState.currentPlayer == 1 && player.equals("human")) {
  23. System.out.println("Player 1 clicked end turn");
  24. gameState.currentPlayer = 2;
  25. // hand off control to AI player:
  26. gameState.aiPlayer.takeTurn(out, gameState);
  27. System.out.println(String.format("%s", message.toString()));
  28. } else if (gameState.currentPlayer == 2 && player.equals("AI")) {
  29. System.out.println("Player 2 clicked end turn");
  30. gameState.currentPlayer = 1;
  31. }
  32. }
  33. }