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.
 
 
 
 
 

48 lines
1.5 KiB

  1. package structures.basic;
  2. // import basic commands for notifications
  3. import commands.BasicCommands;
  4. import structures.GameState;
  5. import com.fasterxml.jackson.databind.JsonNode;
  6. import com.fasterxml.jackson.databind.ObjectMapper;
  7. import com.fasterxml.jackson.databind.node.ObjectNode;
  8. import actors.GameActor;
  9. import akka.actor.ActorRef;
  10. public class AIPlayer extends Player {
  11. private GameActor gameActor;
  12. public AIPlayer() {
  13. super();
  14. }
  15. public AIPlayer(GameActor gameActor) {
  16. super();
  17. this.gameActor = gameActor;
  18. }
  19. public void takeTurn(ActorRef out, GameState gameState) {
  20. // addPlayer2Notification
  21. BasicCommands.addPlayer2Notification(out, "My turn!", 2);
  22. // addPlayer2Notification
  23. BasicCommands.addPlayer2Notification(out, "Ending turn", 2);
  24. // send "endTurnClicked" message to GameActor
  25. // NOTE: #query -- how do we get the GameActor reference?
  26. // #hack way- we add a reference to the GameActor in GameState
  27. // first create the "endTurnClicked" message:
  28. JsonNode message = new ObjectMapper().createObjectNode();
  29. ((ObjectNode) message).put("messageType", "endTurnClicked");
  30. // add some content to say it is the AI player who 'clicked' end turn:
  31. ((ObjectNode) message).put("player", "AI");
  32. // then send it to the GameActor:
  33. try {
  34. this.gameActor.processMessage("endturnclicked", message);
  35. } catch (Exception e) {
  36. e.printStackTrace();
  37. }
  38. }
  39. }