public static void Main(string[] args)
        {
            const int Max = 35;
            string command = string.Empty;
            char[,] field = GenerateField();
            char[,] bombs = GenerateBombs();
            int row = 0;
            int column = 0;
            int result = 0;
            List<Score> highScores = new List<Score>(6);
            bool isNewGame = true;
            bool isGameWon = false;
            bool hasExploaded = false;

            do
            {
                if (isNewGame)
                {
                    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!");
                    DrawField(field);
                    isNewGame = 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 <= field.GetLength(0) && column <= field.GetLength(1))
                    {
                        command = "turn";
                    }
                }

                switch (command)
                {
                    case "top":
                        HighScores(highScores);
                        break;
                    case "restart":
                        field = GenerateField();
                        bombs = GenerateBombs();
                        DrawField(field);
                        hasExploaded = false;
                        isNewGame = false;
                        break;
                    case "exit":
                        Console.WriteLine("4a0, 4a0, 4a0!");
                        break;
                    case "turn":
                        if (bombs[row, column] != '*')
                        {
                            if (bombs[row, column] == '-')
                            {
                                PlayersTurn(field, bombs, row, column);
                                result++;
                            }

                            if (Max == result)
                            {
                                isGameWon = true;
                            }
                            else
                            {
                                DrawField(field);
                            }
                        }
                        else
                        {
                            hasExploaded = true;
                        }

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

                if (hasExploaded)
                {
                    DrawField(bombs);
                    Console.Write("\nHrrrrrr! Umria gerojski s {0} to4ki. " + "Daj si niknejm: ", result);
                    string playerName = Console.ReadLine();
                    Score highScore = new Score(playerName, result);

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

                    highScores.Sort((Score firstScore, Score secondScore) => secondScore.Name.CompareTo(firstScore.Name));
                    highScores.Sort((Score firstScore, Score secondScore) => secondScore.Points.CompareTo(firstScore.Points));
                    HighScores(highScores);

                    field = GenerateField();
                    bombs = GenerateBombs();
                    result = 0;
                    hasExploaded = false;
                    isNewGame = true;
                }

                if (isGameWon)
                {
                    Console.WriteLine("\nBRAVOOOS! Otvri 35 kletki bez kapka kryv.");
                    DrawField(bombs);
                    Console.WriteLine("Daj si imeto, batka: ");
                    string imeee = Console.ReadLine();
                    Score to4kii = new Score(imeee, result);
                    highScores.Add(to4kii);
                    HighScores(highScores);
                    field = GenerateField();
                    bombs = GenerateBombs();
                    result = 0;
                    isGameWon = false;
                    isNewGame = true;
                }
            }
            while (command != "exit");

            Console.WriteLine("Made in Bulgaria - Uauahahahahaha!");
            Console.WriteLine("AREEEEEEeeeeeee.");
            Console.Read();
        }
Esempio n. 2
0
        public static void Main(string[] args)
        {
            const int MAX_OPEN_CELLS = 35;

            List<Score> champions = new List<Score>(6);

            string command = string.Empty;
            char[,] playField = CreatePlayfield();
            char[,] bombsField = PutBombs();

            int openCellsCount = 0;
            int row = 0;
            int col = 0;

            bool hitBomb = false;
            bool isNewGame = true;
            bool hasWon = false;

            do
            {
                if (isNewGame)
                {
                    Console.WriteLine("Let's play mines”. Test your luck to find all fields without mines." + Environment.NewLine +
                        " Command 'top' shows the rating, 'restart' starts new game," + Environment.NewLine + "'exit' means Goodbye!");
                    CreateField(playField);
                    isNewGame = false;
                }

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

                switch (command)
                {
                    case "top":
                        GetRating(champions);
                        break;
                    case "restart":
                        playField = CreatePlayfield();
                        bombsField = PutBombs();
                        CreateField(playField);
                        hitBomb = false;
                        isNewGame = false;
                        break;
                    case "exit":
                        Console.WriteLine("Good-bye!");
                        break;
                    case "turn":
                        if (bombsField[row, col] != '*')
                        {
                            if (bombsField[row, col] == '-')
                            {
                                RevealCell(playField, bombsField, row, col);
                                openCellsCount++;
                            }

                            if (MAX_OPEN_CELLS == openCellsCount)
                            {
                                hasWon = true;
                            }
                            else
                            {
                                CreateField(playField);
                            }
                        }
                        else
                        {
                            hitBomb = true;
                        }

                        break;
                    default:
                        Console.WriteLine(Environment.NewLine + "Error! Invalid command" + Environment.NewLine);
                        break;
                }

                if (hitBomb)
                {
                    CreateField(bombsField);
                    Console.Write(Environment.NewLine + "You are dead. Your points are {0}. " + "Write your name: ", openCellsCount);
                    string playerName = Console.ReadLine();
                    Score currentPlayerScore = new Score(playerName, openCellsCount);
                    if (champions.Count < 5)
                    {
                        champions.Add(currentPlayerScore);
                    }
                    else
                    {
                        for (int i = 0; i < champions.Count; i++)
                        {
                            if (champions[i].Points < currentPlayerScore.Points)
                            {
                                champions.Insert(i, currentPlayerScore);
                                champions.RemoveAt(champions.Count - 1);
                                break;
                            }
                        }
                    }

                    champions.Sort((Score firstPlayer, Score secondPlayer) => secondPlayer.Name.CompareTo(firstPlayer.Name));
                    champions.Sort((Score firstPlayer, Score secondPlayer) => secondPlayer.Points.CompareTo(firstPlayer.Points));
                    GetRating(champions);

                    playField = CreatePlayfield();
                    bombsField = PutBombs();
                    openCellsCount = 0;
                    hitBomb = false;
                    isNewGame = true;
                }

                if (hasWon)
                {
                    Console.WriteLine(Environment.NewLine + "Well done! No blood was shown in all 35 moves");
                    CreateField(bombsField);
                    Console.WriteLine("Write your name, please: ");
                    string successfulPlayerName = Console.ReadLine();
                    Score currentPlayerScore = new Score(successfulPlayerName, openCellsCount);
                    champions.Add(currentPlayerScore);
                    GetRating(champions);
                    playField = CreatePlayfield();
                    bombsField = PutBombs();
                    openCellsCount = 0;
                    hasWon = false;
                    isNewGame = true;
                }
            }
            while (command != "exit");

            Console.WriteLine("Made in Bulgaria!");
            Console.WriteLine("Good-bye!");
            Console.Read();
        }
Esempio n. 3
0
        public static void Main(string[] args)
        {
            const int MAX_OPEN_CELLS = 35;

            List <Score> champions = new List <Score>(6);

            string command = string.Empty;

            char[,] playField  = CreatePlayfield();
            char[,] bombsField = PutBombs();

            int openCellsCount = 0;
            int row            = 0;
            int col            = 0;

            bool hitBomb   = false;
            bool isNewGame = true;
            bool hasWon    = false;

            do
            {
                if (isNewGame)
                {
                    Console.WriteLine("Let's play mines”. Test your luck to find all fields without mines." + Environment.NewLine +
                                      " Command 'top' shows the rating, 'restart' starts new game," + Environment.NewLine + "'exit' means Goodbye!");
                    CreateField(playField);
                    isNewGame = false;
                }

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

                switch (command)
                {
                case "top":
                    GetRating(champions);
                    break;

                case "restart":
                    playField  = CreatePlayfield();
                    bombsField = PutBombs();
                    CreateField(playField);
                    hitBomb   = false;
                    isNewGame = false;
                    break;

                case "exit":
                    Console.WriteLine("Good-bye!");
                    break;

                case "turn":
                    if (bombsField[row, col] != '*')
                    {
                        if (bombsField[row, col] == '-')
                        {
                            RevealCell(playField, bombsField, row, col);
                            openCellsCount++;
                        }

                        if (MAX_OPEN_CELLS == openCellsCount)
                        {
                            hasWon = true;
                        }
                        else
                        {
                            CreateField(playField);
                        }
                    }
                    else
                    {
                        hitBomb = true;
                    }

                    break;

                default:
                    Console.WriteLine(Environment.NewLine + "Error! Invalid command" + Environment.NewLine);
                    break;
                }

                if (hitBomb)
                {
                    CreateField(bombsField);
                    Console.Write(Environment.NewLine + "You are dead. Your points are {0}. " + "Write your name: ", openCellsCount);
                    string playerName         = Console.ReadLine();
                    Score  currentPlayerScore = new Score(playerName, openCellsCount);
                    if (champions.Count < 5)
                    {
                        champions.Add(currentPlayerScore);
                    }
                    else
                    {
                        for (int i = 0; i < champions.Count; i++)
                        {
                            if (champions[i].Points < currentPlayerScore.Points)
                            {
                                champions.Insert(i, currentPlayerScore);
                                champions.RemoveAt(champions.Count - 1);
                                break;
                            }
                        }
                    }

                    champions.Sort((Score firstPlayer, Score secondPlayer) => secondPlayer.Name.CompareTo(firstPlayer.Name));
                    champions.Sort((Score firstPlayer, Score secondPlayer) => secondPlayer.Points.CompareTo(firstPlayer.Points));
                    GetRating(champions);

                    playField      = CreatePlayfield();
                    bombsField     = PutBombs();
                    openCellsCount = 0;
                    hitBomb        = false;
                    isNewGame      = true;
                }

                if (hasWon)
                {
                    Console.WriteLine(Environment.NewLine + "Well done! No blood was shown in all 35 moves");
                    CreateField(bombsField);
                    Console.WriteLine("Write your name, please: ");
                    string successfulPlayerName = Console.ReadLine();
                    Score  currentPlayerScore   = new Score(successfulPlayerName, openCellsCount);
                    champions.Add(currentPlayerScore);
                    GetRating(champions);
                    playField      = CreatePlayfield();
                    bombsField     = PutBombs();
                    openCellsCount = 0;
                    hasWon         = false;
                    isNewGame      = true;
                }
            }while (command != "exit");
            Console.WriteLine("Made in Bulgaria!");
            Console.WriteLine("Good-bye!");
            Console.Read();
        }