Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        private FleetDTO GetFleetDto(TokenDto token, string fleetCommand)
        {
            var fleet = JsonConvert.DeserializeObject <GameElements.FleetCommand[]>(fleetCommand);

            return(new FleetDTO
            {
                Token = token.Token,
                Commands = fleet
            });
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        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();
                }
            };
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
 internal async Task SendFleetToServer(TokenDto token, string fleetCommands)
 {
     await RequestData("SubmitTurn", "Error sending fleetcommands", GetContent(GetFleetDto(token, fleetCommands)));
 }
Esempio n. 7
0
 public void GotToken(TokenDto gameToken)
 {
     Console.WriteLine("Got game token");
 }