Esempio n. 1
0
        public bool Check_for_end_of_game(Game game)
        {
            var frames = game.Frames.ToArray();

            return Check_for_pair_in_10th_frame(frames)  ||
                    Check_for_single_roll_after_spare_in_10th_frame(frames) ||
                    Check_for_2_more_rolls_after_strike_in_10th_frame(frames);
        }
Esempio n. 2
0
        public void Pass_through_score()
        {
            var game = new Game{Score = 42, Frames = new[]{new Frame()}};

            var sut = new Mappings();
            var result = new ViewModel();
            sut.Result += _ => result = _;
            sut.Map(game);

            Assert.AreEqual(42, result.GameScore);
        }
Esempio n. 3
0
        public void Fill_frames()
        {
            var game = new Game
            {
                Frames = new List<Frame>
                {
                    new Frame{Roll1 = 10, Score = 20}, // strike
                    new Frame{Roll1 = 5, Roll2 = 5, Score = 13}, // spare
                    new Frame{Roll1 = 3, Roll2 = 6, Score = 9}, // 2 rolls
                    new Frame{Roll1 = 3}, // 1 roll
                    new Frame{}, // no rolls yet
                    new Frame{Roll1 = 10, Roll2 = 10} // 2 strikes in final frame
                }
            };

            var sut = new Mappings();
            var result = new ViewModel();
            sut.Result += _ => result = _;
            sut.Map(game);

            var lvframes = new List<ListViewItem>();
            var lvi = new ListViewItem("6");
            lvi.SubItems.Add("X");
            lvi.SubItems.Add("X");
            lvi.SubItems.Add("");
            lvframes.Add(lvi);
            lvi = new ListViewItem("5");
            lvi.SubItems.Add("");
            lvi.SubItems.Add("");
            lvi.SubItems.Add("");
            lvframes.Add(lvi);
            lvi = new ListViewItem("4");
            lvi.SubItems.Add("3");
            lvi.SubItems.Add("");
            lvi.SubItems.Add("");
            lvframes.Add(lvi);
            lvi = new ListViewItem("3");
            lvi.SubItems.Add("3");
            lvi.SubItems.Add("6");
            lvi.SubItems.Add("9");
            lvframes.Add(lvi);
            lvi = new ListViewItem("2");
            lvi.SubItems.Add("5");
            lvi.SubItems.Add("/");
            lvi.SubItems.Add("13");
            lvframes.Add(lvi);
            lvi = new ListViewItem("1");
            lvi.SubItems.Add("X");
            lvi.SubItems.Add("");
            lvi.SubItems.Add("20");
            lvframes.Add(lvi);

            Equalidator.AreEqual(result.Frames, lvframes, true);
        }
Esempio n. 4
0
        public void Map(Game game)
        {
            var vm = new ViewModel {
                                        GameScore = game.Score,
                                        GameFinished = game.Finished
                                   };

            var vmFrames = new List<ListViewItem>();
            var i = game.Frames.Count();
            foreach (var f in game.Frames.Reverse())
            {
                var vmFrame = new ListViewItem(i.ToString());
                vmFrame.SubItems.Add(f.Roll1 == null ? "" : f.Roll1 == 10 ? "X" : f.Roll1.ToString());
                vmFrame.SubItems.Add(f.Roll2 == null ? "" : f.Roll2 == 10 ? "X" : (f.Roll1 + f.Roll2) == 10 ? "/" : f.Roll2.ToString());
                vmFrame.SubItems.Add(f.Score == null ? "" : f.Score == 0 ? "" : f.Score.ToString());

                vmFrames.Add(vmFrame);
                i--;
            }
            vm.Frames = vmFrames;

            Result(vm);
        }