Example #1
0
 /// <summary>
 /// Returns a copy of a frame based on its index. If the index is not valid, the method returns NULL.
 /// The return value is a copy of the original object to ensure it is immutable.
 /// </summary>
 public BowlingFrame GetFrame(int index)
 {
     // Check if the given index is valid. If yes - return a copy of BowlingFrame, otherwise, return NULL.
     return((BowlingGameExtenstions.IsIndexExists(Frames, index)) ?
            new BowlingFrame(BowlingGameExtenstions.GetItemFromArray <BowlingFrame>(Frames, index)) :
            null);
 }
Example #2
0
        /// <summary>
        /// Returns the frame type, based on the requested index. If the requested index is invalid, the return value is Empty.
        /// This method is more efficient than calling GetFrame, as it avoids creation of a new BowlingFrame instance.
        /// </summary>
        public FrameTypeEnum GetFrameType(int index)
        {
            return(BowlingGameExtenstions.GetItemFromArray <BowlingFrame>(Frames, index)?.FrameType ?? FrameTypeEnum.Empty);

            /// This is the inefficient way to return the frame's type.
            //return (GetFrame(BowlingGameExtenstions.NUM_OF_REGULAR_ROUNDS - 1)?.FrameType) ?? FrameTypeEnum.Empty;
        }
Example #3
0
 /// <summary>
 /// Returns the score of a given frame if exists, otherwise return null.
 /// </summary>
 /// <param name="index"></param>
 /// <returns></returns>
 public int?GetFrameScore(int index)
 {
     return(BowlingGameExtenstions.GetItemFromArray <int?>(GetFramesScores(), index));
 }