Beispiel #1
0
        public static void PlayRollOrHold(RollOrHoldGame obj)
        {
            // bool isPlaying = true, keepRolling = true;

            obj.KeepRollingDice = true;
            int turnScore = 0, totalScore = 0, counter = 1;

            Console.WriteLine("To roll enter r/R  || To hold enter h/H");

            while (obj.IsPlaying)
            {
                if (obj.CheckForTargetScore(ref totalScore, ref turnScore))
                {
                    PrintResult(ref counter);
                    obj.IsPlaying = false;
                }
                else
                {
                    Console.WriteLine($"\n\nTURN {counter++}");
                    obj.KeepRollingDice = true;
                    PlayATurn(obj, ref turnScore, ref totalScore);
                }
            }
            Console.ReadLine();
        }
Beispiel #2
0
        public static void PlayATurn(RollOrHoldGame instanceOfGame, ref int turnScore, ref int totalScore)
        {
            string userChoice;
            int    randomRoll;
            bool   isUserChoosingToRoll, isUserChoosingToHold;

            while (instanceOfGame.KeepRollingDice)
            {
                Console.Write("Roll or Hold  (r/h) : ");
                userChoice           = Console.ReadLine();
                isUserChoosingToRoll = userChoice.ToLower().Equals(RollOrHoldGame.ROLL);
                isUserChoosingToHold = userChoice.ToLower().Equals(RollOrHoldGame.HOLD);

                if (isUserChoosingToRoll)
                {
                    randomRoll = GenerateRandomNumber();
                    if (randomRoll != 1)
                    {
                        Console.WriteLine($"Die : {randomRoll}");
                        turnScore += randomRoll;
                        if (instanceOfGame.CheckForTargetScore(ref totalScore, ref turnScore))
                        {
                            PrintTurnScore(ref turnScore, ref totalScore);
                            instanceOfGame.KeepRollingDice = false;
                        }
                    }
                    else
                    {
                        Console.WriteLine($"You have rolled 1 , your total score will be set to zero");
                        instanceOfGame.GameReset(ref turnScore, ref totalScore);
                    }
                }
                else if (isUserChoosingToHold)
                {
                    PrintTurnScore(ref turnScore, ref totalScore);
                    instanceOfGame.KeepRollingDice = false;
                }
            }
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            RollOrHoldGame rollOrHoldGameInstance = new RollOrHoldGame(true, 0, 0);

            PlayRollOrHold(rollOrHoldGameInstance);
        }