Example #1
0
        private void HandleGameMenuSelection(int response, bool twoPlayer = false)
        {
            if (!twoPlayer)
            {
                switch (response)
                {
                case 1:     //High Low
                    HighLow hl = new HighLow(_user);
                    hl.Play();
                    break;

                case 2:     //Mastermind
                    Mastermind mm = new Mastermind(_user);
                    mm.Play();
                    break;

                case 3:     //Math Challenge
                    MathChallenge mc = new MathChallenge(_user);
                    mc.Play();
                    break;

                case 4:     //Hangman
                    Hangman hm = new Hangman(_user);
                    hm.Play();
                    break;

                case 5:     //Crack the Code
                    CrackTheCode ctc = new CrackTheCode(_user);
                    ctc.Play();
                    break;

                case 0:     //Back
                    break;
                }
            }
            else
            {
                switch (response)
                {
                case 1:     //TicTacToe
                    TicTacToe ttt = new TicTacToe(_user);
                    ttt.LogInSecondPlayer();
                    ttt.Play();
                    break;

                case 2:     //War
                    War w = new War(_user);
                    w.LogInSecondPlayer();
                    w.Play();
                    break;

                case 0:     //Back
                    break;
                }
            }
        }
Example #2
0
        public override void Play()
        {
            _numberOfMoves = 0;
            UpdateGameDisplay();
            string question = "Please select a maximum number... ";

            _maximumNumber = Validation.GetValidatedInt(question);
            //Generate a random number between 1 and the maximum for the user to guess
            Random rnd = new Random();

            _correctNumber = rnd.Next(1, _maximumNumber + 1);
            UI.DisplaySuccess($" Ok, I have selected a number between 1 and {_maximumNumber}");

            //Until the user has won, keep guessing and hinting
            while (_guessedNumber != _correctNumber)
            {
                //Prompt user for a guess.. reuse previously created method to validate
                question = "What is your guess?... ";
                int[] range = { 0, _maximumNumber };
                _guessedNumber = Validation.GetValidatedRange(question, range);
                // Create another method to compare player's guess to generated random number. If incorrect, provide the user a hint of :"too low" or "too high"
                CheckGuess();
                _numberOfMoves += 1;
            }
            _score += CalculateScore();
            if (!CheckWinner())
            {
                //Keep Trying?
                question = "Keep playing? You need 1000 points to win... [Y/N] ";
                string[] conditionals = { "y", "n" };
                string   response     = Validation.GetValidatedConditional(question, conditionals);
                if (response == "Y")
                {
                    Play();
                }
            }
            else
            {
                DisplayWinner(true);
                if (PlayAgain())
                {
                    HighLow newGame = new HighLow(_player);
                    newGame.Play();
                }
            }
        }//end of play method