public void Roll(int pins) { if (_isComplete) { throw new Exception("Game is complete, no more roll is allowed"); } _current.Roll(pins); _previous?.CheckApplyBonus(pins); _beforePrevious?.CheckApplyBonus(pins); if (!_current.IsComplete) { return; } if (_isFinal && _current.CheckGrantExtraRoll()) { return; } _beforePrevious = _previous; _previous = _current; _isComplete = _isFinal; if (_isComplete) { return; } _current = _frames[++_currentIndex]; _isFinal = _currentIndex == MAX_FRAMES - 1; }
public void AddRoll(int pins) { Frame f = (History.Count < this.Round) ? new Frame() : History.Pop(); f.Roll(pins); if (History.Count > 0) { History.Peek().Update(f); } History.Push(f); if (History.Count < 10) { if (f.PinsRolled.Length == 2 || f.IsStrike()) { this.Round++; } } else if (f.PinsRolled.Length == 3 || (f.PinsRolled.Length == 2 && !f.IsSpare())) { this.Round++; } }