Exemple #1
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Save the previous state of the keyboard and game pad so we can determine single key/button presses
            _previousGamePadState  = _currentGamePadState;
            _previousKeyboardState = _currentKeyboardState;

            // Read the current state of the keyboard, gamepad, mouse and store it
            _currentKeyboardState = Keyboard.GetState();
            _currentGamePadState  = GamePad.GetState(PlayerIndex.One);

#if WINDOWS
            _previousMouseState = _currentMouseState;
            _currentMouseState  = Mouse.GetState();
#endif

            // Exit
            if (_currentKeyboardState.IsKeyDown(Keys.Q) ||
                _currentKeyboardState.IsKeyDown(Keys.Escape) ||
                _currentGamePadState.Buttons.Back == ButtonState.Pressed)
            {
                Exit();
            }

            if (!_battleEngine.Execute())
            {
                // Display winner
                //return;
            }

            base.Update(gameTime);
        }
Exemple #2
0
        /// <summary>
        /// No options other than paths/filenames to the C# source
        /// for each robot
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("You must provide the robot files you want to compile");
                return;
            }

            Init();

            // Load, compile and instantiate the robots given on the command line
            if (_battleEngine.Load(args))
            {
                // Execute battle until one is left standing
                while (true)
                {
                    if (!_battleEngine.Execute())
                    {
                        // Display winner
                        return;
                    }

                    _cycles++;
                    UpdateDisplay();

                    // Check for quit 'Q' key
                    if (Console.KeyAvailable)
                    {
                        ConsoleKeyInfo consoleKeyInfo = Console.ReadKey(true);

                        if (consoleKeyInfo.Key == ConsoleKey.Q)
                        {
                            return;
                        }
                    }

                    Thread.Sleep(20);
                }
            }

            foreach (var error in _battleEngine.Errors)
            {
                Console.WriteLine(error);
            }

            return;
        }
Exemple #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="myObject"></param>
        /// <param name="myEventArgs"></param>
        private void NextGameFrame(Object myObject, EventArgs myEventArgs)
        {
            _gameEventTimer.Stop();
            ++_x;
            ++_y;
            if (_x > _arenaWidth - 16)
            {
                _x = 20;
            }
            if (_y > _arenaHeight - 16)
            {
                _y = 20;
            }

            if (!_battleEngine.Execute())
            {
                // Display winner
                return;
            }

            _cycles++;
            splitContainer.Panel1.Invalidate();
            _gameEventTimer.Start();
        }