5 次程式碼提交

作者 SHA1 備註 提交日期
  Rob Hallam 7a182cb7ea feat: remove GameActor reference from GameState once assigned to AI 9 月之前
  Rob Hallam 7ac60058fa refactor: use setter - give GameState a *temporary* ref to GameActor 9 月之前
  Rob Hallam d123fa9810 feat: call GameState::setupGameState() from initialise event handler 9 月之前
  Rob Hallam 87ed62cc7a feat: add setupGameState method for initialising game state 9 月之前
  Rob Hallam 7686cdd652 feat: move GameActor reference into AIPlayer 9 月之前
共有 4 個檔案被更改,包括 36 行新增19 行删除
分割檢視
  1. +1
    -1
      app/actors/GameActor.java
  2. +1
    -9
      app/events/Initalize.java
  3. +26
    -7
      app/structures/GameState.java
  4. +8
    -2
      app/structures/basic/AIPlayer.java

+ 1
- 1
app/actors/GameActor.java 查看文件

@@ -65,7 +65,7 @@ public class GameActor extends AbstractActor {
// Initalize a new game state object
gameState = new GameState();
// #hack: give the game state a reference to the game actor so AIPlayer can send messages
gameState.gameActor = this;
gameState.setGameActor(this);
// Get the list of image files to pre-load the UI with
Set<String> images = ImageListForPreLoad.getImageListForPreLoad();


+ 1
- 9
app/events/Initalize.java 查看文件

@@ -23,15 +23,7 @@ public class Initalize implements EventProcessor{
@Override
public void processEvent(ActorRef out, GameState gameState, JsonNode message) {
// hello this is a change
gameState.gameInitalised = true;
gameState.something = true;
// User 1 makes a change
//CommandDemo.executeDemo(out); // this executes the command demo, comment out this when implementing your solution
//Loaders_2024_Check.test(out);
gameState.setupGameState();
// start the turn demo
TurnDemo.executeDemo(out);


+ 26
- 7
app/structures/GameState.java 查看文件

@@ -11,17 +11,36 @@ import structures.basic.AIPlayer;
*
*/
public class GameState {
public boolean gameInitalised = false;
public boolean something = false;
public int currentPlayer = 1;
public AIPlayer aiPlayer = new AIPlayer();
private GameActor gameActor;
// note: still a bit of a hack but we remove this from GameState
// and give it to the AIPlayer on initialisation, and it can then
// be removed from here
public AIPlayer aiPlayer;
public GameState() {
super();
}
public void setGameActor(GameActor gameActor) {
this.gameActor = gameActor;
}
// bit of a hack but include a reference to the GameActor so AIPlayer can send messages to it
public GameActor gameActor;
/** Set up everything the game needs to be played (called via initialise game event)
*
*/
public void setupGameState() {
// do game setup
this.gameInitalised = true;
// set initial player
this.currentPlayer = 1;
// create the AI player:
this.aiPlayer = new AIPlayer(this.gameActor);
this.gameActor = null;
}
}

+ 8
- 2
app/structures/basic/AIPlayer.java 查看文件

@@ -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…
取消
儲存