Beispiel #1
0
        public CellGuess ComputerGuess(Board i_Board)
        {
            CellGuess computerGuess = new CellGuess();
            Random    random        = new Random();

            while (true)
            {
                int rowGuess    = random.Next(0, i_Board.Height);
                int columnGuess = random.Next(0, i_Board.Width);
                computerGuess.RowIndex    = rowGuess;
                computerGuess.ColumnIndex = columnGuess;

                if (!this.BoardGame.CurrentBoard[rowGuess, columnGuess].isReveal)
                {
                    break;
                }
            }

            return(computerGuess);
        }
Beispiel #2
0
 public bool Equals(CellGuess i_OtherGuess)
 {
     return(this.m_RowIndex == i_OtherGuess.RowIndex && this.m_ColumnIndex == i_OtherGuess.ColumnIndex);
 }
        private CellGuess getGuessFromUser(Player i_CurrentPlayer, int i_GuessNumber)
        {
            CellGuess guess             = new CellGuess();
            string    outOfRangeMessage = "Your choice is out of the range of te board\n" +
                                          "Please try again";
            string preMessage = String.Format("{0}, now is your turn!\n" +
                                              "Guess number {1}", i_CurrentPlayer.Name, i_GuessNumber);

            Console.WriteLine(preMessage);

            while (true)
            {
                try
                {
                    int rowGuess    = -2;
                    int columnGuess = -2;

                    while (true)
                    {
                        Console.Write("Enter row guess: ");
                        rowGuess = validateUserRowGuess(Console.ReadLine());

                        if (rowGuess >= 0)
                        {
                            break;
                        }

                        Console.WriteLine(outOfRangeMessage);
                    }
                    while (true)
                    {
                        Console.Write("Enter column guess: ");
                        columnGuess = validateUserColumnGuess(Console.ReadLine());

                        if (columnGuess >= 0)
                        {
                            break;
                        }

                        Console.WriteLine(outOfRangeMessage);
                    }
                    guess.RowIndex    = rowGuess;
                    guess.ColumnIndex = columnGuess;

                    if (!m_Game.BoardGameMatrix[rowGuess, columnGuess].isReveal)
                    {
                        break;
                    }
                    else
                    {
                        Console.WriteLine("You can not guess reveal cell, try again please");
                        System.Threading.Thread.Sleep(2000);
                    }
                }
                catch (ArgumentOutOfRangeException)
                {
                    Console.WriteLine("Invalid row argument");
                }
            }

            return(guess);
        }