public Outcome MakeGuess(int guess) { if (guess < 1 || guess > 100) { throw new ArgumentOutOfRangeException(); } for (int i = 0; i < MaxNumberOfGuesses; i++) { if (_guessedNumbers[i].Number == guess) { Outcome = Outcome.OldGuess; return(Outcome); } } if (Count >= 7) { Outcome = Outcome.NoMoreGuesses; return(Outcome); } if (guess < _number) { Outcome = Outcome.Low; } else if (guess > _number) { Outcome = Outcome.High; } else { Outcome = Outcome.Right; CanMakeGuess = false; } GuessedNumber gn = new GuessedNumber(); gn.Number = guess; gn.Outcome = Outcome; _guessedNumbers[Count] = gn; Guess = guess; Count++; if (Count == MaxNumberOfGuesses) { CanMakeGuess = false; } return(Outcome); }
public void Initialize() { Random r = new Random(); Outcome = Outcome.Indefinite; Number = r.Next(1, 100); Count = 0; Guess = null; Outcome = Outcome.Indefinite; CanMakeGuess = true; for (int i = 0; i < _guessedNumbers.Length; i++) { _guessedNumbers[i] = new GuessedNumber(); } }