Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 
 

39 řádky
1.3 KiB

  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. }