示例#1
0
        /// <summary>
        /// Method that reveals cells onto the game field.
        /// </summary>
        /// <param name="mineField">The game field</param>
        /// <param name="currentCell">The cell to reveal</param>
        private static void ExecuteRevealBlockCommand(MineField mineField, Cell currentCell)
        {
            int row = currentCell.Row;
            int col = currentCell.Col;

            if (mineField.IsInsideTheField(row, col) && !mineField.IsAlreadyShown(row, col))
            {
                if (mineField.IsMine(row, col))
                {
                    mineField.RevealAllMines();
                    Console.Clear();
                    GameMessages.EndGame(mineField.RevealedCellsCounter);
                    GameMessages.DrawGameField(mineField.ToString());
                    bool isInTop5 = (mineField.RevealedCellsCounter > scoreBoard.MinimalScoreInTop5());
                    if (scoreBoard.Count() < 5 || isInTop5)
                    {
                        scoreBoard.AddScore(mineField.RevealedCellsCounter);
                    }

                    scoreBoard.ShowScore();
                    Main();
                }
                else
                {
                    mineField.RevealBlock(row, col);
                }
            }
            else
            {
                GameMessages.IlligalMove();
                shouldDisplayBoard = false;
            }
        }
示例#2
0
        /// <summary>
        /// The <see cref="Main"/> method of the application.
        /// Holds the main execution logic of the game
        /// </summary>
        public static void Main()
        {
            MineField mineField = new MineField();

            while (true)
            {
                if (shouldDisplayBoard)
                {
                    Console.Clear();
                    GameMessages.StartGame();
                    GameMessages.DrawGameField(mineField.ToString());
                }

                shouldDisplayBoard = true;
                GameMessages.Entry();

                ExecuteCommand(mineField);
            }
        }