コード例 #1
0
        static void Main(string[] аргументи)
        {
            string command = string.Empty;
            char[,] board = CreateBoard();
            char[,] bombs = PlaceBombs();
            int counter = 0;
            bool isDetonate = false;
            List<PlayerStatistic> playerStatistics = new List<PlayerStatistic>(6);
            int row = 0;
            int column = 0;
            bool isOnMenu = true;
            const int nonMineFieldCount = 35;
            bool isSuccessGame = false;

            do
            {
                if (isOnMenu)
                {
                    Console.WriteLine("Hajde da igraem na “Mini4KI”. Probvaj si kasmeta da otkriesh poleteta bez mini4ki." +
                    " Komanda 'top' pokazva klasiraneto, 'restart' po4va nova igra, 'exit' izliza i hajde 4ao!");
                    PrintBoard(board);
                    isOnMenu = false;
                }

                Console.Write("Daj red i kolona : ");

                command = Console.ReadLine().Trim();

                if (command.Length >= 3)
                {
                    if (int.TryParse(command[0].ToString(), out row) &&
                    int.TryParse(command[2].ToString(), out column) &&
                        row <= board.GetLength(0) && column <= board.GetLength(1))
                    {
                        command = "turn";
                    }
                }

                switch (command)
                {
                    case "top":
                        PrintStatistic(playerStatistics);
                        break;
                    case "restart":
                        board = CreateBoard();
                        bombs = PlaceBombs();
                        PrintBoard(board);
                        isDetonate = false;
                        isOnMenu = false;
                        break;
                    case "exit":
                        Console.WriteLine("4a0, 4a0, 4a0!");
                        break;
                    case "turn":
                        if (bombs[row, column] != '*')
                        {
                            if (bombs[row, column] == '-')
                            {
                                MakeMove(board, bombs, row, column);
                                counter++;
                            }
                            if (nonMineFieldCount == counter)
                            {
                                isSuccessGame = true;
                            }
                            else
                            {
                                PrintBoard(board);
                            }
                        }
                        else
                        {
                            isDetonate = true;
                        }
                        break;
                    default:
                        Console.WriteLine("\nGreshka! nevalidna Komanda\n");
                        break;
                }

                if (isDetonate)
                {
                    PrintBoard(bombs);
                    Console.Write("\nHrrrrrr! Umria gerojski s {0} to4ki. " +
                        "Daj si niknejm: ", counter);
                    string name = Console.ReadLine();
                    PlayerStatistic playerStatistic = new PlayerStatistic(name, counter);

                    if (playerStatistics.Count < 5)
                    {
                        playerStatistics.Add(playerStatistic);
                    }
                    else
                    {
                        for (int i = 0; i < playerStatistics.Count; i++)
                        {
                            if (playerStatistics[i].Score < playerStatistic.Score)
                            {
                                playerStatistics.Insert(i, playerStatistic);
                                playerStatistics.RemoveAt(playerStatistics.Count - 1);
                                break;
                            }
                        }
                    }

                    playerStatistics.Sort((PlayerStatistic firstPlayerStatistic, PlayerStatistic secondPlayerStatistic) => secondPlayerStatistic.Name.CompareTo(firstPlayerStatistic.Name));
                    playerStatistics.Sort((PlayerStatistic firstPlayerStatistic, PlayerStatistic secondPlayerStatistic) => secondPlayerStatistic.Score.CompareTo(firstPlayerStatistic.Score));
                    PrintStatistic(playerStatistics);

                    board = CreateBoard();
                    bombs = PlaceBombs();
                    counter = 0;
                    isDetonate = false;
                    isOnMenu = true;
                }

                if (isSuccessGame)
                {
                    Console.WriteLine("\nBRAVOOOS! Otvri 35 kletki bez kapka kryv.");
                    PrintBoard(bombs);
                    Console.WriteLine("Daj si imeto, batka: ");
                    string name = Console.ReadLine();
                    PlayerStatistic playerStatistic = new PlayerStatistic(name, counter);
                    playerStatistics.Add(playerStatistic);
                    PrintStatistic(playerStatistics);
                    board = CreateBoard();
                    bombs = PlaceBombs();
                    counter = 0;
                    isSuccessGame = false;
                    isOnMenu = true;
                }
            }
            while (command != "exit");

            Console.WriteLine("Made in Bulgaria - Uauahahahahaha!");
            Console.WriteLine("AREEEEEEeeeeeee.");
            Console.Read();
        }
コード例 #2
0
        static void Main(string[] аргументи)
        {
            string command = string.Empty;

            char[,] board = CreateBoard();
            char[,] bombs = PlaceBombs();
            int  counter    = 0;
            bool isDetonate = false;
            List <PlayerStatistic> playerStatistics = new List <PlayerStatistic>(6);
            int       row               = 0;
            int       column            = 0;
            bool      isOnMenu          = true;
            const int nonMineFieldCount = 35;
            bool      isSuccessGame     = false;

            do
            {
                if (isOnMenu)
                {
                    Console.WriteLine("Hajde da igraem na “Mini4KI”. Probvaj si kasmeta da otkriesh poleteta bez mini4ki." +
                                      " Komanda 'top' pokazva klasiraneto, 'restart' po4va nova igra, 'exit' izliza i hajde 4ao!");
                    PrintBoard(board);
                    isOnMenu = false;
                }

                Console.Write("Daj red i kolona : ");

                command = Console.ReadLine().Trim();

                if (command.Length >= 3)
                {
                    if (int.TryParse(command[0].ToString(), out row) &&
                        int.TryParse(command[2].ToString(), out column) &&
                        row <= board.GetLength(0) && column <= board.GetLength(1))
                    {
                        command = "turn";
                    }
                }

                switch (command)
                {
                case "top":
                    PrintStatistic(playerStatistics);
                    break;

                case "restart":
                    board = CreateBoard();
                    bombs = PlaceBombs();
                    PrintBoard(board);
                    isDetonate = false;
                    isOnMenu   = false;
                    break;

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

                case "turn":
                    if (bombs[row, column] != '*')
                    {
                        if (bombs[row, column] == '-')
                        {
                            MakeMove(board, bombs, row, column);
                            counter++;
                        }
                        if (nonMineFieldCount == counter)
                        {
                            isSuccessGame = true;
                        }
                        else
                        {
                            PrintBoard(board);
                        }
                    }
                    else
                    {
                        isDetonate = true;
                    }
                    break;

                default:
                    Console.WriteLine("\nGreshka! nevalidna Komanda\n");
                    break;
                }

                if (isDetonate)
                {
                    PrintBoard(bombs);
                    Console.Write("\nHrrrrrr! Umria gerojski s {0} to4ki. " +
                                  "Daj si niknejm: ", counter);
                    string          name            = Console.ReadLine();
                    PlayerStatistic playerStatistic = new PlayerStatistic(name, counter);

                    if (playerStatistics.Count < 5)
                    {
                        playerStatistics.Add(playerStatistic);
                    }
                    else
                    {
                        for (int i = 0; i < playerStatistics.Count; i++)
                        {
                            if (playerStatistics[i].Score < playerStatistic.Score)
                            {
                                playerStatistics.Insert(i, playerStatistic);
                                playerStatistics.RemoveAt(playerStatistics.Count - 1);
                                break;
                            }
                        }
                    }

                    playerStatistics.Sort((PlayerStatistic firstPlayerStatistic, PlayerStatistic secondPlayerStatistic) => secondPlayerStatistic.Name.CompareTo(firstPlayerStatistic.Name));
                    playerStatistics.Sort((PlayerStatistic firstPlayerStatistic, PlayerStatistic secondPlayerStatistic) => secondPlayerStatistic.Score.CompareTo(firstPlayerStatistic.Score));
                    PrintStatistic(playerStatistics);

                    board      = CreateBoard();
                    bombs      = PlaceBombs();
                    counter    = 0;
                    isDetonate = false;
                    isOnMenu   = true;
                }

                if (isSuccessGame)
                {
                    Console.WriteLine("\nBRAVOOOS! Otvri 35 kletki bez kapka kryv.");
                    PrintBoard(bombs);
                    Console.WriteLine("Daj si imeto, batka: ");
                    string          name            = Console.ReadLine();
                    PlayerStatistic playerStatistic = new PlayerStatistic(name, counter);
                    playerStatistics.Add(playerStatistic);
                    PrintStatistic(playerStatistics);
                    board         = CreateBoard();
                    bombs         = PlaceBombs();
                    counter       = 0;
                    isSuccessGame = false;
                    isOnMenu      = true;
                }
            }while (command != "exit");

            Console.WriteLine("Made in Bulgaria - Uauahahahahaha!");
            Console.WriteLine("AREEEEEEeeeeeee.");
            Console.Read();
        }