public void Initialize()//TODO: initiserar klassens fält och egenskaper - listan rensas -
        {
            Random random = new Random();

            Number = random.Next(1, 101);
            _guessedNumbers.Clear();
            _lastGuessedNumber = new GuessedNumber();
        }
Exemplo n.º 2
0
        //Rensar _guessedNumbers listan, Initierar Random, Tilldelar _number ett värde mellan 1 och 100 (Krav 8) samt ser till att Outcome sätts till Outcome.Indefinite
        public void Initialize()
        {
            _guessedNumbers.Clear();
            Random random = new Random();

            _number            = random.Next(1, 101);
            _lastGuessedNumber = new GuessedNumber {
                Number = null, Outcome = Outcome.Indefinite
            };
        }
 public Outcome MakeGuess(int guess)
 {
     if (!CanMakeGuess)
     {
         return(Outcome.NoMoreGuesses);
     }
     if (guess < 1 || guess > 100)
     {
         throw new ArgumentOutOfRangeException();
     }
     foreach (var old in _guessedNumbers)
     {
         if (old.Number.Equals(guess))
         {
             return(Outcome.OldGuess);
         }
     }
     if (guess > _number)
     {
         privateOutcome = Outcome.High;
     }
     else if (guess < _number)
     {
         privateOutcome = Outcome.Low;
     }
     else if (guess == _number)
     {
         privateOutcome = Outcome.Right;
     }
     _lastGuessedNumber = new GuessedNumber
     {
         Number  = guess,
         Outcome = privateOutcome
     };
     _guessedNumbers.Add(_lastGuessedNumber);
     return(privateOutcome);
 }
 public void Initialize()
 {
     _guessedNumbers.Clear();
     _number = new Random().Next(MinVal, MaxVal + 1);
     _lastGuessedNumber = new GuessedNumber { Number = null, Outcome = Outcome.Indefinite};
 }
        public void Initialize()
        {
            _guessedNumbers.Clear();
            _lastGuessedNumber = new GuessedNumber { Number = null, Outcome = Outcome.Indefinite };

            Random random = new Random();
            _number = random.Next(1, 100);
        }
        public Outcome MakeGuess(int guess)
        {
            if (guess < 1 || guess > 100)
            {
                throw new ArgumentOutOfRangeException();
            }

            if (!CanMakeGuess)
            {
                return Outcome.NoMoreGuesses;
            }

            var guessedNumber = new GuessedNumber();
            guessedNumber.Number = guess;

            if (GuessedNumbers.Contains(guessedNumber))
            {
                guessedNumber.Outcome = Outcome.OldGuess;
                _lastGuessedNumber = guessedNumber;
                return Outcome.OldGuess;
            }

            if (guess > _number)
            {
                guessedNumber.Outcome = Outcome.High;
            }
            else if (guess < _number)
            {
                guessedNumber.Outcome = Outcome.Low;
            }
            else if (guess == _number)
            {
                guessedNumber.Outcome = Outcome.Right;
            }

            _guessedNumbers.Add(guessedNumber);
            _lastGuessedNumber = guessedNumber;

            return guessedNumber.Outcome;
        }
 public void Initialize()
 {
     _guessedNumbers    = new List<GuessedNumber>(MaxNumberOfGuesses);
     _lastGuessedNumber = new GuessedNumber();
 }
        public Outcome MakeGuess(int guess)
        {
            GuessedNumber newGuess = new GuessedNumber();
            Outcome guessOutcome = Outcome.odefinierad;
            Count++;

            if (guess < 1 || guess > 100)
            {
                throw new ArgumentOutOfRangeException();
            }
            if (Count <= MaxNumberOfGuesses)
            {
                if (guess != _number)
                {
                    if (guess < _number)
                    {
                        guessOutcome = Outcome.låg;
                    }
                    else if (guess > _number)
                    {
                        guessOutcome = Outcome.hög;
                    }

                    foreach (GuessedNumber guessedNumber in _guessedNumbers)
                    {
                        if (guess == guessedNumber.Number)
                        {
                            Count--;
                            guessOutcome = Outcome.gammal;
                            break;
                        }
                    }
                }
                else if (guess == _number)
                {
                    guessOutcome = Outcome.rätt;
                }
            }
            else
            {
                guessOutcome = Outcome.s**t;
            }

            newGuess.Number = guess;
            newGuess.Outcome = guessOutcome;
            _lastGuessedNumber = newGuess;
            _guessedNumbers.Add(newGuess);

            return guessOutcome;
        }