Ejemplo n.º 1
0
        private static void Main(string[] args)
        {
            string command = string.Empty;
            char[,] gameField = Minesweeper.CreateGameBoard();
            char[,] mines = Minesweeper.SetMines();
            int counter = 0;
            bool isFired = false;
            List<Ranking> winners = new List<Ranking>(6);
            int row = 0;
            int col = 0;
            bool isNewGame = true;
            const int MaxTurns = 35;
            bool areTurnsMaxed = false;

            do
            {
                if (isNewGame)
                {
                    Console.WriteLine(
                        "Let's go! Play the Minesweeper game. The command 'top' show the ranking," +
                        "'restart' - reset the game and command 'exit' - left the game");
                    Minesweeper.SetGameBoard(gameField);
                    isNewGame = false;
                }

                Console.Write("Enter row and col : ");
                command = Console.ReadLine().Trim();
                if (command.Length >= 3)
                {
                    if (int.TryParse(command[0].ToString(), out row) &&
                        int.TryParse(command[2].ToString(), out col) &&
                        row <= gameField.GetLength(0) &&
                        col <= gameField.GetLength(1))
                    {
                        command = "turn";
                    }
                }

                switch (command)
                {
                    case "top":
                        Minesweeper.GetRanking(winners);
                        break;
                    case "restart":
                        gameField = Minesweeper.CreateGameBoard();
                        mines = Minesweeper.SetMines();
                        Minesweeper.SetGameBoard(gameField);
                        isFired = false;
                        isNewGame = false;
                        break;
                    case "exit":
                        Console.WriteLine("Bye, Bye!");
                        break;
                    case "turn":
                        if (mines[row, col] != '*')
                        {
                            if (mines[row, col] == '-')
                            {
                                Minesweeper.SwitchTurn(gameField, mines, row, col);
                                counter++;
                            }

                            if (MaxTurns == counter)
                            {
                                areTurnsMaxed = true;
                            }
                            else
                            {
                                Minesweeper.SetGameBoard(gameField);
                            }
                        }
                        else
                        {
                            isFired = true;
                        }

                        break;
                    default:
                        Console.WriteLine("\nError! Invalid command!\n");
                        break;
                }

                if (isFired)
                {
                    Minesweeper.SetGameBoard(mines);
                    Console.WriteLine("\n Game over! You died a hero with : {0} points. Enter your nickname : ", counter);
                    string nickname = Console.ReadLine();
                    Ranking winner = new Ranking(nickname, counter);
                    int winnersLimit = 5;
                    if (winners.Count < winnersLimit)
                    {
                        winners.Add(winner);
                    }
                    else
                    {
                        for (int i = 0; i < winners.Count; i++)
                        {
                            if (winners[i].Points < winner.Points)
                            {
                                winners.Insert(i, winner);
                                winners.RemoveAt(winners.Count - 1);
                                break;
                            }
                        }
                    }

                    winners.Sort((Ranking ranking1, Ranking ranking2) => ranking2.Name.CompareTo(ranking1.Name));
                    winners.Sort((Ranking ranking1, Ranking ranking2) => ranking2.Points.CompareTo(ranking1.Points));
                    Minesweeper.GetRanking(winners);

                    gameField = Minesweeper.CreateGameBoard();
                    mines = Minesweeper.SetMines();
                    counter = 0;
                    isFired = false;
                    isNewGame = true;
                }

                if (areTurnsMaxed)
                {
                    Console.WriteLine("\ncongratulations! You find 35 cells without hurt yourself!");
                    Minesweeper.SetGameBoard(mines);
                    Console.WriteLine("Enter your name: ");
                    string name = Console.ReadLine();
                    Ranking points = new Ranking(name, counter);
                    winners.Add(points);
                    Minesweeper.GetRanking(winners);
                    gameField = Minesweeper.CreateGameBoard();
                    mines = Minesweeper.SetMines();
                    counter = 0;
                    areTurnsMaxed = false;
                    isNewGame = true;
                }
            }
            while (command != "exit");
            Console.Read();
        }
        private static void Main(string[] args)
        {
            string command = string.Empty;
            char[,] field = CreatePlayingField();
            char[,] bombs = AddBombs();
            int counter = 0;
            bool isBoom = false;
            List<Ranking> winners = new List<Ranking>(6);
            int row = 0;
            int coll = 0;
            bool flag = true;
            const int max = 35;
            bool flag2 = false;

            do
            {
                if (flag)
                {
                    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!");
                    dumpp(field);
                    flag = 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 coll)
                        && row <= field.GetLength(0) && coll <= field.GetLength(1))
                    {
                        command = "turn";
                    }
                }

                switch (command)
                {
                    case "top":
                        ShowRank(winners);
                        break;
                    case "restart":
                        field = CreatePlayingField();
                        bombs = AddBombs();
                        dumpp(field);
                        isBoom = false;
                        flag = false;
                        break;
                    case "exit":
                        Console.WriteLine("4a0, 4a0, 4a0!");
                        break;
                    case "turn":
                        if (bombs[row, coll] != '*')
                        {
                            if (bombs[row, coll] == '-')
                            {
                                Move(field, bombs, row, coll);
                                counter++;
                            }

                            if (max == counter)
                            {
                                flag2 = true;
                            }
                            else
                            {
                                dumpp(field);
                            }
                        }
                        else
                        {
                            isBoom = true;
                        }

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

                if (isBoom)
                {
                    dumpp(bombs);
                    Console.Write("\nHrrrrrr! Umria gerojski s {0} to4ki. " + "Daj si niknejm: ", counter);
                    string nickname = Console.ReadLine();
                    Ranking t = new Ranking(nickname, counter);
                    if (winners.Count < 5)
                    {
                        winners.Add(t);
                    }
                    else
                    {
                        for (int i = 0; i < winners.Count; i++)
                        {
                            if (winners[i].Points < t.Points)
                            {
                                winners.Insert(i, t);
                                winners.RemoveAt(winners.Count - 1);
                                break;
                            }
                        }
                    }

                    winners.Sort((Ranking r1, Ranking r2) => r2.Player.CompareTo(r1.Player));
                    winners.Sort((Ranking r1, Ranking r2) => r2.Points.CompareTo(r1.Points));
                    ShowRank(winners);

                    field = CreatePlayingField();
                    bombs = AddBombs();
                    counter = 0;
                    isBoom = false;
                    flag = true;
                }

                if (flag2)
                {
                    Console.WriteLine("\nBRAVOOOS! Otvri 35 kletki bez kapka kryv.");
                    dumpp(bombs);
                    Console.WriteLine("Daj si imeto, batka: ");
                    string name = Console.ReadLine();
                    Ranking score = new Ranking(name, counter);
                    winners.Add(score);
                    ShowRank(winners);
                    field = CreatePlayingField();
                    bombs = AddBombs();
                    counter = 0;
                    flag2 = false;
                    flag = true;
                }
            }
            while (command != "exit");
            Console.WriteLine("Made in Bulgaria - Uauahahahahaha!");
            Console.WriteLine("AREEEEEEeeeeeee.");
            Console.Read();
        }