コード例 #1
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;
                        }
                    }
                }
            }
        }
    }