public void PlayMatch()
		{
			var leg = new SinglePlayerLeg(126)

				// Turn #1
				.WithAdditionalThrow(ThrowResult.Triple(20))
				.WithAdditionalThrow(ThrowResult.Double(20))
				.WithAdditionalThrow(ThrowResult.Single(20))
				// Score = 6

				// Turn #2
				.WithAdditionalThrow(ThrowResult.Outside)
				.WithAdditionalThrow(ThrowResult.Outside)
				.WithAdditionalThrow(ThrowResult.Outside)

				// Turn #3. Bust! Not double!
				.WithAdditionalThrow(ThrowResult.Triple(2))

				// Turn #4. Bust! Too many!
				.WithAdditionalThrow(ThrowResult.InnerBull)

				// Turn #5. Bust! Can't leave 1.
				.WithAdditionalThrow(ThrowResult.Single(5))

				// Turn #6. Finished
				.WithAdditionalThrow(ThrowResult.Double(3));

			Assert.AreEqual(6, leg.Turns.Count);
			Assert.AreEqual(0, leg.Score);
		}
Beispiel #2
0
		public void DoNotAddScore_IfBust()
		{
			var leg = new SinglePlayerLeg(10)

				.WithAdditionalThrow(new ThrowResult(1, SectionArea.Single))
				.WithAdditionalThrow(new ThrowResult(1, SectionArea.Single))
				.WithAdditionalThrow(new ThrowResult(7, SectionArea.Single));

			Assert.AreEqual(10, leg.Score);
		}
Beispiel #3
0
		public void AddTurnScore_IfNotBust()
		{
			var leg = new SinglePlayerLeg(103)

				.WithAdditionalThrow(new ThrowResult(1, SectionArea.Single))
				.WithAdditionalThrow(new ThrowResult(1, SectionArea.Single))
				.WithAdditionalThrow(new ThrowResult(1, SectionArea.Single));

			Assert.AreEqual(100, leg.Score);
		}
Beispiel #4
0
		public void AddThrow(ThrowResult throwResult)
		{
			if (Finished) throw new InvalidOperationException("Leg is finished");
			CurrentPlayer = CurrentPlayer.WithAdditionalThrow(throwResult);
			if (!CurrentPlayer.Turns.Last().Finished) return;
			if (CurrentPlayer.Score == 0)
				WinnerIndex = CurrentPlayerIndex;
			else
				CurrentPlayerIndex = (CurrentPlayerIndex + 1) % 2;
		}
Beispiel #5
0
		public void StartNewTurnAfterBust()
		{
			var leg = new SinglePlayerLeg(10)
			
				.WithAdditionalThrow(ThrowResult.InnerBull)
				.WithAdditionalThrow(ThrowResult.Outside);

			Assert.AreEqual(2, leg.Turns.Count);
			CollectionAssert.AreEqual(new[] { ThrowResult.InnerBull }, leg.Turns[0].Throws);
			CollectionAssert.AreEqual(new[] { ThrowResult.Outside }, leg.Turns[1].Throws);
		}
Beispiel #6
0
		public Leg(string id, int initialScore)
		{
			if (id == null) throw new ArgumentNullException("id");
			if (initialScore <= 0) throw new ArgumentOutOfRangeException("initialScore");
			Id = id;
			InitialScore = initialScore;
			var emptyLeg = new SinglePlayerLeg(initialScore);
			players = new List<SinglePlayerLeg> { emptyLeg, emptyLeg };
			WinnerIndex = -1;
			CurrentPlayerIndex = 0;
		}
Beispiel #7
0
		public void SplitThrowsByTurns()
		{
			var leg = new SinglePlayerLeg(301)

				.WithAdditionalThrow(ThrowResult.InnerBull)
				.WithAdditionalThrow(ThrowResult.InnerBull)
				.WithAdditionalThrow(ThrowResult.InnerBull)
				.WithAdditionalThrow(ThrowResult.Outside);

			Assert.AreEqual(2, leg.Turns.Count);
			CollectionAssert.AreEqual(new[] { ThrowResult.Outside }, leg.Turns.Last().Throws);
		}
Beispiel #8
0
        public Leg(string id, int initialScore)
        {
            if (id == null)
            {
                throw new ArgumentNullException("id");
            }
            if (initialScore <= 0)
            {
                throw new ArgumentOutOfRangeException("initialScore");
            }
            Id           = id;
            InitialScore = initialScore;
            var emptyLeg = new SinglePlayerLeg(initialScore);

            players = new List <SinglePlayerLeg> {
                emptyLeg, emptyLeg
            };
            WinnerIndex        = -1;
            CurrentPlayerIndex = 0;
        }
Beispiel #9
0
 public void AddThrow(ThrowResult throwResult)
 {
     if (Finished)
     {
         throw new InvalidOperationException("Leg is finished");
     }
     CurrentPlayer = CurrentPlayer.WithAdditionalThrow(throwResult);
     if (!CurrentPlayer.Turns.Last().Finished)
     {
         return;
     }
     if (CurrentPlayer.Score == 0)
     {
         WinnerIndex = CurrentPlayerIndex;
     }
     else
     {
         CurrentPlayerIndex = (CurrentPlayerIndex + 1) % 2;
     }
 }
Beispiel #10
0
 protected bool Equals(SinglePlayerLeg other)
 {
     return(Turns.SequenceEqual(other.Turns) && InitialScore == other.InitialScore);
 }
		protected bool Equals(SinglePlayerLeg other)
		{
			return Turns.SequenceEqual(other.Turns) && InitialScore == other.InitialScore;
		}