Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 2
0
        public virtual void Handle(Player source, FailedHitEvent e)
        {
            MatchTeam otherTeam = this.MatchTeams.Where(t => t.Player != source).FirstOrDefault();

            if (otherTeam != null)
            {
                this.AddScore(otherTeam);
            }
        }
Exemplo n.º 3
0
 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();
     }
 }
Exemplo n.º 4
0
        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();
            }
        }
Exemplo n.º 5
0
        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();
        }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
0
 public abstract void AddScore(MatchTeam team);
Exemplo n.º 8
0
 private bool IsWin(MatchTeam team, MatchTeam otherTeam)
 {
     return((team.Score == 6 && team.Score - otherTeam.Score >= 2) || team.Score == 7);
 }
Exemplo n.º 9
0
 public MatchUnitFinishedEvent(MatchTeam winningTeam)
 {
     this.WinningTeam = winningTeam;
 }