Browse Source

feat: move GameActor reference into AIPlayer

This avoid the ugly hack of keeping a referenec in GameState
rdh-local-prototype-endturn
Rob Hallam 9 months ago
parent
commit
7686cdd652
1 changed files with 8 additions and 2 deletions
  1. +8
    -2
      app/structures/basic/AIPlayer.java

+ 8
- 2
app/structures/basic/AIPlayer.java View File

@@ -8,13 +8,20 @@ import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.ObjectNode;


import actors.GameActor;
import akka.actor.ActorRef; import akka.actor.ActorRef;


public class AIPlayer extends Player { public class AIPlayer extends Player {
private GameActor gameActor;

public AIPlayer() { public AIPlayer() {
super(); super();
} }


public AIPlayer(GameActor gameActor) {
super();
this.gameActor = gameActor;
}
public void takeTurn(ActorRef out, GameState gameState) { public void takeTurn(ActorRef out, GameState gameState) {
// addPlayer2Notification // addPlayer2Notification
BasicCommands.addPlayer2Notification(out, "My turn!", 2); BasicCommands.addPlayer2Notification(out, "My turn!", 2);
@@ -30,11 +37,10 @@ public class AIPlayer extends Player {
((ObjectNode) message).put("player", "AI"); ((ObjectNode) message).put("player", "AI");
// then send it to the GameActor: // then send it to the GameActor:
try { try {
gameState.gameActor.processMessage("endturnclicked", message);
this.gameActor.processMessage("endturnclicked", message);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
// gameState.gameActor.receive(message);


} }




Loading…
Cancel
Save