コード例 #1
0
ファイル: Match.cs プロジェクト: oromand/tennis-scoring
        public void TeamScores(string teamScore)
        {
            if (!MatchStarted)
            {
                MatchStarted = true;
                StartTime    = new DateTime();
            }

            EventHandler <TeamScoredEvent> handler = TeamScoredHandler;
            TeamScoredEvent teamScoredEvent        = new TeamScoredEvent();

            switch (teamScore)
            {
            case "A":
                teamScoredEvent.Team = TeamA;
                break;

            case "B":
                teamScoredEvent.Team = TeamB;
                break;

            default: throw new Exception("Unknown team, should either be A or B");
            }
            if (handler != null)
            {
                handler(this, teamScoredEvent);
            }
        }
コード例 #2
0
ファイル: Score.cs プロジェクト: oromand/tennis-scoring
        public void OnTeamScored(object sender, TeamScoredEvent args)
        {
            Team teamScored = args.Team;

            if (teamScored is TeamA)
            {
                UpdateScore(ref scoreA, ref scoreB);
            }
            else if (teamScored is TeamB)
            {
                UpdateScore(ref scoreB, ref scoreA);
            }
            else
            {
                throw new Exception("Unknown team");
            }

            //trigger event here
            //team who scored is certainly winning here
            if (GameScore == GameA || GameScore == GameB)
            {
                this.Game.OnGameWon(teamScored);
                this.reinitScores();
            }
        }
コード例 #3
0
ファイル: Score.cs プロジェクト: oromand/tennis-scoring
        public void OnTeamScored(object sender, TeamScoredEvent e)
        {
            Team teamScored = e.Team;

            if (teamScored is TeamA)
            {
                UpdateScore(ref scoreA, ref scoreB);
            }
            else if (teamScored is TeamB)
            {
                UpdateScore(ref scoreB, ref scoreA);
            }

            if (TieScore == TieA || TieScore == TieB || (shouldContinue && Math.Abs(scoreA - scoreB) >= 2))
            {
                this.TieBreak.OnTieBreakWon(teamScored);
            }
        }
コード例 #4
0
ファイル: Set.cs プロジェクト: oromand/tennis-scoring
        //protected void OnTeamScoredGame(object sender, TeamScoredEvent args)
        //{
        //    this.CurrentGame.ScoreGame.OnTeamScored(sender, args);
        //}

        //protected void OnTeamScoredTieBreak(object sender, TeamScoredEvent args)
        //{
        //    this.TieBreak.ScoreTieBreak.OnTeamScored(sender, args);
        //}

        public void OnTeamScored(object sender, TeamScoredEvent args)
        {
            EventHandler <TeamScoredEvent> handler = TeamScoredHandler;

            if (handler != null)
            {
                TeamScoredEvent setEvent = new TeamScoredEvent()
                {
                    Team = args.Team,
                };
                //would be game or tie break depending of game advancement
                handler(this, setEvent);
            }
            //if (this.TieBreak == null)
            //{
            //    this.OnTeamScoredGame(sender, args);
            //}
            //else
            //{
            //    this.OnTeamScoredTieBreak(sender, args);
            //}
        }