Browse Source

feat: add AIPlayer with takeTurn() method

Intention is the game hands control to AI player after human ends turn by
calling this method
rdh-local-prototype-endturn
Rob Hallam 2 months ago
parent
commit
94b9b5f647
1 changed files with 41 additions and 0 deletions
  1. +41
    -0
      app/structures/basic/AIPlayer.java

+ 41
- 0
app/structures/basic/AIPlayer.java View File

@@ -0,0 +1,41 @@
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 akka.actor.ActorRef;

public class AIPlayer extends Player {
public AIPlayer() {
super();
}

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 {
gameState.gameActor.processMessage("endturnclicked", message);
} catch (Exception e) {
e.printStackTrace();
}
// gameState.gameActor.receive(message);

}

}

Loading…
Cancel
Save