internal async Task <string> GetGameStateFromServer(TokenDto token) { var response = await RequestData("GetState", "Could not get gamestate from server", GetContent(token)); if (response != null) { return(await response.Content.ReadAsStringAsync()); } return(null); }
private FleetDTO GetFleetDto(TokenDto token, string fleetCommand) { var fleet = JsonConvert.DeserializeObject <GameElements.FleetCommand[]>(fleetCommand); return(new FleetDTO { Token = token.Token, Commands = fleet }); }
private async Task GetNewGameState(ServerCommunication com, TokenDto gameToken) { gui.NewRound(round++); var gameState = await com.GetGameStateFromServer(gameToken); gui.GotNewGameState(gameState); if (gameState == null) { var winner = await com.GetWinnerFromServer(gameToken); gui.WinnerFound(winner); Terminate(); return; } history.Add(gameState); gui.SendGameStateToUserBot(); botProcess.SendGameState(gameState); }
public BattleMaster(BotProcess botProcess, ServerCommunication com, TokenDto gameToken, IGuiDisplay guiDisplayer) { this.botProcess = botProcess; gui = guiDisplayer; this.botProcess.BotReady += () => { gui.UserBotReady(); GetNewGameState(com, gameToken).Wait(); }; this.botProcess.GotMessage += (message) => { if (string.IsNullOrEmpty(message) == false) { gui.GotMessageFromUserBot(message); gui.SendFleet(message); com.SendFleetToServer(gameToken, message).Wait(); GetNewGameState(com, gameToken).Wait(); } }; }
internal async Task <string> GetWinnerFromServer(TokenDto token) { var response = await RequestData("GetWinner", "Could not get winner from server", GetContent(token)); return(JsonConvert.DeserializeObject <WinnerDto>(await response.Content.ReadAsStringAsync()).Winner); }
internal async Task SendFleetToServer(TokenDto token, string fleetCommands) { await RequestData("SubmitTurn", "Error sending fleetcommands", GetContent(GetFleetDto(token, fleetCommands))); }
public void GotToken(TokenDto gameToken) { Console.WriteLine("Got game token"); }