Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            var board = new Board(9, 9, 10);

            while (true)
            {
                Console.WriteLine("Write quit to leave or the coordinates row,col");
                var response = Console.ReadLine();
                if (response == "" || response == "quit")
                {
                    break;
                }
                else
                {
                    var arrResponse = response.Split(',');
                    if (arrResponse.Length != 2)
                    {
                        break;
                    }
                    var row = Int32.Parse(arrResponse[0]);
                    var col = Int32.Parse(arrResponse[1]);
                    board.Select(row, col);
                    board.PrintBoard(false);
                    if (board.Status == Constants.GameStatus.Ended)
                    {
                        Console.WriteLine("Game Ended");
                        board.PrintBoard(true);
                        break;
                    }
                }
            }
            Console.WriteLine("Process done");
            Console.ReadLine();
        }
Ejemplo n.º 2
0
        public void Start()
        {
            int r     = 0;
            int c     = 0;
            int m     = 0;
            int count = 0;


            do
            {
                //user inputing number of rows, columns and mines found in the board
                Console.Write("Rows: ");
                r = Convert.ToInt32(Console.ReadLine());
                Console.Write("Columns: ");
                c = Convert.ToInt32(Console.ReadLine());


                if (r != 0 && c != 0)
                {
                    b = new Board(r, c);
                    Console.WriteLine("Would you like to set up the board manually? (Y/N)");
                    string ans = Console.ReadLine();

                    //filling up the grid manually
                    if (ans.Equals("Y", StringComparison.InvariantCultureIgnoreCase))
                    {
                        bool userInputValid = false;
                        do
                        {
                            userInputValid = b.SetUpBoardManually();
                        } while (userInputValid != true);
                        board = b.GetBoard();
                    }

                    //filling up the grid automatically
                    else if (ans.Equals("N", StringComparison.InvariantCultureIgnoreCase))
                    {
                        Console.WriteLine("Setting up the board automatically.");
                        Console.Write("Enter max number of mines: ");
                        m = Convert.ToInt32(Console.ReadLine());
                        b.SetUpBoardAutomatically(m);
                        board = b.GetBoard();
                        b.PrintBoard();
                    }

                    //array is traversed to count the number of neighbouring mines for each element
                    for (int i = 0; i < r; i++)
                    {
                        for (int j = 0; j < c; j++)
                        {
                            if (board[i, j] != '*')
                            {
                                int mineCount = CountNeighbourMines(i, j);
                                board[i, j] = (char)(mineCount + 48);
                            }
                        }
                    }

                    boards.Add(board); //filling up list with boards that contain information about number of neighbouring mines
                }
                Console.WriteLine();
            } while (r != 0 && c != 0);

            //commencing printing of results - each array in the list is sent to be printed
            for (count = 0; count < boards.Count; count++)
            {
                Console.WriteLine("Field #" + (count + 1));
                PrintMineCountBoard(boards[count]);
                Console.WriteLine();
            }

            Console.WriteLine("Press any key to exit");
            Console.ReadKey();
        }