示例#1
0
        static void Main(string[] args)
        {
            string commandEntry = string.Empty;
            char[,] field = CreatePlayingField();
            char[,] bombs = placeBombs();
            int pointsCounter = 0;
            bool bombActivated = false;
            List<Player> players = new List<Player>(6);
            int row = 0;
            int column = 0;
            bool startGame = true;

            bool maxPointsReached = false;

            do
            {
                if (startGame)
                {
                    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!");
                    showField(field);
                    startGame = false;
                }
                Console.Write("Daj red i kolona : ");
                commandEntry = Console.ReadLine().Trim().ToLower();
                if (commandEntry.Length >= 3)
                {
                    if (int.TryParse(commandEntry[0].ToString(), out row) &&
                    int.TryParse(commandEntry[2].ToString(), out column) &&
                        row <= field.GetLength(0) && column <= field.GetLength(1) &&
                        commandEntry[1] == ' ' && int.Parse(commandEntry[0].ToString()) < FIELD_ROWS &&
                        int.Parse(commandEntry[2].ToString()) < FIELD_COLUMNS)
                    {
                        commandEntry = "turn";
                    }
                }
                switch (commandEntry)
                {
                    case "top":
                        displayRankings(players);
                        break;
                    case "restart":
                        field = CreatePlayingField();
                        bombs = placeBombs();
                        showField(field);
                        bombActivated = false;
                        startGame = false;
                        break;
                    case "exit":
                        Console.WriteLine("4a0, 4a0, 4a0!");
                        break;
                    case "turn":
                        if (bombs[row, column] != '*')
                        {
                            if (bombs[row, column] == '-')
                            {
                                EvaluatePlayersInput(field, bombs, row, column);
                                pointsCounter++;
                            }
                            if (MAXPOINTS == pointsCounter)
                            {
                                maxPointsReached = true;
                            }
                            else
                            {
                                showField(field);
                            }
                        }
                        else
                        {
                            bombActivated = true;
                        }
                        break;
                    default:
                        Console.WriteLine("\nGreshka! nevalidna Komanda\n");
                        break;
                }

                if (bombActivated)
                {
                    showField(bombs);
                    Console.Write("\nHrrrrrr! Umria gerojski s {0} to4ki. " +
                        "Daj si niknejm: ", pointsCounter);
                    string name = Console.ReadLine();
                    Player player = new Player(name, pointsCounter);
                    if (players.Count < 5)
                    {
                        players.Add(player);
                    }
                    else
                    {
                        for (int i = 0; i < players.Count; i++)
                        {
                            if (players[i].Points < player.Points)
                            {
                                players.Insert(i, player);
                                players.RemoveAt(players.Count - 1);
                                break;
                            }
                        }
                    }
                    players.Sort((Player p1, Player p2) => p2.Name.CompareTo(p1.Name));
                    players.Sort((Player p1, Player p2) => p2.Points.CompareTo(p1.Points));
                    displayRankings(players);

                    field = CreatePlayingField();
                    bombs = placeBombs();
                    pointsCounter = 0;
                    bombActivated = false;
                    startGame = true;
                }
                if (maxPointsReached)
                {
                    Console.WriteLine("\nBRAVOOOS! Otvori 35 kletki bez kapka kryv.");
                    showField(bombs);
                    Console.WriteLine("Daj si imeto, batka: ");
                    string name = Console.ReadLine();
                    Player player = new Player(name, pointsCounter);
                    players.Add(player);
                    displayRankings(players);
                    field = CreatePlayingField();
                    bombs = placeBombs();
                    pointsCounter = 0;
                    maxPointsReached = false;
                    startGame = true;
                }
            }
            while (commandEntry != "exit");
            Console.WriteLine("Made in Bulgaria - Uauahahahahaha!");
            Console.WriteLine("AREEEEEEeeeeeee.");
            Console.Read();
        }
示例#2
0
        static void Main(string[] args)
        {
            string command = string.Empty;
            char[,] board = GetBoard();
            char[,] bombs = GetBoardWithBombs();
            int count = 0;
            bool hasExploded = false;
            List<Player> champions = new List<Player>(6);
            int row = 0;
            int col = 0;
            bool hasEndedGame = true;
            const int maxScore = 35;
            const int MinCommandLength = 3;
            bool hasCompletedGame = false;

            do
            {
                if (hasEndedGame)
                {
                    Console.WriteLine("Let's play minesweeper! Try your luck and find the places without bombs.");
                    Console.WriteLine("Enter 'top' to view top players");
                    Console.WriteLine("Enter 'restart' to begin new game");
                    Console.WriteLine("Enter 'exit' to close the game");
                    DisplayBoard(board);
                    hasEndedGame = false;
                }
                Console.Write("Enter row and col: ");
                command = Console.ReadLine().Trim();
                if (command.Length >= MinCommandLength)
                {
                    string[] positions = command.Split(' ');

                    if (int.TryParse(positions[0], out row) &&
                        int.TryParse(positions[1], out col) &&
                        row < board.GetLength(0) && col < board.GetLength(1) &&
                        positions.Length == 2)
                    {
                        command = "turn";
                    }
                }
                switch (command)
                {
                    case "top":
                        DisplayScores(champions);
                        break;
                    case "restart":
                        board = GetBoard();
                        bombs = GetBoardWithBombs();
                        DisplayBoard(board);
                        hasExploded = false;
                        hasEndedGame = false;
                        break;
                    case "exit":
                        Console.WriteLine("Bye-bye!");
                        break;
                    case "turn":
                        if (bombs[row, col] != '*')
                        {
                            if (bombs[row, col] == '-')
                            {
                                PlayTurn(board, bombs, row, col);
                                count++;
                            }
                            if (maxScore == count)
                            {
                                hasCompletedGame = true;
                            }
                            else
                            {
                                DisplayBoard(board);
                            }
                        }
                        else
                        {
                            hasExploded = true;
                        }
                        break;
                    default:
                        Console.WriteLine("\nError! Invalid command or row and col outside the board.\n");
                        break;
                }
                if (hasExploded)
                {
                    DisplayBoard(bombs);
                    Console.Write("\nOwww! You lost. Result: {0} point(s). " + "Enter your nickname: ", count);
                    string nickname = Console.ReadLine();
                    Player newPlayer = new Player(nickname, count);

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

                    champions.Sort((Player first, Player second) => first.Name.CompareTo(second.Name));
                    champions.Sort((Player first, Player second) => second.Points.CompareTo(first.Points));
                    DisplayScores(champions);

                    board = GetBoard();
                    bombs = GetBoardWithBombs();
                    count = 0;
                    hasExploded = false;
                    hasEndedGame = true;
                }
                if (hasCompletedGame)
                {
                    Console.WriteLine("\nCongratulations. You achieved the max score of 35 points!");
                    DisplayBoard(bombs);
                    Console.WriteLine("Enter your name, champion: ");
                    string name = Console.ReadLine();
                    Player player = new Player(name, count);
                    champions.Add(player);
                    DisplayScores(champions);
                    board = GetBoard();
                    bombs = GetBoardWithBombs();
                    count = 0;
                    hasCompletedGame = false;
                    hasEndedGame = true;
                }
            }
            while (command != "exit");
            Console.WriteLine("Made in Bulgaria");
            Console.WriteLine("See you soon.");
            Console.Read();
        }