Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            int inputOption = 0;

            Console.WriteLine($"Hello there, welcome to a Bowling game!\nPlease select one of the following:\n1) Enter the frames manually\n2) Auto generated values\nPlease select and press Enter to start");
            string result = Console.ReadLine();

            bool isManual = Int32.TryParse(result, out inputOption) ? inputOption == 1 : false;

            ScoreCard scoreCard = ScoreCard.GenerteEmptyScoreCards();

            // run as long as the game runs
            while (Game.IsEligibleForAnotherTry(scoreCard))
            {
                Tuple <int, int> tries = GetNextFrame(isManual, scoreCard);
                if (tries == null)
                {
                    break;
                }

                try
                {
                    PrintInformation($"Try1 {tries.Item1}, Try2: {tries.Item2}");

                    scoreCard = Game.RollNewFrame(scoreCard, tries.Item1, tries.Item2);

                    if (tries.Item1 == BowlingGameExtenstions.NUM_OF_PINS)
                    {
                        PrintInformation("Strike!!! Well done!");
                    }

                    Console.WriteLine($"The current score is: {Game.GetScore(scoreCard)}.");
                }
                catch (Exception ex)
                {
                    PrintError($"An error occurred: {ex.Message}");
                }
            }

            if (Game.GetScore(scoreCard) == BowlingGameExtenstions.NUM_OF_PINS * 30)
            {
                PrintInformation("*** You are a the KING. Big Lebowski - behind you!");
            }

            Console.WriteLine($"\nThe game's frames were (score {Game.GetScore(scoreCard)}):\n{scoreCard.DisplayScoreCard()}\n\nPress Enter to exit, goodbye..");
            Console.ReadLine();
        }
Ejemplo n.º 2
0
        public void Simulate_FullGame_3_Test()
        {
            ScoreCard scoreCard = ScoreCard.GenerteEmptyScoreCards();

            // Run for 9 rounds, but leave the last round for a fixed input.
            for (int i = 0; i < BowlingGameExtenstions.NUM_OF_REGULAR_ROUNDS - 1; i++)
            {
                Tuple <int, int> tries = GenerateFrame(scoreCard);

                scoreCard = Game.RollNewFrame(scoreCard, tries.Item1, tries.Item2);
            }

            // Add the last round
            scoreCard = Game.RollNewFrame(scoreCard, BowlingGameExtenstions.NUM_OF_PINS, 0);

            Trace.WriteLine($"score is {Game.GetScore(scoreCard)}");

            if ((scoreCard.Length == BowlingGameExtenstions.NUM_OF_REGULAR_ROUNDS) &&
                (scoreCard.GetFrameType(scoreCard.Length - 1) == FrameTypeEnum.Spare ||
                 scoreCard.GetFrameType(scoreCard.Length - 1) == FrameTypeEnum.Strike))
            {
                throw new IllegalBowlingActionException("Should have another extra round");
            }
        }