コード例 #1
0
        static void Main()
        {
            // Initialize the variables which rule the game
            string command = string.Empty;

            char[,] gamefield = MinesweeperEngine.CreateGamefield();
            char[,] bombs     = MinesweeperEngine.GenerateBombs();
            List <Player> champions   = new List <Player>(CHAMPIONS_LIST_SIZE);
            int           row         = 0;
            int           column      = 0;
            int           moveCounter = 0;
            bool          isBomb      = false;
            bool          isNewGame   = true;
            bool          isEndGame   = false;

            // Run the game
            do
            {
                if (isNewGame)
                {
                    Console.WriteLine(
                        "Lets play Minesweeper. Try your luck. Find fields without bombs." +
                        "To show the results enter - \"top\", to start new game enter - \"restart\"," +
                        "to make move enter row and column separated by space, to exit enter - \"exit\"");
                    MinesweeperEngine.PrintGamefield(gamefield);
                    isNewGame = false;
                }

                command = ReadCommand(command, gamefield, ref row, ref column);

                switch (command)
                {
                case "top":
                    MinesweeperEngine.PrintResults(champions);
                    break;

                case "restart":
                    gamefield = MinesweeperEngine.CreateGamefield();
                    bombs     = MinesweeperEngine.GenerateBombs();
                    MinesweeperEngine.PrintGamefield(gamefield);
                    isBomb    = false;
                    isNewGame = false;
                    break;

                case "exit":
                    Console.WriteLine("Bye, Bye, Bye!");
                    break;

                case "turn":
                    if (bombs[row, column] != BOMB_SYMBOL)
                    {
                        MinesweeperEngine.Move(gamefield, bombs, row, column);
                        moveCounter++;
                        if (NOT_BOMBS_NUMBER == moveCounter)
                        {
                            isEndGame = true;
                        }
                        else
                        {
                            MinesweeperEngine.PrintGamefield(gamefield);
                        }
                    }
                    else
                    {
                        isBomb = true;
                    }
                    break;

                default:
                    Console.WriteLine(Environment.NewLine +
                                      "Invalid input! You should enter valid command - top, restart, valid row and column or exit" +
                                      Environment.NewLine);
                    break;
                }

                // End current game and start new one if there is a bomb
                if (isBomb)
                {
                    MinesweeperEngine.PrintGamefield(bombs);
                    Console.Write(Environment.NewLine +
                                  "Game over! Your scores are {0}. Enter username: "******"Congratulations! You win this game.");
                    MinesweeperEngine.PrintGamefield(bombs);
                    Console.WriteLine("Enter username: "******"exit");

            Console.WriteLine("Made in Bulgaria");
            Console.WriteLine("Press any key to exit the program.");
            Console.Read();
        }