IsStrike() приватный Метод

private IsStrike ( ) : bool
Результат bool
Пример #1
0
        public int CalculateScore(int[] rolls)
        {
            _rolls = rolls;

            var score = 0;

            for (var roll = 0; roll < _rolls.Length; roll += 2)
            {
                var frame = new Frame(rolls[roll], rolls[roll + 1]);

                var additionalScore = 0;

                if (frame.IsStrike() && !IsExtraRoll(roll + 2))
                {
                    additionalScore = FrameScore(roll, 2);

                    if (IsStrike(roll + 2) && !IsExtraRoll(roll + 2))
                    {
                        additionalScore += _rolls[roll + 4];
                    }
                }

                if (IsSpare(roll))
                {
                    additionalScore = _rolls[roll + 2];
                }

                score += FrameScore(roll) + additionalScore;
            }

            return(score);
        }
        public int Score(Frame frame, Frame nextFrame)
        {
            if (frame?.IsStrike() ?? false)
            {
                return(10 + Score(nextFrame));
            }

            if (frame?.IsSpare() ?? false)
            {
                return(10 + Score(nextFrame?.Tries.ElementAtOrDefault(0)));
            }

            return(Score(frame));
        }
Пример #3
0
        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++;
            }
        }