Esempio n. 1
0
        private RobotState HandleGameTick(GameState gameState)
        {
            var robotState = new RobotState();

            if (runtime.IsChecked == true)
            {
                robotState = battleCityRobot.GetRobotState(gameState);
                map.SetGameState(gameState);
            }
            if (record.IsChecked == true)
            {
                var historyButton = new Button();
                var command       = robotState.Command switch
                {
                    Commands.GO_LEFT => "Left",
                    Commands.GO_TOP => "Top",
                    Commands.GO_RIGHT => "Right",
                    Commands.GO_DOWN => "Down",
                    _ => "None"
                };
                var tempalte = robotState.Fire switch
                {
                    Fire.FIRE_BEFORE_ACTION => "Fire + {0}",
                    Fire.FIRE_AFTER_ACTION => "{0} + Fire",
                    _ => "{0}",
                };
                historyButton.Content = string.Format(tempalte, command);

                historyButton.HorizontalContentAlignment = HorizontalAlignment.Left;
                historyButton.Click += (a, b) =>
                {
                    runtime.IsChecked = false;
                    record.IsChecked  = false;
                    map.SetGameState(gameState);
                    battleCityRobot.GetRobotState(gameState);
                };
                history.Children.Add(historyButton);

                if (!gameState.PlayerTank.Alive)
                {
                    if (history.Children.Count > 6)
                    {
                        history.Children.RemoveRange(0, history.Children.Count - 6);
                    }
                    record.IsChecked = false;
                }
            }
            return(robotState);
        }
Esempio n. 2
0
 private void OnMessageReceivedHandler(string gameStateMessage)
 {
     try
     {
         var gameState         = GetGameState(gameStateMessage);
         var robotState        = battleCityRobot.GetRobotState(gameState);
         var robotStateMessage = GetRobotStateMessage(robotState);
         SendMessage(robotStateMessage);
     }
     catch (Exception ex)
     {
         taskCompletionSource.SetException(ex);
     }
 }