Explorar el Código

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 hace 9 meses
padre
commit
94b9b5f647
Se han modificado 1 ficheros con 41 adiciones y 0 borrados
  1. +41
    -0
      app/structures/basic/AIPlayer.java

+ 41
- 0
app/structures/basic/AIPlayer.java Ver fichero

@@ -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);

}

}

Cargando…
Cancelar
Guardar