public void PlayerWithNameEndingWithWhiteSpacesTest()
 {
     int scores = 5;
     string name = " Ivan Popov                 ";
     Player player = new Player(name, scores);
     string actualName = player.Name;
     string expectedName = "Ivan Popov";
     Assert.AreEqual(expectedName, actualName);
 }
 public void PlayerWithMaxScoresTest()
 {
     string name = "Pesho Petrov";
     int maxPossibleScores = (LevelOptions.ColsCount * LevelOptions.RowsCount) - LevelOptions.MinesCount;
     Player player = new Player(name, maxPossibleScores);
     int acutalScores = player.Scores;
     int expectedScores = maxPossibleScores;
     Assert.AreEqual(expectedScores, acutalScores);
 }
 public void PlayerWithFiveScoresTest()
 {
     string name = "Pesho Petrov";
     int scores = 5;
     Player player = new Player(name, scores);
     int acutalScores = player.Scores;
     int expectedScores = scores;
     Assert.AreEqual(expectedScores, acutalScores);
 }
Exemple #4
0
 private static void AttemptFieldClearedAction(ref bool isFieldCleared, List<Player> topPlayers,
     ref char[,] mines, ref int count, ref char[,] field, ref bool isNewGame)
 {
     if (isFieldCleared)
     {
         Console.WriteLine();
         Console.WriteLine(WinMessage, MaxPoints);
         PrintFieldState(mines);
         Console.Write(EnterNicknameMessage);
         string name = Console.ReadLine();
         Player player = new Player(name, count);
         topPlayers.Add(player);
         PrintScoreboard(topPlayers);
         field = CreateField();
         mines = ArmMines();
         count = 0;
         isFieldCleared = false;
         isNewGame = true;
     }
 }
        public static List<Player> UpdateResults(List<Player> champions, Player player)
        {
            if (champions.Count < CHAMPIONS_LIST_SIZE - 1)
            {
                champions.Add(player);
            }
            else
            {
                for (int position = 0; position < champions.Count; position++)
                {
                    if (champions[position].Scores < player.Scores)
                    {
                        champions.Insert(position, player);
                        champions.RemoveAt(champions.Count - 1);
                        break;
                    }
                }
            }

            champions.Sort((Player first, Player second) => second.Name.CompareTo(first.Name));
            champions.Sort((Player first, Player second) => second.Scores.CompareTo(first.Scores));
            return champions;
        }
        public static void Start()
        {
            string command = string.Empty;
            char[,] gameBoard = CreateGameBoard();
            char[,] mines = CreateMines();
            int counter = 0;
            bool isBlasted = false;
            List<Player> scoreList = new List<Player>(6);
            int row = 0;
            int col = 0;
            bool areInstructionsShown = true;
            const int MaxNumberOfMoves = 35;
            bool isGameWon = false;

            do
            {
                if (areInstructionsShown)
                {
                    Console.WriteLine("Let's play minesweeper!”. Try finding the squares without mines." +
                    " Command 'top' - shows the score list,\n 'restart' - begins a new game,\n 'exit' - exits the game");
                    DrawGameBoard(gameBoard);
                    areInstructionsShown = false;
                }

                Console.Write("Pick a row and a 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 <= gameBoard.GetLength(0) && col <= gameBoard.GetLength(1))
                    {
                        command = "turn";
                    }
                }

                switch (command)
                {
                    case "top":
                        ShowScoreList(scoreList);
                        break;
                    case "restart":
                        gameBoard = CreateGameBoard();
                        mines = CreateMines();
                        DrawGameBoard(gameBoard);
                        isBlasted = false;
                        areInstructionsShown = false;
                        break;
                    case "exit":
                        Console.WriteLine("Goodbye!");
                        break;
                    case "turn":
                        if (mines[row, col] != '*')
                        {
                            if (mines[row, col] == '-')
                            {
                                MakeMove(gameBoard, mines, row, col);
                                counter++;
                            }

                            if (MaxNumberOfMoves == counter)
                            {
                                isGameWon = true;
                            }
                            else
                            {
                                DrawGameBoard(gameBoard);
                            }
                        }
                        else
                        {
                            isBlasted = true;
                        }

                        break;
                    default:
                        Console.WriteLine("\nUnknown Command!\n");
                        break;
                }

                if (isBlasted)
                {
                    DrawGameBoard(mines);
                    Console.Write("\nGame over! You have {0} points. " + "Enter your name: ", counter);
                    string nickname = Console.ReadLine();
                    Player t = new Player(nickname, counter);
                    if (scoreList.Count < 5)
                    {
                        scoreList.Add(t);
                    }
                    else
                    {
                        for (int i = 0; i < scoreList.Count; i++)
                        {
                            if (scoreList[i].NumberOfPoints < t.NumberOfPoints)
                            {
                                scoreList.Insert(i, t);
                                scoreList.RemoveAt(scoreList.Count - 1);
                                break;
                            }
                        }
                    }

                    scoreList.Sort((Player r1, Player r2) => r2.Name.CompareTo(r1.Name));
                    scoreList.Sort((Player r1, Player r2) => r2.NumberOfPoints.CompareTo(r1.NumberOfPoints));
                    ShowScoreList(scoreList);

                    gameBoard = CreateGameBoard();
                    mines = CreateMines();
                    counter = 0;
                    isBlasted = false;
                    areInstructionsShown = true;
                }

                if (isGameWon)
                {
                    Console.WriteLine("\nCongratulations! You have opened 35 squares!");
                    DrawGameBoard(mines);
                    Console.WriteLine("Write your nickname: ");
                    string imeee = Console.ReadLine();
                    Player to4kii = new Player(imeee, counter);
                    scoreList.Add(to4kii);
                    ShowScoreList(scoreList);
                    gameBoard = CreateGameBoard();
                    mines = CreateMines();
                    counter = 0;
                    isGameWon = false;
                    areInstructionsShown = true;
                }
            }
            while (command != "exit");
            Console.WriteLine("Made in Bulgaria!");
            Console.WriteLine("Goodbye.");
            Console.Read();
        }
Exemple #7
0
        public static void Main(string[] args)
        {
            string command = string.Empty;

            char[,] playfield = CreatePlayfield();
            char[,] mines = SetMines();

            List<Player> topPlayers = new List<Player>(6);

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

            bool hasExploded = false;
            bool isNewGame = true;
            bool hasReachedMaxCellsOpen = false;

            do
            {
                if (isNewGame)
                {
                    Console.WriteLine("Let's play \"Minesweeper\". Try to find all cells without steping on a mine.\n" +
                                      "Commands:\n" +
                                      "'top' shows players results,\n" +
                                      "'restart' restart game and begin a new one,\n" +
                                      "'exit' exits the game!\n");
                    DisplayPlayfield(playfield);
                    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 <= playfield.GetLength(0) &&
                        col <= playfield.GetLength(1))
                    {
                        command = "turn";
                    }
                }

                switch (command)
                {
                    case "top":
                        DisplayPlayerResults(topPlayers);
                        break;
                    case "restart":
                        playfield = CreatePlayfield();
                        mines = SetMines();
                        DisplayPlayfield(playfield);

                        hasExploded = false;
                        isNewGame = false;
                        break;
                    case "exit":
                        Console.WriteLine("Bye, bye!");
                        break;
                    case "turn":
                        if (mines[row, col] != '*')
                        {
                            if (mines[row, col] == '-')
                            {
                                UpdateOpenCellsCount(playfield, mines, row, col);
                                openCellsCount++;
                            }

                            if (MaxOpenCellsCount == openCellsCount)
                            {
                                hasReachedMaxCellsOpen = true;
                            }
                            else
                            {
                                DisplayPlayfield(playfield);
                            }
                        }
                        else
                        {
                            hasExploded = true;
                        }

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

                if (hasExploded)
                {
                    DisplayPlayfield(mines);

                    Console.Write("\nYou die with {0} points ", openCellsCount);
                    string nickName = Console.ReadLine();

                    Player currentPlayer = new Player(nickName, openCellsCount);

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

                    topPlayers.Sort((Player r1, Player r2) => r2.Name.CompareTo(r1.Name));
                    topPlayers.Sort((Player r1, Player r2) => r2.Points.CompareTo(r1.Points));

                    DisplayPlayerResults(topPlayers);

                    playfield = CreatePlayfield();
                    mines = SetMines();

                    openCellsCount = 0;
                    hasExploded = false;
                    isNewGame = true;
                }

                if (hasReachedMaxCellsOpen)
                {
                    Console.WriteLine("\nCongratulations! You have successfully opened {0} cells", MaxOpenCellsCount);
                    DisplayPlayfield(mines);

                    Console.WriteLine("Enter your nick name: ");
                    string nickName = Console.ReadLine();
                    Player currentPlayer = new Player(nickName, openCellsCount);

                    topPlayers.Add(currentPlayer);
                    DisplayPlayerResults(topPlayers);

                    playfield = CreatePlayfield();
                    mines = SetMines();

                    openCellsCount = 0;
                    hasReachedMaxCellsOpen = false;
                    isNewGame = true;
                }
            }
            while (command != "exit");

            Console.WriteLine("Made in Bulgaria!");
            Console.Read();
        }
        private static void Main()
        {
            string command;
            char[,] board = CreatBoard();
            char[,] bombs = PutBombs();
            int counter = 0;
            bool boom = false;
            var players = new List<Player>(6);
            int row = 0;
            int column = 0;
            bool flag = true;
            const int Max = 35;
            bool flag2 = false;

            do
            {
                if (flag)
                {
                    Console.WriteLine("Let's to play Minesweeper. Try to find a mine-free fields. Good luck!");
                    Console.WriteLine();
                    Console.WriteLine("Commands:");
                    Console.WriteLine("\"top\" - show rating");
                    Console.WriteLine("\"restart\" - start new game");
                    Console.WriteLine("\"exit\" - exit of game");

                    Dumpp(board);
                    flag = 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 column)
                        && row <= board.GetLength(0) && column <= board.GetLength(1))
                    {
                        command = "turn";
                    }
                }

                switch (command)
                {
                    case "top":
                        DisplayRating(players);
                        break;
                    case "restart":
                        board = CreatBoard();
                        bombs = PutBombs();
                        Dumpp(board);
                        boom = false;
                        flag = false;
                        break;
                    case "turn":
                        if (bombs[row, column] != '*')
                        {
                            if (bombs[row, column] == '-')
                            {
                                SetPlaeyrTurn(board, bombs, row, column);
                                counter++;
                            }

                            if (Max == counter)
                            {
                                flag2 = true;
                            }
                            else
                            {
                                Dumpp(board);
                            }
                        }
                        else
                        {
                            boom = true;
                        }

                        break;
                    default:
                        Console.WriteLine("\n\n");
                        break;
                }

                if (boom)
                {
                    Dumpp(bombs);
                    Console.Write("\n Nice game! Your score is {0} " + "\nWrite your nickname: ", counter);
                    string nickname = Console.ReadLine();
                    var t = new Player(nickname, 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((r1, r2) => r2.Name.CompareTo(r1.Name));
                    players.Sort((r1, r2) => r2.Points.CompareTo(r1.Points));
                    DisplayRating(players);

                    board = CreatBoard();
                    bombs = PutBombs();
                    counter = 0;
                    boom = false;
                    flag = true;
                }

                if (flag2)
                {
                    Console.WriteLine("\nBravo! You win!");
                    Dumpp(bombs);
                    Console.WriteLine("Write your nickname: ");
                    string nickname = Console.ReadLine();
                    var points = new Player(nickname, counter);
                    players.Add(points);
                    DisplayRating(players);
                    board = CreatBoard();
                    bombs = PutBombs();
                    counter = 0;
                    flag2 = false;
                    flag = true;
                }
            }
            while (command != "exit");
            Console.WriteLine("\nGood bye!");
            Console.Read();
        }
        public static void Main()
        {
            string command = string.Empty;
            var gameField = CreateEmptyField();
            var mines = PlaceMines();
            int cellsOpened = 0;
            bool boom = false;
            var topPlayers = new List<Player>(6);
            int row = 0;
            int col = 0;
            bool startGame = true;            
            bool gameFinished = 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!");
                    DrawField(gameField);
                    startGame = 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 <= gameField.GetLength(0) && col <= gameField.GetLength(1))
                    {
                        command = "turn";
                    }
                }

                switch (command)
                {
                    case "top":
                        PrintScoreBoard(topPlayers);
                        break;
                    case "restart":
                        gameField = CreateEmptyField();
                        mines = PlaceMines();
                        DrawField(gameField);
                        boom = false;
                        startGame = false;
                        break;
                    case "exit":
                        Console.WriteLine("4a0, 4a0, 4a0!");
                        break;
                    case "turn":
                        if (mines[row, col] != '*')
                        {
                            if (mines[row, col] == '-')
                            {
                                UpdateField(gameField, mines, row, col);
                                cellsOpened++;
                            }

                            if (cellsOpened == MaxEmptyCells)
                            {
                                gameFinished = true;
                            }
                            else
                            {
                                DrawField(gameField);
                            }
                        }
                        else
                        {
                            boom = true;
                        }

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

                if (boom)
                {
                    DrawField(mines);
                    Console.Write("\nHrrrrrr! Umria gerojski s {0} to4ki. " + "Daj si niknejm: ", cellsOpened);
                    string nickname = Console.ReadLine();
                    var player = new Player(nickname, cellsOpened);
                    if (topPlayers.Count < 5)
                    {
                        topPlayers.Add(player);
                    }
                    else
                    {
                        for (int i = 0; i < topPlayers.Count; i++)
                        {
                            if (topPlayers[i].Points < player.Points)
                            {
                                topPlayers.Insert(i, player);
                                topPlayers.RemoveAt(topPlayers.Count - 1);
                                break;
                            }
                        }
                    }

                    topPlayers.Sort((Player r1, Player r2) => r2.Name.CompareTo(r1.Name));
                    topPlayers.Sort((Player r1, Player r2) => r2.Points.CompareTo(r1.Points));
                    PrintScoreBoard(topPlayers);

                    gameField = CreateEmptyField();
                    mines = PlaceMines();
                    cellsOpened = 0;
                    boom = false;
                    startGame = true;
                }

                if (gameFinished)
                {
                    Console.WriteLine("\nBRAVOOOS! Otvri 35 kletki bez kapka kryv.");
                    DrawField(mines);
                    Console.WriteLine("Daj si imeto, batka: ");
                    string name = Console.ReadLine();
                    var score = new Player(name, cellsOpened);
                    topPlayers.Add(score);
                    PrintScoreBoard(topPlayers);
                    gameField = CreateEmptyField();
                    mines = PlaceMines();
                    cellsOpened = 0;
                    gameFinished = false;
                    startGame = true;
                }
            }
            while (command != "exit");
            Console.WriteLine("Made in Bulgaria - Uauahahahahaha!");
            Console.WriteLine("AREEEEEEeeeeeee.");
            Console.Read();
        }
Exemple #10
0
        internal static void Start()
        {
            const int MOVES_TO_WIN = 35;
            string command = string.Empty;
            char[,] playfield = GeneratePlayfield();
            char[,] minefield = GenerateMinefield();
            int counter = 0;
            bool gameOver = false;
            List<Player> players = new List<Player>(6);
            int row = 0;
            int col = 0;
            bool showInstructions = true;
            bool gameWon = false;

            do
            {
                if (showInstructions)
                {
                    Console.WriteLine("Welcome to minesweeper game! See if you could get lucky and find all the fields without mines." +
                    " Command 'top' shows the top scorers, 'restart' begins new game, 'exit' exits the game!");
                    RenderField(playfield);
                    showInstructions = false;
                }

                Console.Write("Please enter row and column separated by space or command: ");
                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":
                        RenderRanklist(players);
                        break;
                    case "restart":
                        playfield = GeneratePlayfield();
                        minefield = GenerateMinefield();
                        RenderField(playfield);
                        gameOver = false;
                        showInstructions = false;
                        break;
                    case "exit":
                        Console.WriteLine("4a0, 4a0, 4a0!");
                        break;
                    case "turn":
                        if (minefield[row, col] != '*')
                        {
                            if (minefield[row, col] == '-')
                            {
                                MakeMove(playfield, minefield, row, col);
                                counter++;
                            }

                            if (MOVES_TO_WIN == counter)
                            {
                                gameWon = true;
                            }
                            else
                            {
                                RenderField(playfield);
                            }
                        }
                        else
                        {
                            gameOver = true;
                        }

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

                if (gameOver)
                {
                    RevealMinefield(minefield);
                    RenderField(minefield);
                    Console.Write(
                        "\nGame Over. Score: {0} points. " +
                        "Enter nick: ",
                        counter);
                    string nickname = Console.ReadLine();
                    Player player = new Player(nickname, counter);
                    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 r1, Player r2) => r2.Name.CompareTo(r1.Name));
                    players.Sort((Player r1, Player r2) => r2.Points.CompareTo(r1.Points));
                    RenderRanklist(players);

                    playfield = GeneratePlayfield();
                    minefield = GenerateMinefield();
                    counter = 0;
                    gameOver = false;
                    showInstructions = true;
                }

                if (gameWon)
                {
                    Console.WriteLine("\nCongratulations! You discovered all the 35 safe cells.");
                    RenderField(minefield);
                    Console.WriteLine("Enter your nick: ");
                    string imeee = Console.ReadLine();
                    Player player = new Player(imeee, counter);
                    players.Add(player);
                    RenderRanklist(players);
                    playfield = GeneratePlayfield();
                    minefield = GenerateMinefield();
                    counter = 0;
                    gameWon = false;
                    showInstructions = true;
                }
            }
            while (command != "exit");
            Console.WriteLine("Thank you for playing!");
            Console.Read();
        }
Exemple #11
0
 public void PlayerWithNullNameTest()
 {
     string name = null;
     int scores = 5;
     Player player = new Player(name, scores);
 }
Exemple #12
0
 public void PlayerWithNegativeScoresTest()
 {
     string name = "Pesho Petrov";
     int scores = -1;
     Player player = new Player(name, scores);
 }
Exemple #13
0
 public void PlayerWithMoreScoresThanPossibleTest()
 {
     string name = "Pesho Petrov";
     int scores = 150;
     Player player = new Player(name, scores);
 }
Exemple #14
0
 public void PlayerWithEmptyNameTest()
 {
     string name = string.Empty;
     int scores = 5;
     Player player = new Player(name, scores);
 }
        public static void Main()
        {
            string command = string.Empty;
            char[,] field = CreateGameField();
            char[,] bombs = CreateBombs();
            int points = 0;
            bool isDead = false;
            List<Player> highscores = new List<Player>(6);
            int row = 0;
            int column = 0;
            bool isGameStarted = true;
            const int MaxScore = 35;
            bool isGameCompleted = false;

            do
            {
                if (isGameStarted)
                {
                    Console.WriteLine("Lets play a game of “Minesweeper”. Try to find the fields without mines in them." +
                    " command 'top' shows the highscore list, 'restart' starts new game, 'exit' exits the application!");
                    DrawGameField(field);
                    isGameStarted = false;
                }

                Console.Write("Type 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 column) &&
                        row <= field.GetLength(0) && column <= field.GetLength(1))
                    {
                        command = "turn";
                    }
                }

                switch (command)
                {
                    case "top":
                        CreateHighscoreList(highscores);
                        break;
                    case "restart":
                        field = CreateGameField();
                        bombs = CreateBombs();
                        DrawGameField(field);
                        isDead = false;
                        isGameStarted = false;
                        break;
                    case "exit":
                        Console.WriteLine("Bye, bye!");
                        break;
                    case "turn":
                        if (bombs[row, column] != '*')
                        {
                            if (bombs[row, column] == '-')
                            {
                                PlayerTurn(field, bombs, row, column);
                                points++;
                            }

                            if (MaxScore == points)
                            {
                                isGameCompleted = true;
                            }
                            else
                            {
                                DrawGameField(field);
                            }
                        }
                        else
                        {
                            isDead = true;
                        }

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

                if (isDead)
                {
                    DrawGameField(bombs);
                    Console.Write("\nHrrrrrr! You died with {0} points. " + "Type your nickname: ", points);
                    string nickname = Console.ReadLine();
                    Player playerPoints = new Player(nickname, points);

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

                    highscores.Sort((Player firstPlayer, Player secondPlayer) => secondPlayer.Name.CompareTo(firstPlayer.Name));
                    highscores.Sort((Player firstPlayer, Player secondPlayer) => secondPlayer.Points.CompareTo(firstPlayer.Points));
                    CreateHighscoreList(highscores);

                    field = CreateGameField();
                    bombs = CreateBombs();
                    points = 0;
                    isDead = false;
                    isGameStarted = true;
                }

                if (isGameCompleted)
                {
                    Console.WriteLine("\nBRAVO! You opened 35 cells without dying.");
                    DrawGameField(bombs);
                    Console.WriteLine("Daj si imeto, batka: ");

                    string name = Console.ReadLine();
                    Player currentPlayer = new Player(name, points);

                    highscores.Add(currentPlayer);
                    CreateHighscoreList(highscores);
                    field = CreateGameField();
                    bombs = CreateBombs();
                    points = 0;
                    isGameCompleted = false;
                    isGameStarted = true;
                }
            }
            while (command != "exit");

            Console.WriteLine("Made in Bulgaria!");
            Console.WriteLine("Goodbye!");
            Console.Read();
        }
Exemple #16
0
        public static void Main(string[] args)
        {
            string userMenuChoice = string.Empty;
            char[,] gameField = CreateGameField();
            char[,] enemy = PlaceBombs();
            int turnsCount = 0;
            bool isBombField = false;
            List<Player> winners = new List<Player>(6);
            int row = 0;
            int column = 0;
            const int MaxTurns = 35;
            bool isMenu = true;
            bool isWin = false;

            do
            {
                if (isMenu)
                {
                    Console.WriteLine("Let's play \"Minesweeper\". Try finding the fields without bombs."
                        + " Command 'top' shows the current ranking, 'restart' starts a new game, 'exit' exits and goodbye!");
                    ShowObject(gameField);
                    isMenu = false;
                }

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

                switch (userMenuChoice)
                {
                    case "top":
                        ShowRanking(winners);
                        break;
                    case "restart":
                        gameField = CreateGameField();
                        enemy = PlaceBombs();
                        ShowObject(gameField);
                        isBombField = false;
                        isMenu = false;
                        break;
                    case "exit":
                        Console.WriteLine("Goodbye!");
                        break;
                    case "turn":
                        if (enemy[row, column] != '*')
                        {
                            if (enemy[row, column] == '-')
                            {
                                PlayerMove(gameField, enemy, row, column);
                                turnsCount++;
                            }

                            if (turnsCount == MaxTurns)
                            {
                                isWin = true;
                            }
                            else
                            {
                                ShowObject(gameField);
                            }
                        }
                        else
                        {
                            isBombField = true;
                        }

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

                if (isBombField)
                {
                    ShowObject(enemy);
                    Console.Write("\nGame Over! Score {0}. Enter Nickname: ", turnsCount);
                    string nickname = Console.ReadLine();
                    Player winner = new Player(nickname, turnsCount);
                    if (winners.Count < 5)
                    {
                        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((Player winnerOne, Player winnerTwo) => winnerTwo.Name.CompareTo(winnerOne.Name));
                    winners.Sort((Player winnerOne, Player winnerTwo) => winnerTwo.Points.CompareTo(winnerOne.Points));
                    ShowRanking(winners);

                    gameField = CreateGameField();
                    enemy = PlaceBombs();
                    turnsCount = 0;
                    isBombField = false;
                    isMenu = true;
                }

                if (isWin)
                {
                    Console.WriteLine("\nYou win.");
                    ShowObject(enemy);
                    Console.WriteLine("Your name: ");
                    string name = Console.ReadLine();
                    Player winner = new Player(name, turnsCount);
                    winners.Add(winner);
                    ShowRanking(winners);
                    gameField = CreateGameField();
                    enemy = PlaceBombs();
                    turnsCount = 0;
                    isWin = false;
                    isMenu = true;
                }
            }
            while (userMenuChoice != "exit");
            Console.WriteLine("Goodbye!");
            Console.Read();
        }
 public void TryToSignInTopPlayerList(Player player)
 {
     TopPlayers.Add(player);
     FilterTopFivePlayers();
 }
Exemple #18
0
        public static void Main()
        {
            string command = string.Empty;
            char[,] field = MakeField();
            char[,] mines = MakeMines();
            int cellsOpened = 0;
            bool isGameOver = false;
            List<Player> champions = new List<Player>(6);
            int row = 0;
            int col = 0;
            bool isFirstMove = true;
            const int ТotalCells = 35;
            bool allCellsOpened = false;

            do
            {
                if (isFirstMove)
                {
                    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!");
                    PrintField(field);
                    isFirstMove = 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":
                        PrintScoreBoard(champions);
                        break;
                    case "restart":
                        field = MakeField();
                        mines = MakeMines();
                        PrintField(field);
                        isGameOver = false;
                        isFirstMove = false;
                        break;
                    case "exit":
                        Console.WriteLine("4a0, 4a0, 4a0!");
                        break;
                    case "turn":
                        if (mines[row, col] != '*')
                        {
                            if (mines[row, col] == '-')
                            {
                                MakeMove(field, mines, row, col);
                                cellsOpened++;
                            }

                            if (cellsOpened == ТotalCells)
                            {
                                allCellsOpened = true;
                            }
                            else
                            {
                                PrintField(field);
                            }
                        }
                        else
                        {
                            isGameOver = true;
                        }

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

                if (isGameOver)
                {
                    PrintField(mines);
                    Console.Write("\nHrrrrrr! Umria gerojski s {0} to4ki. " + "Daj si niknejm: ", cellsOpened);
                    string playerName = Console.ReadLine();
                    Player player = new Player(playerName, cellsOpened);
                    if (champions.Count < 5)
                    {
                        champions.Add(player);
                    }
                    else
                    {
                        for (int i = 0; i < champions.Count; i++)
                        {
                            if (champions[i].Points < player.Points)
                            {
                                champions.Insert(i, player);
                                champions.RemoveAt(champions.Count - 1);
                                break;
                            }
                        }
                    }

                    champions.Sort((Player p1, Player p2) => p2.Name.CompareTo(p1.Name));
                    champions.Sort((Player p1, Player p2) => p2.Points.CompareTo(p1.Points));
                    PrintScoreBoard(champions);

                    field = MakeField();
                    mines = MakeMines();
                    cellsOpened = 0;
                    isGameOver = false;
                    isFirstMove = true;
                }

                if (allCellsOpened)
                {
                    Console.WriteLine("\nBRAVOOOS! Otvri 35 kletki bez kapka kryv.");
                    PrintField(mines);
                    Console.WriteLine("Daj si imeto, batka: ");
                    string name = Console.ReadLine();
                    Player player = new Player(name, cellsOpened);
                    champions.Add(player);
                    PrintScoreBoard(champions);
                    field = MakeField();
                    mines = MakeMines();
                    cellsOpened = 0;
                    allCellsOpened = false;
                    isFirstMove = true;
                }
            }
            while (command != "exit");
            {
                Console.WriteLine("Made in Bulgaria - Uauahahahahaha!");
                Console.WriteLine("AREEEEEEeeeeeee.");
                Console.Read();
            }
        }
        public static void Main()
        {
            const int MaxCellsWithoutMines = 35;
            string command = string.Empty;
            char[,] playfield = CreatePlayfiled();
            char[,] mines = PlaceMines();
            int row = 0;
            int col = 0;
            int pointsCount = 0;
            bool gameStarted = true;
            bool gameWon = false;
            bool gameOver = false;
            List<Player> players = new List<Player>(6);

            do
            {
                if (gameStarted)
                {
                    Console.WriteLine("Let's play \"Minesweeper\". Try find the mine-free cells." +
                        " Command 'top' shows highscores, 'restart' starts a new game, 'exit' quits the game!");
                    ShowPlayfield(playfield);
                    gameStarted = 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":
                        ShowHighscores(players);
                        break;
                    case "restart":
                        playfield = CreatePlayfiled();
                        mines = PlaceMines();
                        ShowPlayfield(playfield);
                        gameOver = false;
                        gameStarted = false;
                        break;
                    case "exit":
                        Console.WriteLine("Bye bye!");
                        break;
                    case "turn":
                        if (mines[row, col] != '*')
                        {
                            if (mines[row, col] == '-')
                            {
                                MakeMove(playfield, mines, row, col);
                                pointsCount++;
                            }

                            if (MaxCellsWithoutMines == pointsCount)
                            {
                                gameWon = true;
                            }
                            else
                            {
                                ShowPlayfield(playfield);
                            }
                        }
                        else
                        {
                            gameOver = true;
                        }

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

                if (gameOver)
                {
                    ShowPlayfield(mines);
                    Console.Write("\nGame Over! You died with {0} points. Enter your nickname: ", pointsCount);
                    string nickname = Console.ReadLine();
                    Player player = new Player(nickname, pointsCount);
                    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 r1, Player r2) => r2.Name.CompareTo(r1.Name));
                    players.Sort((Player r1, Player r2) => r2.Points.CompareTo(r1.Points));
                    ShowHighscores(players);

                    playfield = CreatePlayfiled();
                    mines = PlaceMines();
                    pointsCount = 0;
                    gameOver = false;
                    gameStarted = true;
                }

                if (gameWon)
                {
                    Console.WriteLine("\nCongratulations! You opened all 35 mine-free cells.");
                    ShowPlayfield(mines);
                    Console.WriteLine("Enter your nickname: ");
                    string nickname = Console.ReadLine();
                    Player player = new Player(nickname, pointsCount);
                    players.Add(player);
                    ShowHighscores(players);
                    playfield = CreatePlayfiled();
                    mines = PlaceMines();
                    pointsCount = 0;
                    gameWon = false;
                    gameStarted = true;
                }
            }
            while (command != "exit");
            Console.WriteLine("Thank you for playing \"Minesweeper\"");
            Console.Read();
        }
Exemple #20
0
        public static void Main()
        {
            string command = string.Empty;
            char[,] field = CreatePlayingField();
            char[,] mines = CreateMines();
            int counter = 0;
            bool isMineHit = false;
            List<Player> leaderboard = new List<Player>(6);
            int row = 0;
            int column = 0;
            bool isToStart = true;
            const int CellsToOpen = 35;
            bool gameFinished = false;

            do
            {
                if (isToStart)
                {
                    Console.WriteLine("Let's play Minesweeper. Try your luck and skill." +
                    " Command 'top' shows the ranking, 'restart' starts a new game, 'exit' is for quitting!");
                    UpdateField(field);
                    isToStart = 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 column) &&
                        row <= field.GetLength(0) && column <= field.GetLength(1))
                    {
                        command = "turn";
                    }
                }

                switch (command)
                {
                    case "top":
                        {
                            GetLeaderboard(leaderboard);
                            break;
                        }

                    case "restart":
                        {
                            field = CreatePlayingField();
                            mines = CreateMines();
                            UpdateField(field);
                            isMineHit = false;
                            isToStart = false;
                            break;
                        }

                    case "exit":
                        {
                            Console.WriteLine("Bye Bye!");
                            break;
                        }

                    case "turn":
                        {
                            if (mines[row, column] != '*')
                            {
                                if (mines[row, column] == '-')
                                {
                                    MakeTurn(field, mines, row, column);
                                    counter++;
                                }

                                if (CellsToOpen == counter)
                                {
                                    gameFinished = true;
                                }
                                else
                                {
                                    UpdateField(field);
                                }
                            }
                            else
                            {
                                isMineHit = true;
                            }

                            break;
                        }

                    default:
                        {
                            Console.WriteLine("Error! Invalid command.");
                            break;
                        }
                }

                if (isMineHit)
                {
                    UpdateField(mines);
                    Console.Write("You died with {0} Poins. " + "Enter nickname: ", counter);
                    string nickname = Console.ReadLine();
                    Player t = new Player(nickname, counter);

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

                    leaderboard.Sort((Player first, Player second) => second.Name.CompareTo(first.Name));
                    leaderboard.Sort((Player first, Player second) => second.Points.CompareTo(first.Points));
                    GetLeaderboard(leaderboard);

                    field = CreatePlayingField();
                    mines = CreateMines();
                    counter = 0;
                    isMineHit = false;
                    isToStart = true;
                }

                if (gameFinished)
                {
                    Console.WriteLine("Congratulations! You win.");
                    UpdateField(mines);
                    Console.WriteLine("Enter your name: ");
                    string nameOfWinner = Console.ReadLine();
                    Player winner = new Player(nameOfWinner, counter);
                    leaderboard.Add(winner);
                    GetLeaderboard(leaderboard);
                    field = CreatePlayingField();
                    mines = CreateMines();
                    counter = 0;
                    gameFinished = false;
                    isToStart = true;
                }
            }
            while (command != "exit");

            Console.WriteLine("Produced in Bulgaria.");
            Console.WriteLine("Hope you enjoyed it.");
            Console.Read();
        }
Exemple #21
0
        internal static void Play()
        {
            string command = string.Empty;
            int currentRow = 0;
            int currentColumn = 0;
            int openedCellsCount = 0;

            char[,] gameBoard = CreateGameBoard('?');
            char[,] gameBoardWithMines = PlaceMines();

            bool gameStarts = true;
            bool playerWon = false;
            bool steppedOnMine = false;

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

            do
            {
                if (gameStarts)
                {
                    Console.WriteLine(IntroMessage);
                    Console.WriteLine(CommandsExplanation);
                    PrintBoard(gameBoard);
                    gameStarts = false;
                }

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

                if (command.Length >= 3)
                {
                    if (int.TryParse(command[0].ToString(), out currentRow) &&
                        int.TryParse(command[2].ToString(), out currentColumn) &&
                        currentRow <= Rows && currentColumn <= Columns)
                    {
                        command = "turn";
                    }
                }

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

                    case "restart":
                        gameBoard = CreateGameBoard('?');
                        gameBoardWithMines = PlaceMines();
                        PrintBoard(gameBoard);
                        steppedOnMine = false;
                        gameStarts = false;
                        break;

                    case "exit":
                        Console.WriteLine(ExitMessage);
                        break;

                    case "turn":
                        if (gameBoardWithMines[currentRow, currentColumn] != '*')
                        {
                            if (gameBoardWithMines[currentRow, currentColumn] == '-')
                            {
                                UpdateBoards(gameBoard, gameBoardWithMines, currentRow, currentColumn);
                                openedCellsCount++;
                            }

                            if (MaxCellsToBeOpened == openedCellsCount)
                            {
                                playerWon = true;
                            }
                            else
                            {
                                PrintBoard(gameBoard);
                            }
                        }
                        else
                        {
                            steppedOnMine = true;
                        }

                        break;

                    default:
                        Console.WriteLine("\nError! Command not valid.\n");
                        break;
                }

                if (steppedOnMine)
                {
                    PrintBoard(gameBoardWithMines);

                    Console.Write(PlayerLostMessage + AskPlayerForName, openedCellsCount);
                    string name = Console.ReadLine();
                    Player looser = new Player(name, openedCellsCount);

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

                    champions.Sort((Player a, Player b) => b.Name.CompareTo(a.Name));
                    champions.Sort((Player a, Player b) => b.Points.CompareTo(a.Points));
                    PrintRanking(champions);

                    gameBoard = CreateGameBoard('?');
                    gameBoardWithMines = PlaceMines();
                    openedCellsCount = 0;
                    steppedOnMine = false;
                    gameStarts = true;
                }

                if (playerWon)
                {
                    Console.WriteLine(PlayerWonMessage);
                    PrintBoard(gameBoardWithMines);

                    Console.WriteLine(AskPlayerForName);
                    string name = Console.ReadLine();
                    Player winner = new Player(name, openedCellsCount);
                    champions.Add(winner);
                    PrintRanking(champions);

                    gameBoard = CreateGameBoard('?');
                    gameBoardWithMines = PlaceMines();
                    openedCellsCount = 0;
                    playerWon = false;
                    gameStarts = true;
                }
            }
            while (command != "exit");

            Console.WriteLine(ExitMessage);
            Console.Read();
        }
Exemple #22
0
 private static void AttemptMineTriggeredAction(ref bool mineTriggered, List<Player> topPlayers,
     ref char[,] mines, ref int count, ref char[,] field, ref bool isNewGame)
 {
     if (mineTriggered)
     {
         PrintFieldState(mines);
         Console.WriteLine();
         Console.Write(DeathMessage, count);
         string nickname = Console.ReadLine();
         Player player = new Player(nickname, count);
         int topPlayersCount = topPlayers.Count;
         if (topPlayersCount < 5)
         {
             topPlayers.Add(player);
         }
         else
         {
             for (int i = 0; i < topPlayersCount; i++)
             {
                 if (topPlayers[i].Points < count)
                 {
                     topPlayers.Insert(i, player);
                     topPlayers.RemoveAt(topPlayersCount - 1);
                     break;
                 }
             }
         }
         topPlayers.Sort((firstPlayer, secondPlayer) => String.Compare(
             secondPlayer.Name, firstPlayer.Name, StringComparison.Ordinal));
         topPlayers.Sort((firstPlayer, secondPlayer) => secondPlayer.Points.CompareTo(firstPlayer.Points));
         PrintScoreboard(topPlayers);
         field = CreateField();
         mines = ArmMines();
         count = 0;
         mineTriggered = false;
         isNewGame = true;
     }
 }
        internal static void Run()
        {
            string currentCommand = string.Empty;
            char[,] fields = CreateGameFields();
            char[,] mines = AddMines();
            int scoreCounter = 0;
            bool gameOver = false;
            List<Player> topPlayersScore = new List<Player>(MAX_NUMBER_OF_PLAYERS_IN_TOP_SCORE_LIST);
            int row = 0;
            int col = 0;
            bool showGameMenu = true;
            bool gameWon = false;

            do
            {
                if (showGameMenu)
                {
                    Console.WriteLine(">>> Mine Sweeper - Console Edition <<<\nTry uncovering all fields without stepping on a mine.\n" +
                    "Commands:\n'top' -       displays the Highscore\n\r'restart' -   initiates a new game\n\r'exit' -      terminates the game.");
                    PrintGameField(fields);
                    showGameMenu = false;
                }

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

                switch (currentCommand)
                {
                    case "top":
                        PrintScore(topPlayersScore);
                        break;
                    case "restart":
                        fields = CreateGameFields();
                        mines = AddMines();
                        PrintGameField(fields);
                        gameOver = false;
                        showGameMenu = false;
                        break;
                    case "exit":
                        Console.WriteLine("Good Bye!");
                        break;
                    case "turn":
                        if (mines[row, col] != MINE_SYMBOL)
                        {
                            if (mines[row, col] == WITHOUT_MINE_FIELD_SYMBOL)
                            {
                                GetPlayerMove(fields, mines, row, col);
                                scoreCounter++;
                            }

                            if (MAX_SCORE == scoreCounter)
                            {
                                gameWon = true;
                            }
                            else
                            {
                                PrintGameField(fields);
                            }
                        }
                        else
                        {
                            gameOver = true;
                        }

                        break;
                    default:
                        Console.WriteLine("\nInvalidcommand!\n");
                        break;
                }

                if (gameOver)
                {
                    PrintGameField(mines);
                    Console.Write(
                        "GAME OVER!\nYour Score: {0} points. \nPlease Enter Your Name: ", scoreCounter);
                    string name = Console.ReadLine();
                    Player currentPlayer = new Player(name, scoreCounter);
                    if (topPlayersScore.Count < MAX_NUMBER_OF_PLAYERS_IN_TOP_SCORE_LIST-1)
                    {
                        topPlayersScore.Add(currentPlayer);
                    }
                    else
                    {
                        for (int i = 0; i < topPlayersScore.Count; i++)
                        {
                            if (topPlayersScore[i].Points < currentPlayer.Points)
                            {
                                topPlayersScore.Insert(i, currentPlayer);
                                topPlayersScore.RemoveAt(topPlayersScore.Count - 1);
                                break;
                            }
                        }
                    }

                    topPlayersScore.Sort((Player x, Player y) => y.Name.CompareTo(x.Name));
                    topPlayersScore.Sort((Player x, Player y) => y.Points.CompareTo(x.Points));
                    PrintScore(topPlayersScore);
                    fields = CreateGameFields();
                    mines = AddMines();
                    scoreCounter = 0;
                    gameOver = false;
                    showGameMenu = true;
                }

                if (gameWon)
                {
                    Console.WriteLine("\nCONGRATULATIONS! YOU WON!");
                    PrintGameField(mines);
                    Console.WriteLine("\nPlease, Enter your name: ");
                    string name = Console.ReadLine();
                    Player currentPlayer = new Player(name, scoreCounter);
                    topPlayersScore.Add(currentPlayer);
                    PrintScore(topPlayersScore);
                    fields = CreateGameFields();
                    mines = AddMines();
                    scoreCounter = 0;
                    gameWon = false;
                    showGameMenu = true;
                }
            }
            while (currentCommand != "Exit");
            Console.WriteLine("Made in Bulgaria");
            Console.WriteLine("GOOD BYE");
            Console.Read();
        }
Exemple #24
0
        private static void Main()
        {
            string command = string.Empty;
            char[,] board = CreateBoard();
            char[,] bombs = PlaceBombs();
            int score = 0;
            bool exploded = false;
            List<Player> topScorers = new List<Player>(6);
            int row = 0;
            int column = 0;
            bool firstMove = true;
            const int Max = 35;
            bool gameWon = false;

            do
            {
                if (firstMove)
                {
                    Console.WriteLine("Let's play \"Game\". Try to find the cells without bombs in them."
                        + " Command 'top' shows the scoreboard, 'restart' starts a new game, 'exit' ends the game!");
                    DrawBoard(board);
                    firstMove = 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 column)
                        && row <= board.GetLength(0) && column <= board.GetLength(1))
                    {
                        command = "turn";
                    }
                }

                switch (command)
                {
                    case "top":
                        PrintScore(topScorers);
                        break;
                    case "restart":
                        board = CreateBoard();
                        bombs = PlaceBombs();
                        DrawBoard(board);
                        break;
                    case "exit":
                        Console.WriteLine("Goodbye!");
                        break;
                    case "turn":
                        if (bombs[row, column] != '*')
                        {
                            if (bombs[row, column] == '-')
                            {
                                Move(board, bombs, row, column);
                                score++;
                            }

                            if (Max == score)
                            {
                                gameWon = true;
                            }
                            else
                            {
                                DrawBoard(board);
                            }
                        }
                        else
                        {
                            exploded = true;
                        }

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

                if (exploded)
                {
                    DrawBoard(bombs);

                    Console.Write("\nOuch! You died heroically with {0} points. Enter your nickname: ", score);

                    string nickname = Console.ReadLine();
                    Player t = new Player(nickname, score);

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

                    topScorers.Sort((r1, r2) => r2.Name.CompareTo(r1.Name));
                    topScorers.Sort((r1, r2) => r2.Points.CompareTo(r1.Points));
                    PrintScore(topScorers);

                    board = CreateBoard();
                    bombs = PlaceBombs();
                    score = 0;
                    exploded = false;
                    firstMove = true;
                }

                if (gameWon)
                {
                    Console.WriteLine("\nCongratulations! You opened 35 cells without getting hurt!");
                    DrawBoard(bombs);
                    Console.WriteLine("Please enter your name: ");
                    string name = Console.ReadLine();
                    Player points = new Player(name, score);
                    topScorers.Add(points);
                    PrintScore(topScorers);
                    board = CreateBoard();
                    bombs = PlaceBombs();
                    score = 0;
                    gameWon = false;
                    firstMove = true;
                }
            } 
            while (command != "exit");

            Console.WriteLine("Made in Bulgaria!");
            Console.Read();
        }
Exemple #25
0
        private static void StepOnBomb(List<Player> hallOfFame, int counter)
        {
            Console.Write("\nYou stepped on a bomb and died with {0} points.\n" + "Enter your name: ", counter);
            string name = Console.ReadLine();
            Player player = new Player(name, counter);

            if (hallOfFame.Count < 5)
            {
                hallOfFame.Add(player);
            }

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

            hallOfFame.Sort((player1, player2) => string.Compare(player2.Name, player1.Name, StringComparison.Ordinal));
            hallOfFame.Sort((player1, player2) => player2.Points.CompareTo(player1.Points));
            HallOfFame(hallOfFame);
        }
        public static void Main(string[] args)
        {
            string command = string.Empty;
            char[,] field = CreateInitialBoard();
            char[,] bombs = BombPlacer();
            int counter = 0;
            bool isMine = false;
            List<Player> champions = new List<Player>(6);
            int row = 0;
            int col = 0;
            bool isBegining = true;
            const int MAX = 35;
            bool allMinesAvoided = false;

            do
            {
                if (isBegining)
                {
                    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!");
                    DrawBoard(field);
                    isBegining = 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":
                        Ranking(champions);
                        break;
                    case "restart":
                        field = CreateInitialBoard();
                        bombs = BombPlacer();
                        DrawBoard(field);
                        isMine = false;
                        isBegining = false;
                        break;
                    case "exit":
                        Console.WriteLine("4a0, 4a0, 4a0!");
                        break;
                    case "turn":
                        if (bombs[row, col] != '*')
                        {
                            if (bombs[row, col] == '-')
                            {
                                CalculationsBeforeMove(field, bombs, row, col);
                                counter++;
                            }

                            if (MAX == counter)
                            {
                                allMinesAvoided = true;
                            }
                            else
                            {
                                DrawBoard(field);
                            }
                        }
                        else
                        {
                            isMine = true;
                        }

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

                if (isMine)
                {
                    DrawBoard(bombs);
                    Console.Write("\nHrrrrrr! Umria gerojski s {0} to4ki. " + "Daj si niknejm: ", counter);
                    string nickname = Console.ReadLine();
                    Player currentPlayer = new Player(nickname, counter);
                    if (champions.Count < 5)
                    {
                        champions.Add(currentPlayer);
                    }
                    else
                    {
                        for (int i = 0; i < champions.Count; i++)
                        {
                            if (champions[i].PointsCount < currentPlayer.PointsCount)
                            {
                                champions.Insert(i, currentPlayer);
                                champions.RemoveAt(champions.Count - 1);
                                break;
                            }
                        }
                    }

                    champions.Sort((Player r1, Player r2) => r2.Name.CompareTo(r1.Name));
                    champions.Sort((Player r1, Player r2) => r2.PointsCount.CompareTo(r1.PointsCount));
                    Ranking(champions);

                    field = CreateInitialBoard();
                    bombs = BombPlacer();
                    counter = 0;
                    isMine = false;
                    isBegining = true;
                }

                if (allMinesAvoided)
                {
                    Console.WriteLine("\nBRAVOOOS! Otvri 35 kletki bez kapka kryv.");
                    DrawBoard(bombs);
                    Console.WriteLine("Daj si imeto, batka: ");
                    string name = Console.ReadLine();
                    Player currentPlayer = new Player(name, counter);
                    champions.Add(currentPlayer);
                    Ranking(champions);
                    field = CreateInitialBoard();
                    bombs = BombPlacer();
                    counter = 0;
                    allMinesAvoided = false;
                    isBegining = true;
                }
            }
            while (command != "exit");
            Console.WriteLine("Made in Bulgaria - Uauahahahahaha!");
            Console.WriteLine("AREEEEEEeeeeeee.");
            Console.Read();
        }
Exemple #27
0
        public static void Run(bool gameStart, char[,] board, int row, int col, List<Player> hallOfFame,
            char[,] bombs, bool foundBomb, int counter, int counterMax, bool gameEnd)
        {
            string command = String.Empty;

            do
            {
                if (gameStart)
                {
                    Console.Clear();
                    Console.WriteLine(
                        "Lets play \"Minesweeper\"! The goal is to find all squares without mines." +
                        " The commands are - \"top\" to see Hall of Fame, \"restart\" starts new game and \"exit\" quits the game!");
                    BoardDraw(board);
                    gameStart = false;
                }

                Console.Write("Enter row and column : ");
                command = Console.ReadLine().Trim();

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

                switch (command)
                {
                    case "top":
                        HallOfFame(hallOfFame);
                        break;
                    case "restart":
                        Restart(out board, out gameStart, out bombs, out foundBomb, out counter);
                        break;
                    case "exit":
                        Console.WriteLine("Bye !");
                        break;
                    case "turn":
                        if (bombs[row, col] != '*')
                        {
                            if (bombs[row, col] == '-')
                            {
                                PlayerTurn(board, bombs, row, col);
                                counter++;
                            }

                            if (counterMax == counter)
                            {
                                gameEnd = true;
                            }

                            else
                            {
                                BoardDraw(board);
                            }
                        }

                        else
                        {
                            foundBomb = true;
                        }
                        break;
                    default:
                        Console.WriteLine("\nUnknow command\n");
                        break;
                }

                if (foundBomb)
                {
                    BoardDraw(bombs);
                    StepOnBomb(hallOfFame, counter);
                    Restart(out board, out gameStart, out bombs, out foundBomb, out counter);
                }

                if (gameEnd)
                {
                    Console.WriteLine("\nCongratulations ! You found all the bombs !");
                    BoardDraw(bombs);
                    Console.WriteLine("Enter your name: ");
                    string name = Console.ReadLine();
                    Player points = new Player(name, counter);
                    hallOfFame.Add(points);
                    HallOfFame(hallOfFame);
                    Restart(out board, out gameStart, out bombs, out foundBomb, out counter);
                }
            } while (command != "exit");

            Console.WriteLine("Made by SoftUni !");
            Console.WriteLine("Thanks for the awful code guys.");
            Console.Read();
        }
        static void Main()
        {
            // Initialize the variables which rule the game
            string command = string.Empty;
            char[,] gamefield = MinesweeperEngine.CreateGamefield();
            char[,] bombs = MinesweeperEngine.GenerateBombs();
            List<Player> champions = new List<Player>(CHAMPIONS_LIST_SIZE);
            int row = 0;
            int column = 0;
            int moveCounter = 0;
            bool isBomb = false;
            bool isNewGame = true;
            bool isEndGame = false;

            // Run the game
            do
            {
                if (isNewGame)
                {
                    Console.WriteLine(
                        "Lets play Minesweeper. Try your luck. Find fields without bombs." +
                        "To show the results enter - \"top\", to start new game enter - \"restart\"," +
                        "to make move enter row and column separated by space, to exit enter - \"exit\"");
                    MinesweeperEngine.PrintGamefield(gamefield);
                    isNewGame = false;
                }

                command = ReadCommand(command, gamefield, ref row, ref column);

                switch (command)
                {
                    case "top":
                        MinesweeperEngine.PrintResults(champions);
                        break;
                    case "restart":
                        gamefield = MinesweeperEngine.CreateGamefield();
                        bombs = MinesweeperEngine.GenerateBombs();
                        MinesweeperEngine.PrintGamefield(gamefield);
                        isBomb = false;
                        isNewGame = false;
                        break;
                    case "exit":
                        Console.WriteLine("Bye, Bye, Bye!");
                        break;
                    case "turn":
                        if (bombs[row, column] != BOMB_SYMBOL)
                        {
                            MinesweeperEngine.Move(gamefield, bombs, row, column);
                            moveCounter++;
                            if (NOT_BOMBS_NUMBER == moveCounter)
                            {
                                isEndGame = true;
                            }
                            else
                            {
                                MinesweeperEngine.PrintGamefield(gamefield);
                            }
                        }
                        else
                        {
                            isBomb = true;
                        }
                        break;
                    default:
                        Console.WriteLine(Environment.NewLine +
                            "Invalid input! You should enter valid command - top, restart, valid row and column or exit" +
                            Environment.NewLine);
                        break;
                }

                // End current game and start new one if there is a bomb
                if (isBomb)
                {
                    MinesweeperEngine.PrintGamefield(bombs);
                    Console.Write(Environment.NewLine +
                        "Game over! Your scores are {0}. Enter username: "******"Congratulations! You win this game.");
                    MinesweeperEngine.PrintGamefield(bombs);
                    Console.WriteLine("Enter username: "******"exit");

            Console.WriteLine("Made in Bulgaria");
            Console.WriteLine("Press any key to exit the program.");
            Console.Read();
        }
        private static void Main(string[] mainArgs)
        {
            string command = string.Empty;
            char[,] field = GenerateField();
            char[,] bombs = GenerateBombs();
            int counter = 0;
            bool gameOver = false;
            List<Player> players = new List<Player>(6);
            int row = 0;
            int col = 0;
            bool justStarted = true;
            const int max = 35;
            bool hasWon = false;

            do
            {
                if (justStarted)
                {
                    Console.WriteLine("Let's play “Minesweeper”. Try your luck to find the cells without bombs. "
                        + "The command 'top' shows the Score ratings, 'reset' starts a new game, 'exit' closes the game.");
                    PrintFrames(field);
                    justStarted = false;
                }

                Console.Write("Please 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 <= field.GetLength(0) && col <= field.GetLength(1))
                    {
                        command = "turn";
                    }
                }

                switch (command)
                {
                    case "top":
                        Rating(players);
                        break;
                    case "reset":
                        field = GenerateField();
                        bombs = GenerateBombs();
                        PrintFrames(field);
                        gameOver = false;
                        justStarted = false;
                        break;
                    case "exit":
                        Console.WriteLine("Bye, bye!");
                        break;
                    case "turn":
                        if (bombs[row, col] != '*')
                        {
                            if (bombs[row, col] == '-')
                            {
                                MakeTurn(field, bombs, row, col);
                                counter++;
                            }

                            if (max == counter)
                            {
                                hasWon = true;
                            }
                            else
                            {
                                PrintFrames(field);
                            }
                        }
                        else
                        {
                            gameOver = true;
                        }

                        break;
                    default:
                        Console.WriteLine("{0}Invalid command!{0}", Environment.NewLine);
                        break;
                }

                if (gameOver)
                {
                    PrintFrames(bombs);
                    Console.Write("\nHrrrrrr! You died heroically with {0} points. " + "Please enter your name: ", counter);
                    string name = Console.ReadLine();
                    Player player = new Player(name, counter);
                    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 r1, Player r2) => r2.Name.CompareTo(r1.Name));
                    players.Sort((Player r1, Player r2) => r2.Points.CompareTo(r1.Points));
                    Rating(players);

                    field = GenerateField();
                    bombs = GenerateBombs();
                    counter = 0;
                    gameOver = false;
                    justStarted = true;
                }

                if (hasWon)
                {
                    Console.WriteLine("\nGreatings! You have selected 35 cells without loosing any health point.");
                    PrintFrames(bombs);
                    Console.WriteLine("Please enter your name: ");
                    string name = Console.ReadLine();
                    Player player = new Player(name, counter);
                    players.Add(player);
                    Rating(players);
                    field = GenerateField();
                    bombs = GenerateBombs();
                    counter = 0;
                    hasWon = false;
                    justStarted = true;
                }
            }
            while (command != "exit");
            Console.WriteLine("Made in Bulgaria - Greatings to you!");
            Console.Read();
        }
Exemple #30
0
        public static void Start()
        {
            const int MaxScore = 35;

            string userInput = string.Empty;
            char[,] userInterfaceBoard = Board.Generate();
            char[,] boardWithBombs = Board.GenerateWithMines();
            int scores = 0;
            bool gameOver = false;
            List<Player> topPlayersColection = new List<Player>(6);
            int row = 0;
            int col = 0;
            bool newGame = true;
            bool gameWined = false;

            do
            {
                if (newGame)
                {
                    Console.WriteLine("Let's play “Mines”. Try to find cells without mines." +
                    " Command 'top' shows top players, 'restart' start new game, 'exit' for exit the game!");
                    Board.Print(userInterfaceBoard);
                    newGame = false;
                }

                Console.Write("Plaese enter row and column : ");

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

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

                switch (userInput)
                {
                    case "top":
                        Player.PrintColection(topPlayersColection);
                        break;
                    case "restart":
                        userInterfaceBoard = Board.Generate();
                        boardWithBombs = Board.GenerateWithMines();
                        Board.Print(userInterfaceBoard);
                        gameOver = false;
                        newGame = false;
                        break;
                    case "exit":
                        Console.WriteLine("Bay bay!");
                        break;
                    case "turn":
                        if (boardWithBombs[row, col] != '*')
                        {
                            Board.AddResultToCellInBoards(userInterfaceBoard, boardWithBombs, row, col);
                            scores++;

                            if (MaxScore == scores)
                            {
                                gameWined = true;
                            }
                            else
                            {
                                Board.Print(userInterfaceBoard);
                            }
                        }
                        else
                        {
                            gameOver = true;
                        }

                        break;
                    default:
                        Console.WriteLine("\nInvalid input!\n");
                        break;
                }

                if (gameOver)
                {
                    Board.Print(boardWithBombs);
                    Console.Write("Game Over! Your result is: {0} scores. \nPlase enter your name: ", scores);
                    string userName = Console.ReadLine();
                    Player currentPlayer = new Player(userName, scores);

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

                    topPlayersColection.Sort((p1, p2) => p2.Name.CompareTo(p1.Name));
                    topPlayersColection.Sort((p1, p2) => p2.Score.CompareTo(p1.Score));
                    Player.PrintColection(topPlayersColection);

                    userInterfaceBoard = Board.Generate();
                    boardWithBombs = Board.GenerateWithMines();
                    scores = 0;
                    gameOver = false;
                    newGame = true;
                }

                if (gameWined)
                {
                    Console.WriteLine("\nYou win! You open {0} cels.", MaxScore);
                    Board.Print(boardWithBombs);
                    Console.WriteLine("Please enter your name: ");
                    string userName = Console.ReadLine();
                    Player currentPlayer = new Player(userName, scores);
                    topPlayersColection.Add(currentPlayer);
                    Player.PrintColection(topPlayersColection);

                    userInterfaceBoard = Board.Generate();
                    boardWithBombs = Board.GenerateWithMines();
                    scores = 0;
                    gameWined = false;
                    newGame = true;
                }
            }
            while (userInput != "exit");

            Console.WriteLine("Made in Bulgaria");
            Console.Read();
        }
        private static void Menu()
        {
            InitializeTopPlayers();
            string str = "restart";
            int choosenRow = 0;
            int chosenColumn = 0;

            while (str != "exit")
            {


                if (str == "restart")
                {
                    InitializeGameBoard();
                    Console.WriteLine("Welcome to the game “Minesweeper”. " +
                        "Try to reveal all cells without mines. " +
                        "Use 'top' to view the scoreboard, 'restart' to start a new game" +
                        "and 'exit' to quit the game.");
                    board.PrintGameBoard();
                }
                else if (str == "exit")
                {
                    Console.WriteLine("Good bye!");
                    Console.Read();
                }
                else if (str == "top")
                {
                    top();
                }
                else if (str == "coordinates")
                {


                    try
                    {
                        Board.Status status = board.OpenField(choosenRow, chosenColumn);
                        if (status == Board.Status.SteppedOnAMine)
                        {
                            board.PrintAllFields();
                            int score = board.CountOpenedFields();
                            Console.WriteLine("Booooom! You were killed by a mine. You revealed " +
                                score +
                                " cells without mines.");

                            if (CheckHighScores(score))
                            {
                                Console.WriteLine("Please enter your name for the top scoreboard: ");
                                string name = Console.ReadLine();
                                Player player = new Player(name, score);
                                topadd(ref player);
                                top();
                            }
                            str = "restart";
                            continue;
                        }


                        else if (status == Board.Status.AlreadyOpened)
                        {
                            Console.WriteLine("Illegal move!");
                        }
                        else if (status == Board.Status.AllFieldsAreOpened)
                        {
                            board.PrintAllFields();
                            int score = board.CountOpenedFields();
                            Console.WriteLine("Congratulations! You win!!");
                            if (CheckHighScores(score))
                            {
                                Console.WriteLine("Please enter your name for the top scoreboard: ");
                                string name = Console.ReadLine();
                                Player player = new Player(name, score);
                                topadd(ref player);
                                // pokazvame klasiraneto
								top();
                            }
                            str = "restart";
                            continue;
                        }
                        else
                        {


                            board.PrintGameBoard();
                        }
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("Illegal move");
                    }
                }

                Console.Write(System.Environment.NewLine + "Enter row and column: ");

                str = Console.ReadLine();
                try
                {
                    choosenRow = int.Parse(str);
                    str = "coordinates";
                }
                catch
                {

					// niama smisal tuka
                    continue;
                }

                str = Console.ReadLine();
                try
                {
                    chosenColumn = int.Parse(str);
                    str = "coordinates";
                }
                catch (Exception)
                {
                    continue;
                }
            }
        }