Пример #1
0
        private static void Main()
        {
            string command = string.Empty;
            char[,] field = CreateGamingField();
            char[,] bombs = PutTheBombs();
            int counter = 0;
            bool explode = false;
            List<LeaderBoard> players = new List<LeaderBoard>(6);
            int row = 0;
            int col = 0;
            bool flag = true;
            bool isFinish = 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!");
                    PrintBoard(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 col)
                        && row <= field.GetLength(0) && col <= field.GetLength(1))
                    {
                        command = "turn";
                    }
                }

                switch (command)
                {
                    case "top":
                        PrintRating(players);
                        break;
                    case "restart":
                        field = CreateGamingField();
                        bombs = PutTheBombs();
                        PrintBoard(field);
                        break;
                    case "exit":
                        Console.WriteLine("4a0, 4a0, 4a0!");
                        break;
                    case "turn":
                        if (bombs[row, col] != '*')
                        {
                            if (bombs[row, col] == '-')
                            {
                                SetPlayerPosition(field, bombs, row, col);
                                counter++;
                            }

                            if (MaxFields == counter)
                            {
                                isFinish = true;
                            }
                            else
                            {
                                PrintBoard(field);
                            }
                        }
                        else
                        {
                            explode = true;
                        }

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

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

                    players.Sort((LeaderBoard r1, LeaderBoard r2) => r2.Name.CompareTo(r1.Name));
                    players.Sort((LeaderBoard r1, LeaderBoard r2) => r2.Points.CompareTo(r1.Points));
                    PrintRating(players);

                    field = CreateGamingField();
                    bombs = PutTheBombs();
                    counter = 0;
                    explode = false;
                    flag = true;
                }

                if (isFinish)
                {
                    Console.WriteLine("\nBRAVOOOS! Otvri 35 kletki bez kapka kryv.");
                    PrintBoard(bombs);
                    Console.WriteLine("Daj si imeto, batka: ");
                    string imeee = Console.ReadLine();
                    LeaderBoard to4kii = new LeaderBoard(imeee, counter);
                    players.Add(to4kii);
                    PrintRating(players);
                    field = CreateGamingField();
                    bombs = PutTheBombs();
                    counter = 0;
                    isFinish = false;
                    flag = true;
                }
            }
            while (command != "exit");
            Console.WriteLine("Made in Bulgaria - Uauahahahahaha!");
            Console.WriteLine("AREEEEEEeeeeeee.");
            Console.Read();
        }
Пример #2
0
        public void Run()
        {
            do
            {
                if (this.hasStarted)
                {
                    Console.WriteLine(
                        "Let's play minesweeper! The top command shows top 5 players, " +
                        "reset command resets the game and the exit " +
                        "command stops the game. Good luck!");
                    DumpGameField(this.gameField);
                    this.hasStarted = false;
                }

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

                    this.ManageCommand();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }

                if (this.hasExploded)
                {
                    DumpGameField(this.mines);
                    Console.Write("\nYou died heroicly with {0} points. " + "Enter your name: ", this.count);
                    string      nickName    = Console.ReadLine();
                    LeaderBoard leaderBoard = new LeaderBoard(nickName, this.count);
                    if (this.champions.Count < 5)
                    {
                        this.champions.Add(leaderBoard);
                    }
                    else
                    {
                        for (int i = 0; i < this.champions.Count; i++)
                        {
                            if (this.champions[i].Points < leaderBoard.Points)
                            {
                                this.champions.Insert(i, leaderBoard);
                                this.champions.RemoveAt(this.champions.Count - 1);
                                break;
                            }
                        }
                    }

                    this.champions.Sort(
                        (LeaderBoard r1, LeaderBoard r2) =>
                        string.Compare(r2.PlayerName, r1.PlayerName, StringComparison.Ordinal));
                    this.champions.Sort((LeaderBoard r1, LeaderBoard r2) => r2.Points.CompareTo(r1.Points));
                    CreateLeaderBoard(this.champions);

                    this.gameField   = CreateGameField();
                    this.mines       = GenerateMines();
                    this.count       = 0;
                    this.hasExploded = false;
                    this.hasStarted  = true;
                }

                if (this.hasEnded)
                {
                    Console.WriteLine("\nCongratulations! You opened 35 cells without spilling any blood!");
                    DumpGameField(this.mines);
                    Console.WriteLine("Enter your name: ");
                    string      name   = Console.ReadLine();
                    LeaderBoard points = new LeaderBoard(name, this.count);
                    this.champions.Add(points);
                    CreateLeaderBoard(this.champions);
                    this.gameField  = CreateGameField();
                    this.mines      = GenerateMines();
                    this.count      = 0;
                    this.hasEnded   = false;
                    this.hasStarted = true;
                }
            }while (this.inputLine != "exit");
            Console.WriteLine("Made in Bulgaria");
            Console.Read();
        }