コード例 #1
0
ファイル: SinglePlayerLeg.cs プロジェクト: urfu-code/Darts
 public SinglePlayerLeg WithAdditionalThrow(ThrowResult throwResult)
 {
     if (Score == 0)
     {
         throw new InvalidOperationException("Leg is over");
     }
     return(new SinglePlayerLeg(InitialScore, AddThrowIntoTurns(throwResult)));
 }
コード例 #2
0
		private ImmutableList<Turn> AddThrowIntoTurns(ThrowResult result)
		{
			if (!Turns.Any() || Turns.Last().Finished)
				return Turns
					.Add(new Turn(Score).WithAdditionalThrow(result));
			return Turns
				.RemoveAt(Turns.Count - 1)
				.Add(Turns.Last().WithAdditionalThrow(result));
		}
コード例 #3
0
ファイル: Leg.cs プロジェクト: xoposhiy/design-course
		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;
		}
コード例 #4
0
ファイル: SinglePlayerLeg.cs プロジェクト: urfu-code/Darts
 private ImmutableList <Turn> AddThrowIntoTurns(ThrowResult result)
 {
     if (!Turns.Any() || Turns.Last().Finished)
     {
         return(Turns
                .Add(new Turn(Score).WithAdditionalThrow(result)));
     }
     return(Turns
            .RemoveAt(Turns.Count - 1)
            .Add(Turns.Last().WithAdditionalThrow(result)));
 }
コード例 #5
0
ファイル: Match.cs プロジェクト: urfu-code/Darts
 public void AddThrow(ThrowResult throwResult)
 {
     if (Finished)
     {
         throw new InvalidOperationException("Match is finished");
     }
     CurrentLeg.AddThrow(throwResult);
     if (CurrentLeg.Finished && Legs.Count < MaxLegsCount)
     {
         StartNewLeg();
     }
 }
コード例 #6
0
 public Turn WithAdditionalThrow(ThrowResult throwResult)
 {
     if (throwResult == null)
     {
         throw new ArgumentNullException("throwResult");
     }
     if (Finished)
     {
         throw new InvalidOperationException("Turn is over already.");
     }
     return(new Turn(ScoreBefore, Throws.Add(throwResult)));
 }
コード例 #7
0
ファイル: Leg.cs プロジェクト: urfu-code/Darts
 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;
     }
 }
コード例 #8
0
ファイル: ThrowResult.cs プロジェクト: xoposhiy/design-course
		protected bool Equals(ThrowResult other)
		{
			return Section == other.Section && SectionArea == other.SectionArea;
		}
コード例 #9
0
ファイル: Match.cs プロジェクト: xoposhiy/design-course
		public void AddThrow(ThrowResult throwResult)
		{
			if (Finished) throw new InvalidOperationException("Match is finished");
			CurrentLeg.AddThrow(throwResult);
			if (CurrentLeg.Finished && Legs.Count < MaxLegsCount) StartNewLeg();
		}
コード例 #10
0
		public SinglePlayerLeg WithAdditionalThrow(ThrowResult throwResult)
		{
			if (Score == 0) throw new InvalidOperationException("Leg is over");
			return new SinglePlayerLeg(InitialScore, AddThrowIntoTurns(throwResult));
		}
コード例 #11
0
ファイル: ThrowResult.cs プロジェクト: urfu-code/Darts
 protected bool Equals(ThrowResult other)
 {
     return(Section == other.Section && SectionArea == other.SectionArea);
 }
コード例 #12
0
ファイル: Turn.cs プロジェクト: xoposhiy/design-course
		public Turn WithAdditionalThrow(ThrowResult throwResult)
		{
			if (throwResult == null) throw new ArgumentNullException("throwResult");
			if (Finished) throw new InvalidOperationException("Turn is over already.");
			return new Turn(ScoreBefore, Throws.Add(throwResult));
		}