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