public void Handle(MatchUnit source, MatchUnitFinishedEvent e) { MatchTeam team = this.MatchTeams.Where(t => t.Player == e.WinningTeam.Player).FirstOrDefault(); if (team != null) { this.AddScore(team); } }
public virtual void Handle(Player source, FailedHitEvent e) { MatchTeam otherTeam = this.MatchTeams.Where(t => t.Player != source).FirstOrDefault(); if (otherTeam != null) { this.AddScore(otherTeam); } }
public override void AddScore(MatchTeam team) { team.Score += 1; if (team.Score == this.WinScore) { DI.Resolver.Resolve <IEventDispatcher>().Dispatch(this, new MatchUnitFinishedEvent(team)); DI.Resolver.Resolve <IEventDispatcher>().CleanupSource(this); } else { this.Play(); } }
public override void AddScore(MatchTeam team) { MatchTeam otherTeam = this.MatchTeams.Where(t => t != team).FirstOrDefault(); team.Score += 1; if (this.IsWin(team, otherTeam)) { DI.Resolver.Resolve <IEventDispatcher>().Dispatch(this, new MatchUnitFinishedEvent(team)); DI.Resolver.Resolve <IEventDispatcher>().CleanupSource(this); } else { this.Play(); } }
public override void AddScore(MatchTeam team) { MatchTeam otherTeam = this.MatchTeams.Where(t => t != team).FirstOrDefault(); if (team.Score == 0) { team.Score = 15; } else if (team.Score == 15) { team.Score = 30; } else if (team.Score == 30) { team.Score = 40; } else if (team.Score == 40) { if (otherTeam.Score < 40) { team.Score = 42; // remove handlers foreach (MatchTeam t in this.MatchTeams) { DI.Resolver.Resolve <IEventDispatcher>().RemoveHandler <Player, BallHittedEvent>(t.Player, this); DI.Resolver.Resolve <IEventDispatcher>().RemoveHandler <Player, FailedHitEvent>(t.Player, this); } DI.Resolver.Resolve <IEventDispatcher>().Dispatch(this, new MatchUnitFinishedEvent(team)); DI.Resolver.Resolve <IEventDispatcher>().CleanupSource(this); return; } else if (otherTeam.Score == 40) { team.Score = 41; } else { team.Score = 40; otherTeam.Score = 40; } } this.Play(); }
public override MatchTeam GetWinTeam() { MatchTeam team = this.MatchTeams[0]; MatchTeam otherTeam = this.MatchTeams[0]; if (team.Score < this.MatchTeams[1].Score) { team = this.MatchTeams[1]; otherTeam = this.MatchTeams[0]; } if (team != null && otherTeam != null && ((team.Score == 6 && team.Score - otherTeam.Score >= 2) || team.Score == 7)) { return(team); } return(null); }
public abstract void AddScore(MatchTeam team);
private bool IsWin(MatchTeam team, MatchTeam otherTeam) { return((team.Score == 6 && team.Score - otherTeam.Score >= 2) || team.Score == 7); }
public MatchUnitFinishedEvent(MatchTeam winningTeam) { this.WinningTeam = winningTeam; }