Esempio n. 1
0
        static void Main(string[] arguments)
        {
            string command = string.Empty;
            char[,] field = CreateGameField();
            char[,] bombs = LocateBombs();
            int counter = 0;
            bool explode = false;
            List<Points> champions = new List<Points>(6);
            int row = 0;
            int col = 0;
            bool flag = true;
            const int max = 35;
            bool notFlag = false;

            do
            {
                if (flag)
                {
                    Console.WriteLine("Let's play MineSweeper. Try to find the fields without mines." +
                    "Command 'top' shows the results, 'restart' starts new game, 'exit' finishes the game!");
                    PrintBoard(field);
                    flag = 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":
                        Results(champions);
                        break;
                    case "restart":
                        field = CreateGameField();
                        bombs = LocateBombs();
                        PrintBoard(field);
                        explode = false;
                        flag = false;
                        break;
                    case "exit":
                        Console.WriteLine("Bye-bye!");
                        break;
                    case "turn":
                        if (bombs[row, col] != '*')
                        {
                            if (bombs[row, col] == '-')
                            {
                                Move(field, bombs, row, col);
                                counter++;
                            }
                            if (max == counter)
                            {
                                notFlag = true;
                            }
                            else
                            {
                                PrintBoard(field);
                            }
                        }
                        else
                        {
                            explode = true;
                        }
                        break;
                    default:
                        Console.WriteLine("\nError! Invalid command!\n");
                        break;
                }
                if (explode)
                {
                    PrintBoard(bombs);
                    Console.Write("\nHrrrrrr! Lost game with {0} points. " +
                        "Enter your nickname: ", counter);
                    string nickname = Console.ReadLine();
                    Points points = new Points(nickname, counter);
                    if (champions.Count < 5)
                    {
                        champions.Add(points);
                    }
                    else
                    {
                        for (int i = 0; i < champions.Count; i++)
                        {
                            if (champions[i].Points < points.Points)
                            {
                                champions.Insert(i, points);
                                champions.RemoveAt(champions.Count - 1);
                                break;
                            }
                        }
                    }
                    champions.Sort((Points player1Points, Points player2Points) => player2Points.Name.CompareTo(player1Points.Name));
                    champions.Sort((Points player1Points, Points player2Points) => player2Points.Points.CompareTo(player1Points.Points));
                    Results(champions);

                    field = CreateGameField();
                    bombs = LocateBombs();
                    counter = 0;
                    explode = false;
                    flag = true;
                }
                if (notFlag)
                {
                    Console.WriteLine("\nWell done! You have opened 35 cells without mines.");
                    PrintBoard(bombs);
                    Console.WriteLine("Enter name: ");
                    string name = Console.ReadLine();
                    Points points = new Points(name, counter);
                    champions.Add(points);
                    Results(champions);
                    field = CreateGameField();
                    bombs = LocateBombs();
                    counter = 0;
                    notFlag = false;
                    flag = true;
                }
            }
            while (command != "exit");
            Console.WriteLine("Made in Bulgaria!");
            Console.WriteLine("URAAAAAAAA.");
            Console.Read();
        }
Esempio n. 2
0
        internal static void Start()
        {
            const int FieldsWithNoMines = 35;
            string command = string.Empty;
            char[,] board = CreateBoard();
            char[,] mines = PlaceMines();
            int pointsCounter = 0;
            int row = 0;
            int col = 0;
            bool gameOver = false;
            bool inGame = true;
            bool gameWon = false;
            List<Points> highScores = new List<Points>(6);

            do
            {
                if (inGame)
                {
                    Console.WriteLine("Lets play MineSweeper. Try to find all the fields with no mines placed. " +
                    "Command 'top' shows highscores, 'restart' starts a new game, 'exit' quits the game!");
                    PrintBoard(board);
                    inGame = 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 <= board.GetLength(0) && col <= board.GetLength(1))
                    {
                        command = "turn";
                    }
                }

                switch (command)
                {
                    case "top":
                        PrintHighScores(highScores);
                        break;
                    case "restart":
                        board = CreateBoard();
                        mines = PlaceMines();
                        PrintBoard(board);
                        gameOver = false;
                        inGame = false;
                        break;
                    case "exit":
                        Console.WriteLine("Bye, Bye!");
                        break;
                    case "turn":
                        if (mines[row, col] != '*')
                        {
                            if (mines[row, col] == '-')
                            {
                                PlayerTurn(board, mines, row, col);
                                pointsCounter++;
                            }

                            if (FieldsWithNoMines == pointsCounter)
                            {
                                gameWon = true;
                            }
                            else
                            {
                                PrintBoard(board);
                            }
                        }
                        else
                        {
                            gameOver = true;
                        }

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

                if (gameOver)
                {
                    PrintBoard(mines);
                    Console.Write("Boom! You fought like a hero and got {0} points. " + "Enter your nickname: ", pointsCounter);
                    string nickname = Console.ReadLine();
                    Points result = new Points(nickname, pointsCounter);

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

                    highScores.Sort((Points result1, Points result2) => result2.PlayerName.CompareTo(result1.PlayerName));
                    highScores.Sort((Points result1, Points result2) => result2.PlayerPoints.CompareTo(result1.PlayerPoints));
                    PrintHighScores(highScores);

                    board = CreateBoard();
                    mines = PlaceMines();
                    pointsCounter = 0;
                    gameOver = false;
                    inGame = true;
                }

                if (gameWon)
                {
                    Console.WriteLine("\nCongratulations!You opened all the 35 fields with no mines!");
                    PrintBoard(mines);
                    Console.WriteLine("Enter your name: ");
                    string name = Console.ReadLine();
                    Points points = new Points(name, pointsCounter);
                    highScores.Add(points);
                    PrintHighScores(highScores);
                    board = CreateBoard();
                    mines = PlaceMines();
                    pointsCounter = 0;
                    gameWon = false;
                    inGame = true;
                }
            }
            while (command != "exit");

            Console.WriteLine("Made in Bulgaria !");
            Console.Read();
        }
        static void Main(string[] args)
        {
            const int maxSafeCells = 35;
            string command = string.Empty;
            char[,] field = CreateGameField();
            char[,] bombs = PlaceBombs();
            int openedSafeCells = 0;
            bool steppedOnMine = false;
            List<Points> champions = new List<Points>(6);
            int row = 0;
            int column = 0;
            bool introActivated = true;
            bool outroActivated = false;

            do
            {
                if (introActivated)
                {
                    Console.WriteLine("Hajde da igraem na “Mini4KI”. Probvaj si kasmeta da otkriesh poleteta bez mini4ki." +
                    " Komanda 'top' pokazva klasiraneto, 'restart' po4va nova igra, 'exit' izliza i hajde 4ao!");
                    DrawField(field);
                    introActivated = false;
                }
                Console.Write("Daj red i kolona : ");
                command = Console.ReadLine().Trim();
                if (command.Length >= 3)
                {
                    if (int.TryParse(command[0].ToString(), out row) &&
                    int.TryParse(command[2].ToString(), out column) &&
                        row <= field.GetLength(0) && column <= field.GetLength(1))
                    {
                        command = "turn";
                    }
                }
                switch (command)
                {
                    case "top":
                        PrintLeaderboard(champions);
                        break;
                    case "restart":
                        field = CreateGameField();
                        bombs = PlaceBombs();
                        DrawField(field);
                        steppedOnMine = false;
                        introActivated = false;
                        break;
                    case "exit":
                        Console.WriteLine("4a0, 4a0, 4a0!");
                        break;
                    case "turn":
                        if (bombs[row, column] != '*')
                        {
                            if (bombs[row, column] == '-')
                            {
                                MakeAMove(field, bombs, row, column);
                                openedSafeCells++;
                            }
                            if (maxSafeCells == openedSafeCells)
                            {
                                outroActivated = true;
                            }
                            else
                            {
                                DrawField(field);
                            }
                        }
                        else
                        {
                            steppedOnMine = true;
                        }
                        break;
                    default:
                        Console.WriteLine("\nGreshka! nevalidna Komanda\n");
                        break;
                }
                if (steppedOnMine)
                {
                    DrawField(bombs);
                    Console.Write("\nHrrrrrr! Umria gerojski s {0} to4ki. " +
                        "Daj si niknejm: ", openedSafeCells);
                    string name = Console.ReadLine();
                    Points score = new Points(name, openedSafeCells);
                    if (champions.Count < 5)
                    {
                        champions.Add(score);
                    }
                    else
                    {
                        for (int i = 0; i < champions.Count; i++)
                        {
                            if (champions[i].Score < score.Score)
                            {
                                champions.Insert(i, score);
                                champions.RemoveAt(champions.Count - 1);
                                break;
                            }
                        }
                    }
                    champions.Sort((Points scoreFirst, Points scoreSecond) => scoreSecond.Name.CompareTo(scoreFirst.Name));
                    champions.Sort((Points scoreFirst, Points scoreSecond) => scoreSecond.Score.CompareTo(scoreFirst.Score));
                    PrintLeaderboard(champions);

                    field = CreateGameField();
                    bombs = PlaceBombs();
                    openedSafeCells = 0;
                    steppedOnMine = false;
                    introActivated = true;
                }
                if (outroActivated)
                {
                    Console.WriteLine("\nBRAVOOOS! Otvri 35 kletki bez kapka kryv.");
                    DrawField(bombs);
                    Console.WriteLine("Daj si imeto, batka: ");
                    string name = Console.ReadLine();
                    Points score = new Points(name, openedSafeCells);
                    champions.Add(score);
                    PrintLeaderboard(champions);
                    field = CreateGameField();
                    bombs = PlaceBombs();
                    openedSafeCells = 0;
                    outroActivated = false;
                    introActivated = true;
                }
            }
            while (command != "exit");
            Console.WriteLine("Made in Bulgaria - Uauahahahahaha!");
            Console.WriteLine("AREEEEEEeeeeeee.");
            Console.Read();
        }
        static void Main()
        {
            string command = string.Empty;
            char[,] field = CreateField();
            char[,] mines = PlaceMines();
            int counter = 0;
            bool isMine = false;
            List<Points> highScores = new List<Points>(6);
            int row = 0;
            int col = 0;
            bool play = true;
            const int maxPoints = 35;
            bool haveMaxPoints = false;

            do
            {
                if (play)
                {
                    Console.WriteLine("Let's play MineSweeper. Try to find fields without mines." +
                    " Command 'top' shows champions list, 'restart' starts a new game, 'exit' exits the game");
                    PrintField(field);
                    play = false;
                }
                Console.Write("Enter rows and columns: ");
                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":
                        PrintHighScores(highScores);
                        break;
                    case "restart":
                        field = CreateField();
                        mines = PlaceMines();
                        PrintField(field);
                        isMine = false;
                        play = false;
                        break;
                    case "exit":
                        Console.WriteLine("Game over!");
                        break;
                    case "turn":
                        if (mines[row, col] != '*')
                        {
                            if (mines[row, col] == '-')
                            {
                                Move(field, mines, row, col);
                                counter++;
                            }
                            if (maxPoints == counter)
                            {
                                haveMaxPoints = true;
                            }
                            else
                            {
                                PrintField(field);
                            }
                        }
                        else
                        {
                            isMine = true;
                        }
                        break;
                    default:
                        Console.WriteLine("\nError! Invalid Command\n");
                        break;
                }
                if (isMine)
                {
                    PrintField(mines);
                    Console.Write("\nYou loose with {0} points. " +
                        "Enter nickname: ", counter);
                    string nickname = Console.ReadLine();
                    Points user = new Points(nickname, counter);
                    if (highScores.Count < 5)
                    {
                        highScores.Add(user);
                    }
                    else
                    {
                        for (int i = 0; i < highScores.Count; i++)
                        {
                            if (highScores[i].UserPoints < user.UserPoints)
                            {
                                highScores.Insert(i, user);
                                highScores.RemoveAt(highScores.Count - 1);
                                break;
                            }
                        }
                    }
                    highScores.Sort((Points user1, Points user2) => user2.UserName.CompareTo(user1.UserName));
                    highScores.Sort((Points user1, Points user2) => user2.UserPoints.CompareTo(user1.UserPoints));
                    PrintHighScores(highScores);

                    field = CreateField();
                    mines = PlaceMines();
                    counter = 0;
                    isMine = false;
                    play = true;
                }
                if (haveMaxPoints)
                {
                    Console.WriteLine("\nWell done! You passed 35 cells.");
                    PrintField(mines);
                    Console.WriteLine("Enter your name: ");
                    string name = Console.ReadLine();
                    Points userPoints = new Points(name, counter);
                    highScores.Add(userPoints);
                    PrintHighScores(highScores);
                    field = CreateField();
                    mines = PlaceMines();
                    counter = 0;
                    haveMaxPoints = false;
                    play = true;
                }
            }
            while (command != "exit");
            Console.WriteLine("You win!");
            Console.WriteLine("Well done!");
            Console.Read();
        }
        public static void Main()
        {
            const int MAX_MOVES = 35;

            string command = string.Empty;
            char[,] playBoard = CreatePlayBoard();
            char[,] mines = PutRandomMines();
            int counter = 0;
            bool stepOnMine = false;
            List<Points> championsList = new List<Points>(6);
            int row = 0;
            int column = 0;
            bool commandStart = true;
            bool isMaxMoves = false;

            do
            {
                if (commandStart)
                {
                    Console.WriteLine("Let's play Mines.Try to find all fields without mines." +
                    " Command 'top' shows score table, 'restart' starts a new game, 'exit' quits the game!");
                    PrintBoard(playBoard);
                    commandStart = false;
                }

                Console.Write("Please, enter row and column or command : ");
                command = Console.ReadLine().Trim();

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

                switch (command)
                {
                    case "top":
                        PrintFinalScore(championsList);
                        break;

                    case "restart":
                        playBoard = CreatePlayBoard();
                        mines = PutRandomMines();
                        PrintBoard(playBoard);
                        stepOnMine = false;
                        commandStart = false;
                        break;

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

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

                            if (MAX_MOVES == counter)
                            {
                                isMaxMoves = true;
                            }
                            else
                            {
                                PrintBoard(playBoard);
                            }
                        }
                        else
                        {
                            stepOnMine = true;
                        }

                        break;

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

                if (stepOnMine)
                {
                    PrintBoard(mines);
                    Console.Write("\nGame over!Your are death with {0} points. " + "Please, enter your nickname: ", counter);
                    string nickname = Console.ReadLine();
                    Points playerScore = new Points(nickname, counter);

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

                    championsList.Sort((Points player1, Points player2) => player2.Name.CompareTo(player1.Name));
                    championsList.Sort((Points player1, Points player2) => player2.Score.CompareTo(player1.Score));
                    PrintFinalScore(championsList);

                    playBoard = CreatePlayBoard();
                    mines = PutRandomMines();
                    counter = 0;
                    stepOnMine = false;
                    commandStart = true;
                }

                if (isMaxMoves)
                {
                    Console.WriteLine("\nExcellent.You open 35 cells.");
                    PrintBoard(mines);
                    Console.WriteLine("Please, enter your name: ");
                    string name = Console.ReadLine();
                    Points player = new Points(name, counter);
                    championsList.Add(player);
                    PrintFinalScore(championsList);
                    playBoard = CreatePlayBoard();
                    mines = PutRandomMines();
                    counter = 0;
                    isMaxMoves = false;
                    commandStart = true;
                }
            }
            while (command != "exit");
            Console.WriteLine("Made in Bulgaria");
            Console.Read();
        }
Esempio n. 6
0
        public static void Main()
        {
            const int MAX_MOVES = 35;

            string command = string.Empty;

            char[,] playBoard = CreatePlayBoard();
            char[,] mines     = PutRandomMines();
            int           counter       = 0;
            bool          stepOnMine    = false;
            List <Points> championsList = new List <Points>(6);
            int           row           = 0;
            int           column        = 0;
            bool          commandStart  = true;
            bool          isMaxMoves    = false;

            do
            {
                if (commandStart)
                {
                    Console.WriteLine("Let's play Mines.Try to find all fields without mines." +
                                      " Command 'top' shows score table, 'restart' starts a new game, 'exit' quits the game!");
                    PrintBoard(playBoard);
                    commandStart = false;
                }

                Console.Write("Please, enter row and column or command : ");
                command = Console.ReadLine().Trim();

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

                switch (command)
                {
                case "top":
                    PrintFinalScore(championsList);
                    break;

                case "restart":
                    playBoard = CreatePlayBoard();
                    mines     = PutRandomMines();
                    PrintBoard(playBoard);
                    stepOnMine   = false;
                    commandStart = false;
                    break;

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

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

                        if (MAX_MOVES == counter)
                        {
                            isMaxMoves = true;
                        }
                        else
                        {
                            PrintBoard(playBoard);
                        }
                    }
                    else
                    {
                        stepOnMine = true;
                    }

                    break;

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

                if (stepOnMine)
                {
                    PrintBoard(mines);
                    Console.Write("\nGame over!Your are death with {0} points. " + "Please, enter your nickname: ", counter);
                    string nickname    = Console.ReadLine();
                    Points playerScore = new Points(nickname, counter);

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

                    championsList.Sort((Points player1, Points player2) => player2.Name.CompareTo(player1.Name));
                    championsList.Sort((Points player1, Points player2) => player2.Score.CompareTo(player1.Score));
                    PrintFinalScore(championsList);

                    playBoard    = CreatePlayBoard();
                    mines        = PutRandomMines();
                    counter      = 0;
                    stepOnMine   = false;
                    commandStart = true;
                }

                if (isMaxMoves)
                {
                    Console.WriteLine("\nExcellent.You open 35 cells.");
                    PrintBoard(mines);
                    Console.WriteLine("Please, enter your name: ");
                    string name   = Console.ReadLine();
                    Points player = new Points(name, counter);
                    championsList.Add(player);
                    PrintFinalScore(championsList);
                    playBoard    = CreatePlayBoard();
                    mines        = PutRandomMines();
                    counter      = 0;
                    isMaxMoves   = false;
                    commandStart = true;
                }
            }while (command != "exit");
            Console.WriteLine("Made in Bulgaria");
            Console.Read();
        }