예제 #1
0
 /// <summary>
 /// This method rolls the next ball and updates the score and score type (open frame, strike, spare) for the current frame
 /// </summary>
 /// <param name="pins"></param>
 public void Roll(int pins)
 {
     try
     {
         //check if any frames are added already or this is the first roll
         if (CurrentFrame == null)
         {
             AddNewFrame(pins, null);
         }
         else
         {
             //check if the current frame does have any more rolls else add a new frame and the new roll to it
             if (CanAddRoll)
             {
                 CurrentFrame.AddRoll(CreateRoll(pins));
                 UpdateFrameScoreType(CurrentFrame);
             }
             else
             {
                 AddNewFrame(pins, CurrentFrame);
             }
         }
     }
     catch (ArgumentOutOfRangeException arg)
     {
         throw arg;
     }
     catch (Exception ex)
     {
         throw new Exception("An error occurred while trying to execute Roll.");
     }
 }
예제 #2
0
        /// <summary>
        /// This is a common method to add a new frame, associate the next frame of the previous frame to the new frame being added as well as adds the first
        /// roll to the frame and updates the score type
        /// </summary>
        /// <param name="pins"></param>
        /// <param name="prevFrame"></param>
        private void AddNewFrame(int pins, Frame prevFrame)
        {
            try
            {
                Roll roll = CreateRoll(pins);

                Frame frame = CreateFrame(prevFrame);
                frame.AddRoll(roll);
                UpdateFrameScoreType(frame);
                Frames.Add(frame);
            }
            catch
            {
                throw;
            }
        }