Ejemplo n.º 1
0
    /// <summary>
    /// Conduct behaviours when a batter hit a ball in a common way.
    /// </summary>
    /// <param name="hit"></param>
    public static void AddHit(Hit hit, bool isITPHR = false)
    {
        //Clears count.
        AtPlate.ClearCount();

        if (InGameManager.isBottom)
        {
            InGameManager.game.homeScoreBoard.H++;
        }
        else
        {
            InGameManager.game.awayScoreBoard.H++;
        }

        //Add AB by 1.
        InGameManager.currentBatter.stats.SetStat(1, PlayerStatistics.PS.AB);
        InGameManager.currentBatter.stats.SetStat(1, PlayerStatistics.PS.H_BAT);

        if (hit == Hit.SINGLE)
        {
            currentBatter.stats.SetStat(1, PlayerStatistics.PS.SIN);
            BaseRunning.AdvanceRunner(1);
            Debug.Log("SINGLE");
        }
        else if (hit == Hit.DOUBLE)
        {
            currentBatter.stats.SetStat(1, PlayerStatistics.PS.DBL);
            BaseRunning.AdvanceRunner(2);
            Debug.Log("DOUBLE");
        }
        else if (hit == Hit.TRIPLE)
        {
            currentBatter.stats.SetStat(1, PlayerStatistics.PS.TRP);
            BaseRunning.AdvanceRunner(3);
            Debug.Log("TRIPLE");
        }
        else if (hit == Hit.HOME_RUN)
        {
            currentBatter.stats.SetStat(1, PlayerStatistics.PS.HR_BAT);
            if (isITPHR)
            {
                currentBatter.stats.SetStat(1, PlayerStatistics.PS.ITPHR);
            }
            BaseRunning.AdvanceRunner(4);
            Debug.Log("HOME RUN");
        }

        //If inning is over 9 and walked off, finishes game.
        if (InGameManager.currentInning > 9 && InGameManager.isBottom && InGameManager.game.homeScoreBoard.R > InGameManager.game.awayScoreBoard.R)
        {
            Innings.EndGame();
        }
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Initializes a game.
    /// </summary>
    public static void InitializeGame(bool isUIEnable = true)
    {
        //Toggles UI on or off.
        isUIEnabled = isUIEnable;

        //Resets isPaused value to false.
        isPaused = false;

        //Resets isGameEnd value to false.
        isGameEnd = false;

        //Sets the inning.
        currentInning = 1;
        isBottom      = false;
        currentAttack = game.away;
        currentDefend = game.home;

        //Sets batting orders.
        homeBattingOrder        = game.home.battingOrder.d;
        homeCurrentBattersIndex = 0;
        awayBattingOrder        = game.away.battingOrder.d;
        awayCurrentBattersIndex = 0;

        //Sets a pitcher.
        currentPitcher = game.homeStarterPitcher;
        otherPitcher   = game.awayStarterPitcher;
        strikeCount    = 0;
        ballCount      = 0;
        outCount       = 0;

        //Initializes batter and pitcher set.
        game.homeBatterSet  = new HashSet <Batter>();
        game.awayBatterSet  = new HashSet <Batter>();
        game.homePitcherSet = new HashSet <Pitcher>();
        game.awayPitcherSet = new HashSet <Pitcher>();

        //Sets pitcher set.
        game.homePitcherSet.Add(currentPitcher);
        game.awayPitcherSet.Add(otherPitcher);

        //Brings the batter to plate.
        AtPlate.AdvanceBatterToPlate();
    }
Ejemplo n.º 3
0
    /// <summary>
    /// Conducts field play.
    /// </summary>
    /// <param name="isRandom"></param>
    public void FieldPlay(bool isRandom = true)
    {
        if (isRandom)
        {
            float random = UnityEngine.Random.Range(0f, 10f);

            //FlyOut
            if (0 <= random && random <= 3.5f)
            {
                AtPlate.AddOut(AtPlate.Out.FLY_BALL);
            }
            //GroundBall
            else if (3.5f <= random && random <= 7f)
            {
                AtPlate.AddOut(AtPlate.Out.GROUND_BALL);
            }
            //Hit
            else if (7f <= random && random <= 10f)
            {
                random = UnityEngine.Random.Range(0, 10);
                if (0 <= random && random <= 4)
                {
                    Hitting.AddHit(Hitting.Hit.SINGLE);
                }
                else if (5 <= random && random <= 7)
                {
                    Hitting.AddHit(Hitting.Hit.DOUBLE);
                }
                else if (8 <= random && random <= 8)
                {
                    Hitting.AddHit(Hitting.Hit.TRIPLE);
                }
                else if (9 <= random && random <= 9)
                {
                    Hitting.AddHit(Hitting.Hit.HOME_RUN);
                }
            }
        }
    }
Ejemplo n.º 4
0
    /// <summary>
    /// Advances inning.
    /// </summary>
    public static void AdvanceInning()
    {
        //Innings pitched
        InGameManager.currentPitcher.stats.SetStat(0.7f, PlayerStatistics.PS.IP);

        //If the game satisfies the end condition, end game.
        if ((InGameManager.game.homeScoreBoard.R != InGameManager.game.awayScoreBoard.R) &&
            InGameManager.currentInning >= 9 && (InGameManager.isBottom || InGameManager.game.homeScoreBoard.R > InGameManager.game.awayScoreBoard.R))
        {
            EndGame();
            return;
        }

        if (InGameManager.isUIEnabled)
        {
            //BoardPanel UI.
            InGameObjects InGameObjects = GameObject.Find("InGameManager").GetComponent <InGameObjects>();
            InGameObjects.boardPanel.AddScorePanel();
        }

        //Switch side.
        Pitcher tempPitcher = InGameManager.currentPitcher;

        InGameManager.currentPitcher = InGameManager.otherPitcher;
        InGameManager.otherPitcher   = tempPitcher;

        if (InGameManager.currentAttack == InGameManager.game.home)
        {
            InGameManager.currentAttack = InGameManager.game.away;
            InGameManager.currentDefend = InGameManager.game.home;

            InGameManager.currentBatter = InGameManager.awayBattingOrder[InGameManager.awayCurrentBattersIndex];
        }
        else if (InGameManager.currentAttack == InGameManager.game.away)
        {
            InGameManager.currentAttack = InGameManager.game.home;
            InGameManager.currentDefend = InGameManager.game.away;

            InGameManager.currentBatter = InGameManager.homeBattingOrder[InGameManager.homeCurrentBattersIndex];
        }
        else
        {
            throw new System.NullReferenceException("Error: There is no appropriate team matching. Check currentAttack and Game instance again.");
        }

        if (InGameManager.isBottom)
        {
            InGameManager.isBottom = false;
            InGameManager.currentInning++;
        }
        else
        {
            InGameManager.isBottom = true;
        }

        for (int i = 0; i < 4; ++i)
        {
            InGameManager.runnerInBases[i] = null;
        }

        InGameManager.outCount = 0;
        AtPlate.ClearCount();

        //UI
        if (InGameManager.isUIEnabled)
        {
            InGameObjects InGameObjects = GameObject.Find("InGameManager").GetComponent <InGameObjects>();
            InGameObjects.PlayerUIApply.SetPlayers();
        }
    }
Ejemplo n.º 5
0
    /// <summary>
    /// A single turn.
    /// </summary>
    public void Turn()
    {
        if (isUIEnabled)
        {
            //InningPanel
            InGameObjects.inningPanel.UpdateLayout();

            //OutPanel
            InGameObjects.outPanelLayout.ClearLayout();
            InGameObjects.outPanelLayout.UpdateLayout();

            //BasePanel
            InGameObjects.basePanel.UpdateLayout();
            InGameObjects.basePanel.UpdateStealing();

            //ScorePanel
            InGameObjects.scorePanel.UpdateLayout();

            //BoardPanel
            InGameObjects.boardPanel.UpdateLayout();

            //Field_Condition
            InGameObjects.PlayerUIApply.SetPlayers(true);
        }

        //Initializes stealingAttempts array to false.
        for (int i = 0; i < 4; ++i)
        {
            stealingAttempts[i] = false;
        }
        //First, determine whether runners in bases attempt to steal base or not.
        for (int i = 1; i <= 3; ++i)
        {
            bool isBaseStealing = BaseRunning.BaseStealDetermine(runnerInBases[i], true);
            if (isBaseStealing)
            {
                Debug.Log("BASE " + i + "TRYING TO STEAL");
                //If a runner is going to steal base, change stealingAttempt bool to true.
                stealingAttempts[i] = true;
            }
        }

        if (isUIEnabled)
        {
            //This is a stealingAttempts UI update.
            InGameObjects.basePanel.UpdateStealing();
        }

        //Then, a pitcher determines whether pick off the ball or not.
        bool isPickedOff = PickingOff.PickOffDetermine(out int whichBase, true);

        if (isPickedOff)
        {
            Debug.Log("PICK OFF");
            //If the pitcher picks off the ball, a pickoff function starts and control goes to ball in play.
            PickingOff.PickOff(-1, true);
            BallInPlay(BallInPlayMode.PICKOFF, true, whichBase);
            return;
        }
        else
        {
            //If not picked off, pitcher pitches, and sets wildpitch and hitbypitch bool variables.
            Pitching.Pitch(out bool isWildPitch, out bool isHitByPitch, true);
            if (isWildPitch)
            {
                Debug.Log("WILD PITCHED");
                //If a pitcher wild pitched, control goes to ball in play.
                PitchedWild.WildPitch(currentPitcher);
                BallInPlay(BallInPlayMode.WILD_PITCH);
                return;
            }
            else
            {
                //If not wild pitched, determine wheter a batter swung or not.
                bool isSwung = AtPlate.SwingDetermine(true);
                if (isHitByPitch)
                {
                    //If a batter got a hit-by-pitch ball, advances runner by 1 base, and the turn ends.
                    AtPlate.AddBall(true);
                    return;
                }
                else
                {
                    //If not hit-by-pitch ball, check if a batter swung.
                    if (isSwung)
                    {
                        Debug.Log("He Swings!");
                        //If swung, determine whether a swing hit or not.
                        bool isHit = Hitting.HitDetermine(true);
                        if (isHit)
                        {
                            //If hit, control goes to ball in play.
                            BallInPlay(BallInPlayMode.NORMAL);
                            return;
                        }
                        else
                        {
                            //If not hit, adds a strike.
                            AtPlate.AddStrike();
                            return;
                        }
                    }
                    else
                    {
                        //If not swung, determine whether a ball is strike or ball.
                        bool isInStrike = Pitching.InStrikeZoneDetermine(true);
                        if (isInStrike)
                        {
                            //If a ball is in strikezone, adds a strike.
                            AtPlate.AddStrike();
                            return;
                        }
                        else
                        {
                            //If not in strikezone, adds a ball.
                            AtPlate.AddBall();
                            return;
                        }
                    }
                }
            }
        }
    }