Beispiel #1
0
 private void FillItem(ListViewItem itm, Batter btr)
 {
     itm.Text = btr.Name;
     itm.SubItems.Add(btr.PrimaryPosition.ToString());
     itm.SubItems.Add(btr.SeasonStats.BattingAvg.ToString("0.000"));
     itm.SubItems.Add(btr.SeasonStats.SluggingPct.ToString("0.000"));
 }
        public ShowBatterForm(Batter btr)
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            batter = btr;

            FillPlayerValues();
        }
 private void AddToBatterList(Batter btr)
 {
     ListViewItem lvi = new ListViewItem(btr.Name);
     string posString = EnumHelpers.PositionToString(btr.PrimaryPosition);
     if (btr.SecondaryPosition != Position.None)
     {
         posString += ", " + EnumHelpers.PositionToString(btr.SecondaryPosition);
     }
     lvi.SubItems.Add(posString);
     lvi.Tag = btr;
     battersListView.Items.Add(lvi);
 }
Beispiel #4
0
 public void RemoveFromLineup(Batter btr)
 {
     for (int i = 0; i < 9; i++)
     {
         if (battingOrder[i].Hitter == btr)
         {
             battingOrder[i] = null;
             lineupModified = true;
         }
     }
 }
Beispiel #5
0
 public void RemoveBatter(Batter batter)
 {
     batterList.Remove(batter);
     RemoveFromLineup(batter);
     battersModified = true;
 }
Beispiel #6
0
 public void AddBatter(Batter batter)
 {
     batterList.Add(batter);
     battersModified = true;
 }
Beispiel #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;
            }
        }
Beispiel #8
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 #9
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;
        }
Beispiel #10
0
        public void NextAtBat()
        {
            int			atBatResult;
            string		result;
            GameWinner  previousWinner;
            GameWinner  currentWinner;

            previousWinner = score.WinningTeam;

            atBatResult = DoAtBat(currentPitcher, currentHitter);

            switch (atBatResult)
            {
                case RESULT_GROUNDOUT:
                    result = HandleGroundOut();
                    break;

                case RESULT_STRIKEOUT:
                    result = HandleStrikeOut();
                    break;

                case RESULT_POPUP:
                    result = HandlePopUp();
                    break;

                case RESULT_FLYOUT:
                    result = HandleFlyOut();
                    break;

                case RESULT_WALK:
                    result = HandleWalk();
                    break;

                case RESULT_SINGLE:
                    result = HandleSingle();
                    break;

                case RESULT_SINGLEPLUS:
                    result = HandleSinglePlus();
                    break;

                case RESULT_DOUBLE:
                    result = HandleDouble();
                    break;

                case RESULT_TRIPLE:
                    result = HandleTriple();
                    break;

                case RESULT_HOMERUN:
                    result = HandleHomeRun();
                    break;

                default:
                    result = "";
                    break;

            }

            RaiseAtBatResultUpdateEvent(result);

            gameLog.Append(result);

            //  new batter and other values to setup for next atbat

            currentWinner = score.WinningTeam;

            if (currentWinner != previousWinner)
            {
                HandleLeadChange(previousWinner, currentWinner);
            }

            if (GameIsComplete == true)
            {
                HandleEndGame();
            }
            else
            {
                atBatIndex[teamAtBat] = IncrementAtBatIndex(atBatIndex[teamAtBat]);

                if (outs > 2)
                {
                    HandleHalfInningEnd();
                }

                currentHitter = battingTeam.GetBatterByLineup(atBatIndex[teamAtBat]);
                RaiseBaseRunnerUpdateEvent(Base.Home, currentHitter.Name);
            }
        }
Beispiel #11
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);
        }
Beispiel #12
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);
        }
Beispiel #13
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;
        }
Beispiel #14
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;
        }
Beispiel #15
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());
                }
            }
        }
Beispiel #16
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;
        }
 private void RemoveFromBatterList(Batter btr)
 {
     foreach (ListViewItem lvi in battersListView.Items)
     {
         if (lvi.Tag == btr)
         {
             battersListView.Items.Remove(lvi);
             break;
         }
     }
 }