Exemplo n.º 1
0
 private void FillItem(ListViewItem itm, Pitcher ptr)
 {
     itm.Text = ptr.Name;
     itm.SubItems.Add(ptr.SeasonStats.Wins.ToString());
     itm.SubItems.Add(ptr.SeasonStats.Losses.ToString());
     itm.SubItems.Add(ptr.SeasonStats.Saves.ToString());
     itm.SubItems.Add(ptr.SeasonStats.EarnedRunAvg.ToString("#0.00"));
 }
Exemplo n.º 2
0
        public ShowPitcherForm(Pitcher ptr)
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            pitcher = ptr;

            FillPlayerValues();
        }
Exemplo n.º 3
0
        public void SetPitcher()
        {
            int index = gamesPlayed % (rotation.Count);

            currentPitcher = rotation.ToArray()[index];
            currentPitcher.ResetGameStats();
            currentPitcher.PlayedThisGame = true;
        }
Exemplo n.º 4
0
        public Team(DataRow row)
        {
            DataTable table;
            Initialize();
            Batter btr;

            name = row["team_name"].ToString();
            abbrev = row["abbrev"].ToString();
            id = Int32.Parse(row["team_id"].ToString());

            table = DbUtils.GetDataTable(string.Format("select * from team_record where team_id = {0}", id));

            if (table.Rows.Count == 0)
            {
                gamesPlayed = wins = losses = 0;
            }
            else
            {
                wins = Int32.Parse(table.Rows[0]["wins"].ToString());
                losses = Int32.Parse(table.Rows[0]["losses"].ToString());
                gamesPlayed = wins + losses;
            }

            table = DbUtils.GetDataTable(string.Format("select * from team_players where team_id = {0}", id));

            if (table.Rows.Count != 0)
            {
                DataTable tablePlayer;
                foreach (DataRow playerRow in table.Rows)
                {

                    tablePlayer = DbUtils.GetDataTable(string.Format("select * from players where player_id = {0}",
                        Int32.Parse(playerRow["player_id"].ToString())));

                    if (tablePlayer.Rows.Count == 0)
                    {
                        continue;
                    }
                    else
                    {
                        bool isBatter = Boolean.Parse(tablePlayer.Rows[0]["batter"].ToString());

                        if (isBatter)
                        {
                            Batter batter = new Batter(tablePlayer.Rows[0]);
                            batterList.Add(batter);
                        }
                        else
                        {
                            Pitcher pitcher = new Pitcher(tablePlayer.Rows[0]);

                            pitcherList.Add(pitcher);
                            if (pitcher.PitcherRole == PitcherType.Starter)
                            {
                                StartingPitchers.Add(pitcher);
                            }
                            else
                            {
                                bullpen.Add(pitcher);
                            }
                        }
                    }
                }
            }

            // now build lineup
            table = DbUtils.GetDataTable(string.Format("select * from team_lineup where team_id = {0} order by lineup_order", id));
            foreach (DataRow lineupRow in table.Rows)
            {
                btr = GetBatterByID(Int32.Parse(lineupRow["player_id"].ToString()));
                if (btr != null)
                {
                    int lineupSlot = Int32.Parse(lineupRow["lineup_order"].ToString()) - 1;
                    battingOrder[lineupSlot] = new BattingOrderSlot();
                    battingOrder[lineupSlot].Hitter = btr;
                    battingOrder[lineupSlot].FieldingPosition = (Position) Int32.Parse(lineupRow["position"].ToString());
                }
            }
        }
Exemplo n.º 5
0
        public void RemovePitcher(Pitcher pitcher)
        {
            pitcherList.Remove(pitcher);

            if (pitcher.PitcherRole == PitcherType.Starter)
            {
                rotation.Remove(pitcher);
            }
            else
            {
                bullpen.Remove(pitcher);
            }
            pitchersModified = true;
        }
Exemplo n.º 6
0
 public void AddPitcher(Pitcher pitcher)
 {
     pitcherList.Add(pitcher);
     pitchersModified = true;
     if (pitcher.PitcherRole == PitcherType.Starter)
     {
         rotation.Add(pitcher);
     }
     else
     {
         bullpen.Add(pitcher);
     }
 }
Exemplo n.º 7
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;
            }
        }
Exemplo n.º 8
0
        private void HandleLeadChange(GameWinner prev, GameWinner curr)
        {
            // if the  status has changed and there was a pitcher in line for a save, he can't be anymore
            savePitcher = null;

            if (curr == GameWinner.TieScore)
            {
                winningPitcher = null;
                losingPitcher = null;
            }
            else if (curr == GameWinner.HomeTeam)
            {
                winningPitcher = homeTeam.CurrentPitcher;
                losingPitcher = visitingTeam.CurrentPitcher;
            }
            else
            {
                winningPitcher = visitingTeam.CurrentPitcher;
                losingPitcher = homeTeam.CurrentPitcher;
            }
        }
Exemplo n.º 9
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);
        }
Exemplo n.º 10
0
        private int DoAtBat(Pitcher pitcher, Batter batter)
        {
            int pitch = RollDie(20);
            int	swing = RollDie(20);
            int	onBase = batter.OnBase;
            int	control = pitcher.AdjustedControl;
            int	result;

            if (control + pitch > onBase)
                result = pitcher.GetResult(swing);
            else
                result = batter.GetResult(swing);

            return result;
        }
Exemplo n.º 11
0
        public void SwapCurrentPitcher(bool swapHomeTeam)
        {
            // update current pitcher for next at bat
            if (currentPitcher != fieldingTeam.CurrentPitcher)
            {
                currentPitcher = fieldingTeam.CurrentPitcher;
            }

            // evalaute save opportunity for new pitcher
            int scoreDiff = Math.Abs(score.VisitingScore - score.HomeScore);
            int runnersOnBase = CountRunnersOnBase();

            if (scoreDiff < 4 || scoreDiff < runnersOnBase + 3)
            {
                // could be a save now check for change matches winning team
                if (swapHomeTeam == true && score.WinningTeam == GameWinner.HomeTeam)
                {
                    savePitcher = homeTeam.CurrentPitcher;
                }
                else if (swapHomeTeam == false && score.WinningTeam == GameWinner.VisitingTeam)
                {
                    savePitcher = visitingTeam.CurrentPitcher;
                }
            }
        }
Exemplo n.º 12
0
        public void PlayBall()
        {
            gameInProgress = true;

            InitializeGameStats();

            homeTeam.ResetGameStats();
            visitingTeam.ResetGameStats();

            RaiseLineupUpdateEvent(LineupRoleType.Team, -1, TeamLocation.Home, homeTeam.Name);
            RaiseLineupUpdateEvent(LineupRoleType.Team, -1, TeamLocation.Visitor, visitingTeam.Name);

            for (int i = 0; i < 9; i++)
            {

                RaiseLineupUpdateEvent(LineupRoleType.Batter, i, TeamLocation.Home, homeTeam.GetBatterByLineup(i).LineUpText);
                RaiseLineupUpdateEvent(LineupRoleType.Batter, i, TeamLocation.Visitor, visitingTeam.GetBatterByLineup(i).LineUpText);

                homeTeam.GetBatterByLineup(i).PlayedThisGame = true;
                visitingTeam.GetBatterByLineup(i).PlayedThisGame = true;
            }

            visitingTeam.SetPitcher();
            RaiseLineupUpdateEvent(LineupRoleType.Pitcher, -1, TeamLocation.Visitor, visitingTeam.CurrentPitcher.Name);

            homeTeam.SetPitcher();
            RaiseLineupUpdateEvent(LineupRoleType.Pitcher, -1, TeamLocation.Home, homeTeam.CurrentPitcher.Name);

            // need to clear display here
            RaiseBaseRunnerUpdateEvent(Base.Home, "");
            RaiseBaseRunnerUpdateEvent(Base.First, "");
            RaiseBaseRunnerUpdateEvent(Base.Second, "");
            RaiseBaseRunnerUpdateEvent(Base.Third, "");

            RaiseLineScoreUpdateEvent(LineScoreUpdateType.Name, -1, -1, TeamLocation.Visitor, visitingTeam.Abbrev);
            RaiseLineScoreUpdateEvent(LineScoreUpdateType.CurrentScore, -1, 0, TeamLocation.Visitor, "");
            RaiseLineScoreUpdateEvent(LineScoreUpdateType.CurrentHits, -1, 0, TeamLocation.Visitor, "");
            RaiseLineScoreUpdateEvent(LineScoreUpdateType.CurrentErrors, -1, 0, TeamLocation.Visitor, "");
            RaiseLineScoreUpdateEvent(LineScoreUpdateType.InningScore, 1, 0, TeamLocation.Visitor, "");

            RaiseLineScoreUpdateEvent(LineScoreUpdateType.Name, -1, -1, TeamLocation.Home, homeTeam.Abbrev);
            RaiseLineScoreUpdateEvent(LineScoreUpdateType.CurrentScore, -1, 0, TeamLocation.Home, "");
            RaiseLineScoreUpdateEvent(LineScoreUpdateType.CurrentHits, -1, 0, TeamLocation.Home, "");
            RaiseLineScoreUpdateEvent(LineScoreUpdateType.CurrentErrors, -1, 0, TeamLocation.Home, "");

            currentPitcher = fieldingTeam.CurrentPitcher;
            currentHitter = battingTeam.GetBatterByLineup(atBatIndex[teamAtBat]);
            RaiseBaseRunnerUpdateEvent(Base.Home, currentHitter.Name);

            inningScores[VISITING_TEAM, 0] = 0;
        }
Exemplo n.º 13
0
        private void SelectVisitingTeam()
        {
            Pitcher pitcher;
            Batter batter;

            visitingTeam = new Team();

            // for now create players in code and add to roster
            pitcher = new Pitcher(5, 7, ThrowingSide.Right, 600, PitcherType.Starter,
                "00000111222223334557", "Kevin Brown");
            visitingTeam.AddPitcher(pitcher);

            pitcher = new Pitcher(4, 7, ThrowingSide.Right, 430, PitcherType.Starter,
                "11000002222223333455", "Jose Lima");
            visitingTeam.AddPitcher(pitcher);

            pitcher = new Pitcher(4, 7, ThrowingSide.Left, 330, PitcherType.Starter,
                "11100000222223334555", "Odalis Perez");
            visitingTeam.AddPitcher(pitcher);

            pitcher = new Pitcher(3, 6, ThrowingSide.Right, 270, PitcherType.Starter,
                "11000002222222334459", "Darren Dreifort");
            visitingTeam.AddPitcher(pitcher);

            batter = new Batter(BattingSide.SwitchHitter, 9, Position.SecondBase, 2, Position.None, 0, 15,
                320, "11224444445555567789", "Jose Offerman");
            visitingTeam.AddBatter(batter);

            batter = new Batter(BattingSide.LeftHanded, 9, Position.LeftRight, 1, Position.FirstBase, 0, 15,
                280, "00022444444555557779", "John Vander Wal");
            visitingTeam.AddBatter(batter);

            batter = new Batter(BattingSide.LeftHanded, 10, Position.FirstBase, 1, Position.None, 0, 10,
                360, "22234444444455557799", "John Olerud");
            visitingTeam.AddBatter(batter);

            batter = new Batter(BattingSide.RightHanded, 10, Position.LeftRight, 2, Position.None, 0, 10,
                490, "00444444555555777999", "Kevin Pulsifer");
            visitingTeam.AddBatter(batter);

            batter = new Batter(BattingSide.RightHanded, 10, Position.CenterField, 4, Position.None, 0, 20,
                490, "00444444555555777999", "David Pulsifer");
            visitingTeam.AddBatter(batter);

            batter = new Batter(BattingSide.LeftHanded, 9, Position.LeftRight, 1, Position.None, 0, 20,
                340, "00044444445555556799", "J.D. Drew");
            visitingTeam.AddBatter(batter);

            batter = new Batter(BattingSide.RightHanded, 9, Position.ThirdBase, 2, Position.None, 0, 15,
                320, "02223445555555557799", "Chris Stynes");
            visitingTeam.AddBatter(batter);

            batter = new Batter(BattingSide.LeftHanded, 9, Position.Catcher, 0, Position.None, 0, 10,
                180, "02234444444555555779", "Scott Hatteberg");
            visitingTeam.AddBatter(batter);

            batter = new Batter(BattingSide.RightHanded, 7, Position.Shortstop, 3, Position.None, 0, 15,
                230, "00244445555555567999", "Jose Hernandez");
            visitingTeam.AddBatter(batter);

            visitingTeamSelected = true;
            visitingTeam.Name = "Brooklyn Dodgers";
            visitingTeam.Abbrev = "BRK";

            visitingTeam.SetLineUp();

            visitingLineupSelected = true;

            RaiseLineScoreUpdateEvent(LineScoreUpdateType.Name, -1, -1, TeamLocation.Visitor, visitingTeam.Abbrev);
        }
Exemplo n.º 14
0
        private void SelectHomeTeam()
        {
            Pitcher pitcher;
            Batter batter;

            homeTeam = new Team();

            // for now create players in code and add to roster
            pitcher = new Pitcher(5, 7, ThrowingSide.Right, 550, PitcherType.Starter,
                "10000002222233333457", "Curt Schilling");
            homeTeam.AddPitcher(pitcher);

            pitcher = new Pitcher(4, 7, ThrowingSide.Right, 550, PitcherType.Starter,
                "11110000002222233335", "Derek Lowe");
            homeTeam.AddPitcher(pitcher);

            pitcher = new Pitcher(5, 6, ThrowingSide.Right, 440, PitcherType.Starter,
                "11100000222223333555", "Pedro Martinez");
            homeTeam.AddPitcher(pitcher);

            pitcher = new Pitcher(3, 6, ThrowingSide.Right, 250, PitcherType.Starter,
                "11110000222222334557", "Tim Wakefield");
            homeTeam.AddPitcher(pitcher);

            batter = new Batter(BattingSide.LeftHanded, 12, Position.CenterField, 0, Position.None, 0, 22,
                390, "00222344555555666679", "Jacoby Ellsbury");
            homeTeam.AddBatter(batter);

            batter = new Batter(BattingSide.RightHanded, 12, Position.Shortstop, 2, Position.None, 0, 17,
                590, "02223344555555677899", "Nomar Garciaparra");
            homeTeam.AddBatter(batter);

            batter = new Batter(BattingSide.LeftHanded, 14, Position.DesignatedHitter, 0, Position.None, 0, 10,
                540, "00223344444455557799", "David Ortiz");
            homeTeam.AddBatter(batter);

            batter = new Batter(BattingSide.RightHanded, 14, Position.LeftRight, 0, Position.None, 0, 10,
                610, "00233344444455557799", "Manny Ramirez");
            homeTeam.AddBatter(batter);

            batter = new Batter(BattingSide.RightHanded, 12, Position.FirstBase, 1, Position.None, 0, 15,
                270, "00223344444455555579", "Kevin Youkilis");
            homeTeam.AddBatter(batter);

            batter = new Batter(BattingSide.RightHanded, 11, Position.ThirdBase, 3, Position.None, 0, 12,
                230, "02233344455555555799", "Mike Lowell");
            homeTeam.AddBatter(batter);

            batter = new Batter(BattingSide.LeftHanded, 12, Position.LeftRight, 0, Position.None, 0, 12,
                340, "00023334444455557799", "Trot Nixon");
            homeTeam.AddBatter(batter);

            batter = new Batter(BattingSide.SwitchHitter, 12, Position.Catcher, 5, Position.None, 0, 15,
                360, "00223344445555566779", "Jason Varitek");
            homeTeam.AddBatter(batter);

            batter = new Batter(BattingSide.RightHanded, 11, Position.SecondBase, 3, Position.None, 0, 17,
                250, "02223344455555556779", "Dustin Pedroia");
            homeTeam.AddBatter(batter);

            homeTeamSelected = true;
            homeTeam.Name = "Boston Red Sox";
            homeTeam.Abbrev = "BOS";

            homeTeam.SetLineUp();

            homeLineupSelected = true;

            RaiseLineScoreUpdateEvent(LineScoreUpdateType.Name, -1, -1, TeamLocation.Home, homeTeam.Abbrev);
        }
Exemplo n.º 15
0
        private void AddAllPlayers(League lge)
        {
            DataTable tablePlayer;

            tablePlayer = DbUtils.GetDataTable(string.Format("select * from players"));

            if (tablePlayer.Rows.Count == 0)
            {
                return;
            }
            else
            {
                foreach (DataRow row in tablePlayer.Rows)
                {
                    bool isBatter = Boolean.Parse(row["batter"].ToString());

                    if (isBatter)
                    {
                        Batter batter = new Batter(row);
                        lge.AddPlayer(batter);
                    }
                    else
                    {
                        Pitcher pitcher = new Pitcher(row);
                        lge.AddPlayer(pitcher);
                    }
                }
            }

            return;
        }
Exemplo n.º 16
0
        private void AddAllPlayers2(League lge)
        {
            Dictionary<long, DataRow> batterStats = LoadDictionary("select * from batter_stats", "player_id");
            Dictionary<long, DataRow> batterSkill = LoadDictionary("select * from batting_skill", "player_id");
            Dictionary<long, DataRow> pitcherStats = LoadDictionary("select * from pitcher_stats", "player_id");
            Dictionary<long, DataRow> pitcherSkill = LoadDictionary("select * from pitcher_skill", "player_id");
            long id;
            DataTable tablePlayer;

            tablePlayer = DbUtils.GetDataTable(string.Format("select * from players"));

            if (tablePlayer.Rows.Count == 0)
            {
                return;
            }
            else
            {
                foreach (DataRow row in tablePlayer.Rows)
                {
                    id = long.Parse(row["player_id"].ToString());

                    bool isBatter = Boolean.Parse(row["batter"].ToString());

                    if (isBatter)
                    {
                        Batter batter = new Batter(row, batterStats[id], batterSkill[id]);
                        lge.AddPlayer(batter);
                    }
                    else
                    {
                        Pitcher pitcher = new Pitcher(row, pitcherStats[id], pitcherSkill[id]);
                        lge.AddPlayer(pitcher);
                    }
                }
            }

            return;
        }