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 2 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.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);
@@ -30,11 +37,10 @@ public class AIPlayer extends Player {
((ObjectNode) message).put("player", "AI");
// then send it to the GameActor:
try {
gameState.gameActor.processMessage("endturnclicked", message);
this.gameActor.processMessage("endturnclicked", message);
} catch (Exception e) {
e.printStackTrace();
}
// gameState.gameActor.receive(message);

}



Loading…
Cancel
Save