Exemple #1
0
 private void PlayRound(CurrentGameInfo CGI)
 {
     GetPlayerKey(CGI);
     _ui.ClearConsole();
     _ui.WriteNumberList(CGI.PlayerSolution);
     _ui.WriteKeyList(CGI.KeyList);
 }
Exemple #2
0
        internal void StartNewGame()
        {
            CurrentGameInfo CGI = _modelBuilder.GetStartModel();

            while (CGI.Tries > 0)
            {
                PlayRound(CGI);
                CGI = CheckForWin(CGI);
            }
        }
Exemple #3
0
        private void GetPlayerKey(CurrentGameInfo CGI)
        {
            CGI.PlayerSolution.Clear();
            CGI.KeyList.Clear();

            while (CGI.PlayerSolution.Count < 4)
            {
                PlayerInput(CGI);
            }

            CGI.KeyList = _gameLogic.GenerateKeyList(CGI);
        }
Exemple #4
0
        private void PlayerInput(CurrentGameInfo CGI)
        {
            int playerGuess;

            _ui.PlayerEnter();

            Int32.TryParse(Console.ReadLine(), out playerGuess);
            bool valid = _gameLogic.Validate(playerGuess);

            if (valid)
            {
                _ui.ClearLine();
                CGI.PlayerSolution.Add(playerGuess);
            }
            else
            {
                _ui.InvalidMessage();
            }
        }
Exemple #5
0
        private CurrentGameInfo CheckForWin(CurrentGameInfo CGI)
        {
            bool result = CGI.PlayerSolution.SequenceEqual(CGI.Solution);

            if (result && CGI.Tries > 0)
            {
                _ui.Win();
                CGI.Tries = 0;
            }
            else if (!result && CGI.Tries > 1)
            {
                CGI.Tries--;
                _ui.TryAgain(CGI.Tries);
            }
            else if (CGI.Tries == 1)
            {
                _ui.Loser(CGI.Solution);
                CGI.Tries = 0;
            }

            return(CGI);
        }