Пример #1
0
        internal void Run(int _gameSimCount)
        {
            int count = -1;

            while (++count < _gameSimCount)
            {
                abstractGame.NewGame();
                positionGuesser.Reset();

                while (!abstractGame.GameOver)
                {
                    positionGuesser.MakeGuess();
                }

                serializer.WriteBattleshipGuessesToTextFile(abstractGame);
            }
        }
Пример #2
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)
        {
            cumulativeElapsedTime += gameTime.ElapsedGameTime.Milliseconds;

            // NOTE: Could get overflow exception here if update is called less frequently than updateTimeInMilliseconds
            if (cumulativeElapsedTime > updateTimeInMilliseconds)
            {
                cumulativeElapsedTime -= updateTimeInMilliseconds;

                // Allows the game to exit
                if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                {
                    this.Exit();
                }

                mouseState = Mouse.GetState();
                mouseFilter.Update(mouseState, ref currentClickInfo);
                if (currentClickInfo.Count > 0)
                {
                    visualGame.RegisterClick(currentClickInfo[0]); // Registers one click at a time.  currentClickInfo is like a queue.
                    currentClickInfo.RemoveAt(0);
                }

                keyboardState = Keyboard.GetState();
                pressedKeys   = keyboardFilter.GetPressedKeys(keyboardState);
                foreach (Keys key in pressedKeys)
                {
                    switch (key)
                    {
                    case Keys.R:
                    {
                        abstractGame.ResetGame();
                        break;
                    }

                    case Keys.N:
                    {
                        abstractGame.NewGame();
                        break;
                    }

                    case Keys.C:
                    {
                        visualGame.ShowShips = !visualGame.ShowShips;
                        break;
                    }

                    case Keys.S:
                    {
                        if (abstractGame.GameOver)
                        {
                            serializer.WriteBattleshipGuessesToTextFile(abstractGame);
                        }
                        break;
                    }
                    }
                }
            }

            base.Update(gameTime);
        }