Esempio n. 1
0
        public void PerfectGameTest()
        {
            var broker = new ScoreBroker();
            var game   = new BowlingGame(broker);

            broker.Command(new RollballCommand(game, 10));
            broker.Command(new RollballCommand(game, 10));
            broker.Command(new RollballCommand(game, 10));
            broker.Command(new RollballCommand(game, 10));
            broker.Command(new RollballCommand(game, 10));
            broker.Command(new RollballCommand(game, 10));
            broker.Command(new RollballCommand(game, 10));
            broker.Command(new RollballCommand(game, 10));
            broker.Command(new RollballCommand(game, 10));
            broker.Command(new RollballCommand(game, 10));
            broker.Command(new RollballCommand(game, 10));
            broker.Command(new RollballCommand(game, 10));

            broker.Frames[9].TotalScore.Should().Be(300);
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            var broker = new ScoreBroker();
            var game   = new BowlingGame(broker);

            broker.Command(new RollballCommand(game, 1));
            broker.Command(new RollballCommand(game, 4));
            broker.Command(new RollballCommand(game, 4));
            broker.Command(new RollballCommand(game, 5));
            broker.Command(new RollballCommand(game, 6));
            broker.Command(new RollballCommand(game, 4));
            broker.Command(new RollballCommand(game, 5));
            broker.Command(new RollballCommand(game, 5));
            broker.Command(new RollballCommand(game, 10));
            broker.Command(new RollballCommand(game, 0));
            broker.Command(new RollballCommand(game, 1));
            broker.Command(new RollballCommand(game, 7));
            broker.Command(new RollballCommand(game, 3));
            broker.Command(new RollballCommand(game, 6));
            broker.Command(new RollballCommand(game, 4));
            broker.Command(new RollballCommand(game, 10));
            broker.Command(new RollballCommand(game, 2));
            broker.Command(new RollballCommand(game, 8));
            broker.Command(new RollballCommand(game, 6));


            var table = new ConsoleTable("FrameNumber", "RollNumber", "KnockedDownPins", "TotalScore", "Note");

            foreach (var frame in broker.Frames)
            {
                table.AddRow(frame.Number, 1, frame.Roll1.KnockedDownPins, "", frame.StrikeNote);

                if (frame.Number == 10)
                {
                    table.AddRow(frame.Number, 2, frame.Roll2?.KnockedDownPins, "", frame.SpareNote);
                    table.AddRow(frame.Number, 3, frame.Roll3?.KnockedDownPins, frame.TotalScore, "");
                }
                else
                {
                    table.AddRow(frame.Number, 2, frame.Roll2?.KnockedDownPins, frame.TotalScore, frame.SpareNote);
                }
            }
            table.Write();
            var f = broker.Query <Frame>(new FrameQuery()
            {
                Target = game
            });

            Console.WriteLine($"The total score is:{f.TotalScore}");
            Console.ReadLine();
        }
Esempio n. 3
0
        public void GameTest()
        {
            var broker = new ScoreBroker();
            var game   = new BowlingGame(broker);

            broker.Command(new RollballCommand(game, 1));
            broker.Command(new RollballCommand(game, 4));
            broker.Command(new RollballCommand(game, 4));
            broker.Command(new RollballCommand(game, 5));
            broker.Command(new RollballCommand(game, 6));
            broker.Command(new RollballCommand(game, 4));
            broker.Command(new RollballCommand(game, 5));
            broker.Command(new RollballCommand(game, 5));
            broker.Command(new RollballCommand(game, 10));
            broker.Command(new RollballCommand(game, 0));
            broker.Command(new RollballCommand(game, 1));
            broker.Command(new RollballCommand(game, 7));
            broker.Command(new RollballCommand(game, 3));
            broker.Command(new RollballCommand(game, 6));
            broker.Command(new RollballCommand(game, 4));
            broker.Command(new RollballCommand(game, 10));
            broker.Command(new RollballCommand(game, 2));
            broker.Command(new RollballCommand(game, 8));
            broker.Command(new RollballCommand(game, 6));

            broker.Frames[0].TotalScore.Should().Be(5);
            broker.Frames[1].TotalScore.Should().Be(14);
            broker.Frames[2].TotalScore.Should().Be(29);
            broker.Frames[3].TotalScore.Should().Be(49);
            broker.Frames[4].TotalScore.Should().Be(60);
            broker.Frames[5].TotalScore.Should().Be(61);
            broker.Frames[6].TotalScore.Should().Be(77);
            broker.Frames[7].TotalScore.Should().Be(97);
            broker.Frames[8].TotalScore.Should().Be(117);
            broker.Frames[9].TotalScore.Should().Be(133);
        }