Beispiel #1
0
        private void InitializeGameStats()
        {
            string result;
            battingTeam = visitingTeam;
            fieldingTeam = homeTeam;
            battingLocation = TeamLocation.Visitor;
            score.Reset();

            winningPitcher = null;
            losingPitcher = null;
            savePitcher = null;

            runnerOnFirst = null;
            runnerOnSecond = null;
            runnerOnThird = null;
            currentHitter = null;
            currentPitcher = null;

            outs = 0;
            RaiseLineScoreUpdateEvent(LineScoreUpdateType.Outs, -1, outs, battingLocation, "");
            inning = 1;
            RaiseLineScoreUpdateEvent(LineScoreUpdateType.Inning, inning, -1, battingLocation, "");
            RaiseInningChangeEvent(inning);
            teamAtBat = VISITING_TEAM;
            teamInField = HOME_TEAM;

            atBatIndex[VISITING_TEAM] = 0;
            atBatIndex[HOME_TEAM] = 0;
            runs[VISITING_TEAM] = 0;
            hits[VISITING_TEAM] = 0;
            errors[VISITING_TEAM] = 0;
            runs[HOME_TEAM] = 0;
            hits[HOME_TEAM] = 0;
            errors[HOME_TEAM] = 0;

            gameLog = new StringBuilder();
            result = string.Format("{0} {1}:\r\n\r\n", (teamAtBat == VISITING_TEAM) ? "TOP" : "BOTTOM",
                inning);
            gameLog.Append(result);

            for (int i = 0; i < 30; i++)
            {
                inningScores[HOME_TEAM, i] = inningScores[VISITING_TEAM, i] = -1;
            }
        }
Beispiel #2
0
        private string HandleTriple()
        {
            currentHitter.GameStats.Hits++;
            currentHitter.GameStats.Triples++;
            currentHitter.GameStats.AtBats++;
            hits[teamAtBat]++;

            RaiseLineScoreUpdateEvent(LineScoreUpdateType.CurrentHits, inning, hits[teamAtBat], battingLocation, "");

            if (runnerOnThird != null)
            {
                ScoreRunner((BaseRunner)runnerOnThird, true);
                runnerOnThird = null;
                RaiseBaseRunnerUpdateEvent(Base.Third, "");
            }

            if (runnerOnSecond != null)
            {
                ScoreRunner((BaseRunner)runnerOnSecond, true);
                runnerOnSecond = null;
                RaiseBaseRunnerUpdateEvent(Base.Second, "");
            }

            if (runnerOnFirst != null)
            {
                ScoreRunner((BaseRunner)runnerOnFirst, true);
                runnerOnFirst = null;
                RaiseBaseRunnerUpdateEvent(Base.First, "");
            }

            runnerOnThird = new BaseRunner();
            runnerOnThird.Hitter = currentHitter;
            runnerOnThird.PitcherFaced = currentPitcher;
            RaiseBaseRunnerUpdateEvent(Base.Third, currentHitter.Name);

            return (currentHitter.Name + " triples.\r\n");
        }
Beispiel #3
0
        private string HandleWalk()
        {
            currentPitcher.GameStats.Walks++;
            currentHitter.GameStats.Walks++;

            if (runnerOnFirst != null)
            {
                if (runnerOnSecond != null)
                {
                    if (runnerOnThird != null)
                    {
                        ScoreRunner((BaseRunner) runnerOnThird, true);
                        runnerOnThird = null;
                        RaiseBaseRunnerUpdateEvent(Base.Third, "");
                    }

                    runnerOnThird = runnerOnSecond;
                    RaiseBaseRunnerUpdateEvent(Base.Third, runnerOnThird.Hitter.Name);
                    runnerOnSecond = null;;
                    RaiseBaseRunnerUpdateEvent(Base.Second, "");
                }

                runnerOnSecond = runnerOnFirst;
                RaiseBaseRunnerUpdateEvent(Base.Second, runnerOnSecond.Hitter.Name);
                runnerOnFirst = null;
                RaiseBaseRunnerUpdateEvent(Base.First, "");
            }

            runnerOnFirst = new BaseRunner();
            runnerOnFirst.Hitter = currentHitter;
            runnerOnFirst.PitcherFaced = currentPitcher;
            RaiseBaseRunnerUpdateEvent(Base.First, runnerOnFirst.Hitter.Name);

            return (currentHitter.Name + " walks.\r\n");
        }
Beispiel #4
0
        private string HandleHomeRun()
        {
            currentHitter.GameStats.Hits++;
            currentHitter.GameStats.HomeRuns++;
            currentHitter.GameStats.AtBats++;
            hits[teamAtBat]++;
            RaiseLineScoreUpdateEvent(LineScoreUpdateType.CurrentHits, inning, hits[teamAtBat], battingLocation, "");

            if (runnerOnThird != null)
            {
                ScoreRunner((BaseRunner)runnerOnThird, true);
                runnerOnThird = null;
                RaiseBaseRunnerUpdateEvent(Base.Third, "");
            }

            if (runnerOnSecond != null)
            {
                ScoreRunner((BaseRunner)runnerOnSecond, true);
                runnerOnSecond = null;
                RaiseBaseRunnerUpdateEvent(Base.Second, "");
            }

            if (runnerOnFirst != null)
            {
                ScoreRunner((BaseRunner)runnerOnFirst, true);
                runnerOnFirst = null;
                RaiseBaseRunnerUpdateEvent(Base.First, "");
            }

            BaseRunner runner = new BaseRunner();
            runner.Hitter = currentHitter;
            runner.PitcherFaced = currentPitcher;

            ScoreRunner(runner, true);

            if (inning < 15)
            {
                inningHomeRuns[inning - 1]++;
            }

            return (currentHitter.Name + " homers.\r\n");
        }
Beispiel #5
0
        private string HandleSinglePlus()
        {
            string result;
            result = HandleSingle();

            if (runnerOnSecond == null)
            {
                runnerOnSecond = runnerOnFirst;
                ((Batter)runnerOnSecond.Hitter).GameStats.Steals++;
                RaiseBaseRunnerUpdateEvent(Base.Second, runnerOnSecond.Hitter.Name);

                runnerOnFirst = null;
                RaiseBaseRunnerUpdateEvent(Base.First, "");

                result += currentHitter.Name + " steals second.\r\n";
            }

            return result;
        }
Beispiel #6
0
        private void HandleHalfInningEnd()
        {
            string result;

            if (teamAtBat == HOME_TEAM)
            {
                inning++;
                RaiseLineScoreUpdateEvent(LineScoreUpdateType.Inning, inning, -1, battingLocation, "");
                RaiseInningChangeEvent(inning);
            }

            SwapTeams();

            runnerOnFirst = null;
            runnerOnSecond = null;
            runnerOnThird = null;
            RaiseBaseRunnerUpdateEvent(Base.First, "");
            RaiseBaseRunnerUpdateEvent(Base.Second, "");
            RaiseBaseRunnerUpdateEvent(Base.Third, "");

            outs = 0;
            RaiseLineScoreUpdateEvent(LineScoreUpdateType.Outs, -1, outs, battingLocation, "");
            inningScores[teamAtBat, inning - 1] = 0;
            RaiseLineScoreUpdateEvent(LineScoreUpdateType.InningScore, inning, 0, battingLocation, "");

            currentPitcher = fieldingTeam.CurrentPitcher;
            currentHitter = battingTeam.GetBatterByLineup(atBatIndex[teamAtBat]);

            result = string.Format("{0} {1}:\r\n\r\n", (teamAtBat == VISITING_TEAM) ? "TOP" : "BOTTOM",
                inning);
            gameLog.Append("\r\n=================================================\r\n" + result);
        }
Beispiel #7
0
        private string HandleGroundOut()
        {
            bool	doublePlay = false;
            int		rating = fieldingTeam.InfieldRating;

            StringBuilder sb = new StringBuilder();

            outs++;
            RaiseLineScoreUpdateEvent(LineScoreUpdateType.Outs, -1, outs, battingLocation, "");
            currentHitter.GameStats.AtBats++;
            currentPitcher.GameStats.Outs++;

            sb.Append(currentHitter.Name + " grounds out.\r\n");

            // check for runner on first double play
            if (outs < 3)
            {
                if (runnerOnFirst != null)
                {
                    if (rating + RollDie(20) > currentHitter.Speed)
                    {
                        outs++;
                        RaiseLineScoreUpdateEvent(LineScoreUpdateType.Outs, -1, outs, battingLocation, "");
                        doublePlay = true;
                        currentPitcher.GameStats.Outs++;

                        runnerOnFirst = null;
                        RaiseBaseRunnerUpdateEvent(Base.First, "");
                    }
                    else
                    {
                        BaseRunner runner = new BaseRunner();
                        runner.Hitter = currentHitter;
                        runner.PitcherFaced = currentPitcher;
                        runnerOnFirst = runner;
                        RaiseBaseRunnerUpdateEvent(Base.First, runnerOnFirst.Hitter.Name);
                    }
                }
            }

            if (outs < 3) // need to check again incase of double play
            {
                // if runner on third and < 3 outs then runner scores
                if (runnerOnThird != null)
                {
                    ScoreRunner((BaseRunner)runnerOnThird, !doublePlay);
                    runnerOnThird = null;
                    RaiseBaseRunnerUpdateEvent(Base.Third, "");
                }

                // if runner on second and < 3 outs runner advances
                if (runnerOnSecond != null)
                {
                    runnerOnThird = runnerOnSecond;
                    RaiseBaseRunnerUpdateEvent(Base.Third, runnerOnThird.Hitter.Name);
                    runnerOnSecond = null;
                    RaiseBaseRunnerUpdateEvent(Base.Second, "");
                }
            }

            if (doublePlay)
            {
                sb.Append("Double play.\r\n");
            }

            return sb.ToString();
        }
Beispiel #8
0
        private string HandleFlyOut()
        {
            StringBuilder sb = new StringBuilder();

            outs++;
            RaiseLineScoreUpdateEvent(LineScoreUpdateType.Outs, -1, outs, battingLocation, "");

            currentPitcher.GameStats.Outs++;

            currentHitter.GameStats.AtBats++;

            sb.Append(currentHitter.Name + " flies out.\r\n");

            if (runnerOnThird != null && outs < 3)
            {
                if (((Batter)runnerOnThird.Hitter).Speed >= SPEED_B)
                {
                    sb.Append(runnerOnThird.Hitter.Name + " scores from third.\r\n");
                    sb.Append(currentHitter.Name + " gets the RBI.\r\n");

                    ScoreRunner((BaseRunner)runnerOnThird, true);
                    runnerOnThird = null;
                    RaiseBaseRunnerUpdateEvent(Base.Third, "");

                    currentHitter.GameStats.AtBats--;
                    currentHitter.GameStats.SacFlies++;

                }
            }

            if (runnerOnThird == null && runnerOnSecond != null && outs < 3)
            {
                if (((Batter)runnerOnSecond.Hitter).Speed >= SPEED_A)
                {
                    sb.Append(runnerOnSecond.Hitter.Name + " advances to third.\r\n");
                    runnerOnThird = runnerOnSecond;
                    RaiseBaseRunnerUpdateEvent(Base.Third, runnerOnThird.Hitter.Name);
                    runnerOnSecond = null;
                    RaiseBaseRunnerUpdateEvent(Base.Second, "");
                }
            }

            return sb.ToString();
        }
Beispiel #9
0
        private string HandleDouble()
        {
            currentHitter.GameStats.Hits++;
            currentHitter.GameStats.Doubles++;
            currentHitter.GameStats.AtBats++;
            hits[teamAtBat]++;
            RaiseLineScoreUpdateEvent(LineScoreUpdateType.CurrentHits, inning, hits[teamAtBat], battingLocation, "");

            if (runnerOnThird != null)
            {
                ScoreRunner((BaseRunner)runnerOnThird, true);
                RaiseBaseRunnerUpdateEvent(Base.Third, "");
            }

            if (runnerOnSecond != null)
            {
                ScoreRunner((BaseRunner)runnerOnSecond, true);
                runnerOnSecond = null;
                RaiseBaseRunnerUpdateEvent(Base.Second, "");
            }

            if (runnerOnFirst != null)
            {
                if (outs == 2 && ((Batter)runnerOnFirst.Hitter).Speed == SPEED_A)
                {
                    ScoreRunner((BaseRunner)runnerOnFirst, true);
                    runnerOnFirst = null;
                    RaiseBaseRunnerUpdateEvent(Base.First, "");
                }
                else
                {
                    runnerOnThird = runnerOnFirst;
                    RaiseBaseRunnerUpdateEvent(Base.Third, runnerOnThird.Hitter.Name);
                    runnerOnFirst = null;
                    RaiseBaseRunnerUpdateEvent(Base.First, "");
                }

            }

            runnerOnSecond = new BaseRunner();
            runnerOnSecond.Hitter = currentHitter;
            runnerOnSecond.PitcherFaced = currentPitcher;

            RaiseBaseRunnerUpdateEvent(Base.Second, currentHitter.Name);

            return (currentHitter.Name + " doubles.\r\n");
        }
Beispiel #10
0
        private void ScoreRunner(BaseRunner runner, bool rbi)
        {
            runner.PitcherFaced.GameStats.Runs++;
            runner.PitcherFaced.GameStats.EarnedRuns++;

            runner.Hitter.GameStats.RunsScored++;

            runs[teamAtBat]++;

            if (battingLocation == TeamLocation.Home)
            {
                score.HomeScore++;
            }
            else
            {
                score.VisitingScore++;
            }

            inningScores[teamAtBat, inning - 1]++;

            RaiseLineScoreUpdateEvent(LineScoreUpdateType.CurrentScore, inning, runs[teamAtBat], battingLocation, "");
            RaiseLineScoreUpdateEvent(LineScoreUpdateType.InningScore, inning, inningScores[teamAtBat, inning - 1], battingLocation, "");

            gameLog.AppendFormat("{0} scores.\r\n", runner.Hitter.Name);

            if (rbi)
                currentHitter.GameStats.RBIs++;
        }