|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- package structures.basic;
-
- // import basic commands for notifications
- import commands.BasicCommands;
- import structures.GameState;
-
- import com.fasterxml.jackson.databind.JsonNode;
- import com.fasterxml.jackson.databind.ObjectMapper;
- import com.fasterxml.jackson.databind.node.ObjectNode;
-
- import actors.GameActor;
- import akka.actor.ActorRef;
-
- public class AIPlayer extends Player {
- private GameActor gameActor;
-
- public AIPlayer() {
- super();
- }
-
- public AIPlayer(GameActor gameActor) {
- super();
- this.gameActor = gameActor;
- }
- public void takeTurn(ActorRef out, GameState gameState) {
- // addPlayer2Notification
- BasicCommands.addPlayer2Notification(out, "My turn!", 2);
- // addPlayer2Notification
- BasicCommands.addPlayer2Notification(out, "Ending turn", 2);
- // send "endTurnClicked" message to GameActor
- // NOTE: #query -- how do we get the GameActor reference?
- // #hack way- we add a reference to the GameActor in GameState
- // first create the "endTurnClicked" message:
- JsonNode message = new ObjectMapper().createObjectNode();
- ((ObjectNode) message).put("messageType", "endTurnClicked");
- // add some content to say it is the AI player who 'clicked' end turn:
- ((ObjectNode) message).put("player", "AI");
- // then send it to the GameActor:
- try {
- this.gameActor.processMessage("endturnclicked", message);
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- }
-
- }
|