Exemplo n.º 1
0
        public bool Roll(int roll)
        {
            Rolls.Add(roll);

            Score += roll;

            if (IsStrike || IsSpare)
            {
                if (IsLast && Rolls.Count() == MaxRollsPerFrame)
                {
                    return(false);
                }
            }

            if (Previous != null)
            {
                if (Previous.IsSpare && Rolls.Count == 1)
                {
                    Previous.AddSpareScore(roll);
                }
                else if (Previous.IsStrike)
                {
                    Previous.AddSpareScore(roll);
                }

                var prePrevious = Previous.Previous;

                if (!IsLast && prePrevious != null && prePrevious.IsStrike)
                {
                    prePrevious.AddSpareScore(roll);
                }
            }

            return(!IsStrike && !IsLast && Rolls.Count < 2);
        }
Exemplo n.º 2
0
        public Frame Roll(uint pins)
        {
            if (IsFull)
            {
                if (NextFrame != null)
                {
                    return(NextFrame.Roll(pins));
                }

                return(null);
            }

            if (!IsValidRoll(pins))
            {
                throw new InvalidRollException($"Invalid roll > {MaxValidRoll}");
            }

            var roll = new Roll(pins);

            Rolls.Add(roll);

            if (IsFull)
            {
                return(NextFrame);
            }

            return(this);
        }
Exemplo n.º 3
0
        public virtual void Roll(int pins)
        {
            if (pins < 0 || pins > NumPins)
            {
                throw new Exception("Can only roll 0-10 pins");
            }

            var roll = new Roll(pins);

            Rolls.Add(roll);
            roll.IsSpare = IsSpare();
        }
Exemplo n.º 4
0
        public void Roll(Dice dice, IDiceRoller diceRoller)
        {
            _rolled = true;

            for (int i = 0; i < dice.Number; i++)
            {
                Rolls.Add(diceRoller.Roll(dice.Type));
                Total += Rolls[i];
            }

            Total += dice.Modifier;
            WriteRollString(dice);
        }
Exemplo n.º 5
0
 public void Roll(int noOfPins)
 {
     if (!IsComplete)
     {
         Rolls.Add(noOfPins);
         if (Score != 10)
         {
             return;
         }
         if (Rolls.Count == 1)
         {
             IsStrike = true;
         }
         else
         {
             IsSpare = true;
         }
     }
     else
     {
         throw new Exception("Set is complete, cannot throw anymore");
     }
 }
Exemplo n.º 6
0
 public void RollAndUpdatePosition()
 {
     if (!Imprisoned)
     {
         var roll = new DiceRoll(_random).Roll();
         Rolls.Add(roll);
         if (LastThreeRollsWereDoubles())
         {
             Imprison();
         }
         else
         {
             MoveForward(roll.TotalValue());
         }
     }
     else if (Imprisoned)
     {
         RollInPrison();
         if (ShouldBeReleasedFromPrison())
         {
             ReleaseFromPrison();
         }
     }
 }