Ejemplo n.º 1
0
        public void ParseSimpleFrame()
        {
            var frame = new Frame("11");

            int baseValue = frame.GetBaseValue();
            Assert.AreEqual(2, baseValue);
        }
Ejemplo n.º 2
0
        //Get values for all cells & organize it into the Game / Frame structure properly.
        private void RefreshFrames()
        {
            //Create an array of Frame objects representative of the current state of all input boxes.
            Frame[] _frames = new Frame[10];
            _frames[0] = new Frame(1, new int[] { frame1r1.IntValue, frame1r2.IntValue });
            _frames[1] = new Frame(2, new int[] { frame2r1.IntValue, frame2r2.IntValue });
            _frames[2] = new Frame(3, new int[] { frame3r1.IntValue, frame3r2.IntValue });
            _frames[3] = new Frame(4, new int[] { frame4r1.IntValue, frame4r2.IntValue });
            _frames[4] = new Frame(5, new int[] { frame5r1.IntValue, frame5r2.IntValue });
            _frames[5] = new Frame(6, new int[] { frame6r1.IntValue, frame6r2.IntValue });
            _frames[6] = new Frame(7, new int[] { frame7r1.IntValue, frame7r2.IntValue });
            _frames[7] = new Frame(8, new int[] { frame8r1.IntValue, frame8r2.IntValue });
            _frames[8] = new Frame(9, new int[] { frame9r1.IntValue, frame9r2.IntValue });
            _frames[9] = new Frame(10, new int[] { frame10r1.IntValue, frame10r2.IntValue, frame10r3.IntValue });

            //If this is the first update, instantiate the Game object for this window. If not, just update the frames in the pre-existing one.
            if (game == null) {
                game = new Game(_frames);
            } else {
                game.UpdateFrames(_frames);
            }

            //Set subtotal boxes (as long as the frame has been modified)
            int[] _subtotals = game.GetIncremTotals();
            if (frame1r1.Text != string.Empty) {
                frame1total.Text = _subtotals[0].ToString();
            }
            if (frame2r1.Text != string.Empty) {
                frame2total.Text = _subtotals[1].ToString();
            }
            if (frame3r1.Text != string.Empty) {
                frame3total.Text = _subtotals[2].ToString();
            }
            if (frame4r1.Text != string.Empty) {
                frame4total.Text = _subtotals[3].ToString();
            }
            if (frame5r1.Text != string.Empty) {
                frame5total.Text = _subtotals[4].ToString();
            }
            if (frame6r1.Text != string.Empty) {
                frame6total.Text = _subtotals[5].ToString();
            }
            if (frame7r1.Text != string.Empty) {
                frame7total.Text = _subtotals[6].ToString();
            }
            if (frame8r1.Text != string.Empty) {
                frame8total.Text = _subtotals[7].ToString();
            }
            if (frame9r1.Text != string.Empty) {
                frame9total.Text = _subtotals[8].ToString();
            }
            if (frame10r1.Text != string.Empty) {
                frame10total.Text = _subtotals[9].ToString();
            }

            //Set game total status
            gameTotal.Text = ("Game Total: " + game.GetTotal());
        }
Ejemplo n.º 3
0
 //Create Game from array of rolls (Used for testing)
 public Game(int[][] rolls)
 {
     Frame[] _frames = new Frame[rolls.Length];
     for (int i = 0; i < rolls.Length; i++) {
         _frames[i] = new Frame(i, rolls[i]);
     }
     frames = _frames;
     Calculate();
 }
Ejemplo n.º 4
0
        private void ChangeFrame()
        {
            if (_currentFrame.IsSecondThrow() || _currentFrame.IsStrike())
            {
                _previousFrame = _currentFrame;
                _currentFrame = new Frame();

            }
        }
Ejemplo n.º 5
0
 //Create Game from array of Frames
 public Game(Frame[] _frames)
 {
     if(_frames.Length != 10) {
         throw new Exception("Cannot create a game without 10 frames!");
     } else {
         frames = _frames;
         Calculate();
     }
 }
Ejemplo n.º 6
0
        public void FrameShouldCountItsOwnScore()
        {
            //given
            var frame = new Frame {FirstTry = 3, SecondTry = 4};

            //when
            var score = frame.Score;

            //then
            Assert.AreEqual(7, score);
        }
Ejemplo n.º 7
0
Archivo: Game.cs Proyecto: Saulis/Katas
        public int GetSecondNextRoll(Frame frame)
        {
            if(NextFrameHasTwoRolls(frame))
            {
                Frame nextFrame = GetNextFrame(frame);

                return nextFrame.SecondRoll;
            }

            return GetFirstRollFromSecondFrame(frame);
        }
Ejemplo n.º 8
0
        public void FrameShouldCountNextTwoBallsAsScoreWhenThereIsStrike()
        {
            //given
            var frame1 = new Frame {FirstTry = 10, SecondTry = 0};
            var frame2 = new Frame {FirstTry = 5, SecondTry = 2};
            frame1.Next = frame2;

            //when
            var score1 = frame1.Score;

            //then
            Assert.AreEqual(17, score1);
        }
Ejemplo n.º 9
0
        public void FrameShouldCountNextBallAsScoreWhenThereIsSpare()
        {
            //given
            var frame1 = new Frame {FirstTry = 4, SecondTry = 6};
            var frame2 = new Frame {FirstTry = 5, SecondTry = 2};
            frame1.Next = frame2;

            //when
            var score1 = frame1.Score;

            //then
            Assert.AreEqual(15, score1);
        }
Ejemplo n.º 10
0
 private void AddFrame(Frame frame)
 {
     if (frames.Count == 10)
     {
         throw new ArgumentOutOfRangeException(nameof(frame),
             "Only 10 frames are allowed to be added into the board.");
     }
     if (frames.Count > 0)
     {
         frames.Last().Next = frame;
     }
     frames.Add(frame);
 }
Ejemplo n.º 11
0
        public void ThreeStrikesShouldScore30()
        {
            //given
            var frame1 = new Frame {FirstTry = 10, SecondTry = 0};
            var frame2 = new Frame {FirstTry = 10, SecondTry = 0};
            var frame3 = new Frame {FirstTry = 10, SecondTry = 0};
            frame1.Next = frame2;
            frame2.Next = frame3;

            //when
            var score1 = frame1.Score;

            //then
            Assert.AreEqual(30, score1);
        }
Ejemplo n.º 12
0
 public void SecondBallShouldNotBePlayedIfIsStrike()
 {
     var frame = new Frame {FirstTry = 10, SecondTry = 2};
     var score = frame.Score;
 }
Ejemplo n.º 13
0
Archivo: Game.cs Proyecto: Saulis/Katas
        public int GetNextRoll(Frame frame)
        {
            Frame nextFrame = GetNextFrame(frame);

            return nextFrame.FirstRoll;
        }
Ejemplo n.º 14
0
 private void Add(Frame frame)
 {
     _frames.Add(frame);
 }
Ejemplo n.º 15
0
 public BowlingKata()
 {
     _currentFrame = new Frame();
     _previousFrame = new Frame();
 }
Ejemplo n.º 16
0
Archivo: Game.cs Proyecto: Saulis/Katas
        private int GetFirstRollFromSecondFrame(Frame frame)
        {
            Frame secondFrame = GetNextFrame(GetNextFrame(frame));

            return secondFrame.FirstRoll;
        }
Ejemplo n.º 17
0
Archivo: Game.cs Proyecto: Saulis/Katas
 private Frame GetNextFrame(Frame frame)
 {
     return frames.Single(f => f.Number == frame.Number + 1);
 }
Ejemplo n.º 18
0
 //Replace current frame set with new frame set
 public void UpdateFrames(Frame[] _frames)
 {
     frames = _frames;
     Calculate();
 }
Ejemplo n.º 19
0
Archivo: Game.cs Proyecto: Saulis/Katas
        private bool NextFrameHasTwoRolls(Frame frame)
        {
            Frame nextFrame = GetNextFrame(frame);

            return nextFrame.RollsCount() >= 2;
        }
Ejemplo n.º 20
0
 public void Update(Frame f)
 {
     if ((this.IsSpare () && f.PinsRolled.Length == 1) || (f.PinsRolled.Length == 2 && this.IsStrike ())) {
         this.Score += f.PinsRolled.Last ();
     }
 }
Ejemplo n.º 21
0
 public void AddFrame(int firstTry, int secondTry)
 {
     var frame = new Frame {FirstTry = firstTry, SecondTry = secondTry};
     AddFrame(frame);
 }