Beispiel #1
0
        public static Frame Create(
            Ball ball1,
            Ball ball2)
        {
            if (ball1 == null)
            {
                throw new ArgumentNullException(nameof(ball1));
            }
            if (ball2 == null)
            {
                throw new ArgumentNullException(nameof(ball2));
            }

            if (ball1.IsSpare || ball1.IsStrike || ball2.IsSpare || ball2.IsStrike)
            {
                throw new ArgumentException("Not spare or strike frame cannot be composed of spare or strike balls");
            }
            if (ball1.PinsKnockedDown + ball2.PinsKnockedDown > 9)
            {
                throw new ArgumentException("Not spare or strike frame must knock 9 pins at most");
            }

            return new Frame
            {
                Ball1 = ball1,
                Ball2 = ball2,
            };
        }
Beispiel #2
0
        public static Frame CreateSpare(
            Ball ball1)
        {
            if (ball1 == null)
            {
                throw new ArgumentNullException(nameof(ball1));
            }

            if (ball1.IsSpare || ball1.IsStrike)
            {
                throw new ArgumentException("First ball in spare frame cannot be spare or strike ball");
            }

            return new Frame
            {
                Ball1 = ball1,
                Ball2 = Ball.CreateSpare(10 - ball1.PinsKnockedDown),
            };
        }