コード例 #1
0
ファイル: KnockDown.cs プロジェクト: Sam-Thomson/Knock_Out
 // Update is called once per frame
 void Update()
 {
     boxer1Position    = FindObjectOfType <Boxer1Movement>();
     boxer2Position    = FindObjectOfType <Boxer2Movement>();
     boxer1KnockedDown = FindObjectOfType <Boxer1Health> ();
     boxer1Down        = boxer1KnockedDown.down;
     boxer2KnockedDown = FindObjectOfType <Boxer2Health> ();
     boxer2Down        = boxer2KnockedDown.down;
     rounds            = FindObjectOfType <Rounds> ();
     gameOver          = rounds.gameOver;
     if (boxer1Down == true)
     {
         if (boxer1RoundKDs >= 2)
         {
             player2Wins.enabled = true;
             if (Input.GetButtonDown("Controller1AButton") || Input.GetButtonDown("Controller2AButton"))
             {
                 SceneManager.LoadScene(0);
             }
         }
         boxer2Position.resetPosition();
         aButton.enabled         = true;
         aButtonProgress.enabled = true;
         KDCText.enabled         = true;
         if (Input.GetButtonDown("Controller1AButton") && cTime < 10)
         {
             if (boxer1TotalKDs >= 1)
             {
                 progressAmount = progressAmount + (0.1f / (boxer1TotalKDs + 1));
             }
             else
             {
                 progressAmount = progressAmount + 0.1f;
             }
         }
         if (progressAmount >= 1)
         {
             boxer1KnockedDown.boxer1Up();
             aButton.enabled         = false;
             aButtonProgress.enabled = false;
             progressAmount          = 0;
             cTime           = sTime;
             KDCText.enabled = false;
             boxer1TotalKDs++;
             boxer1RoundKDs++;
             score.boxer1KnockedDown();
         }
         ProgressBar.GetComponent <Image> ().fillAmount = progressAmount;
         cTime       += 1 * Time.deltaTime;
         KDCText.text = cTime.ToString("0");
         if (cTime >= 10)
         {
             player2Wins.enabled = true;
             if (Input.GetButtonDown("Controller1AButton") || Input.GetButtonDown("Controller2AButton"))
             {
                 SceneManager.LoadScene(0);
             }
         }
     }
     else if (boxer2Down == true)
     {
         if (boxer2RoundKDs >= 2)
         {
             player1Wins.enabled = true;
             if (Input.GetButtonDown("Controller1AButton") || Input.GetButtonDown("Controller2AButton"))
             {
                 SceneManager.LoadScene(0);
             }
         }
         boxer1Position.resetPosition();
         aButton.enabled         = true;
         aButtonProgress.enabled = true;
         KDCText.enabled         = true;
         if (Input.GetButtonDown("Controller2AButton") && cTime < 10)
         {
             if (boxer2TotalKDs >= 1)
             {
                 progressAmount = progressAmount + (0.1f / (boxer2TotalKDs + 1));
             }
             else
             {
                 progressAmount = progressAmount + 0.1f;
             }
         }
         if (progressAmount >= 1)
         {
             boxer2KnockedDown.boxer2Up();
             aButton.enabled         = false;
             aButtonProgress.enabled = false;
             progressAmount          = 0;
             cTime           = sTime;
             KDCText.enabled = false;
             boxer2TotalKDs++;
             boxer2RoundKDs++;
             score.boxer2KnockedDown();
         }
         ProgressBar.GetComponent <Image> ().fillAmount = progressAmount;
         cTime       += 1 * Time.deltaTime;
         KDCText.text = cTime.ToString("0");
         if (cTime >= 10)
         {
             player1Wins.enabled = true;
             if (Input.GetButtonDown("Controller1AButton") || Input.GetButtonDown("Controller2AButton"))
             {
                 SceneManager.LoadScene(0);
             }
         }
     }
     else if (gameOver == true)
     {
         if (Input.GetButtonDown("Controller1AButton") || Input.GetButtonDown("Controller2AButton"))
         {
             SceneManager.LoadScene(0);
         }
     }
 }
コード例 #2
0
    void Update()
    {
        points            = FindObjectOfType <PointCounter> ();
        boxer1RoundPoints = points.boxer1Points;
        boxer2RoundPoints = points.boxer2Points;
        knockDowns        = FindObjectOfType <KnockDown> ();
        boxer1KnockDowns  = knockDowns.boxer1RoundKDs;
        boxer2KnockDowns  = knockDowns.boxer2RoundKDs;
        roundTime        -= Time.deltaTime;
        int minutes = Mathf.FloorToInt(roundTime / 60f);
        int seconds = Mathf.RoundToInt(roundTime % 60f);

        if (seconds == 60)
        {
            seconds  = 0;
            minutes += 1;
        }

        roundTimer.text      = minutes.ToString("0") + ":" + seconds.ToString("00");
        roundNumberText.text = roundNumber.ToString("0");

        if (roundTimer.text == "0:00")
        {
            if (boxer1RoundPoints > boxer2RoundPoints)
            {
                if (roundNumber == 1)
                {
                    boxer1Round1.text = "10";
                    if (boxer2KnockDowns == 1)
                    {
                        boxer2Round1.text = "8";
                    }
                    else if (boxer2KnockDowns == 2)
                    {
                        boxer2Round1.text = "7";
                    }
                    else
                    {
                        boxer2Round1.text = "9";
                    }
                }
                else if (roundNumber == 2)
                {
                    boxer1Round2.text = "10";
                    if (boxer2KnockDowns == 1)
                    {
                        boxer2Round1.text = "8";
                    }
                    else if (boxer2KnockDowns == 2)
                    {
                        boxer2Round1.text = "7";
                    }
                    else
                    {
                        boxer2Round2.text = "9";
                    }
                }
                else if (roundNumber == 3)
                {
                    boxer1Round3.text = "10";
                    if (boxer2KnockDowns == 1)
                    {
                        boxer2Round1.text = "8";
                    }
                    else if (boxer2KnockDowns == 2)
                    {
                        boxer2Round1.text = "7";
                    }
                    else
                    {
                        boxer2Round3.text = "9";
                    }
                }
                else if (roundNumber == 4)
                {
                    boxer1Round4.text = "10";
                    if (boxer2KnockDowns == 1)
                    {
                        boxer2Round1.text = "8";
                    }
                    else if (boxer2KnockDowns == 2)
                    {
                        boxer2Round1.text = "7";
                    }
                    else
                    {
                        boxer2Round4.text = "9";
                    }
                }
                boxer1Points = boxer1Points + 10;
                if (boxer2KnockDowns == 1)
                {
                    boxer2Points = boxer2Points + 8;
                }
                else if (boxer2KnockDowns == 2)
                {
                    boxer2Points = boxer2Points + 7;
                }
                else
                {
                    boxer2Points = boxer2Points + 9;
                }
                boxer1Total.text = boxer1Points.ToString();
                boxer2Total.text = boxer2Points.ToString();
            }
            else if (boxer1RoundPoints < boxer2RoundPoints)
            {
                if (roundNumber == 1)
                {
                    boxer1Round1.text = "9";
                    boxer2Round1.text = "10";
                }
                else if (roundNumber == 2)
                {
                    boxer1Round2.text = "9";
                    boxer2Round2.text = "10";
                }
                else if (roundNumber == 3)
                {
                    boxer1Round3.text = "9";
                    boxer2Round3.text = "10";
                }
                else if (roundNumber == 4)
                {
                    boxer1Round4.text = "9";
                    boxer2Round4.text = "10";
                }
                boxer1Points     = boxer1Points + 9;
                boxer2Points     = boxer2Points + 10;
                boxer1Total.text = boxer1Points.ToString();
                boxer2Total.text = boxer2Points.ToString();
            }
            else
            {
                if (roundNumber == 1)
                {
                    boxer1Round1.text = "10";
                    boxer2Round1.text = "10";
                }
                else if (roundNumber == 2)
                {
                    boxer1Round2.text = "10";
                    boxer2Round2.text = "10";
                }
                else if (roundNumber == 3)
                {
                    boxer1Round3.text = "10";
                    boxer2Round3.text = "10";
                }
                else if (roundNumber == 4)
                {
                    boxer1Round4.text = "10";
                    boxer2Round4.text = "10";
                }
                boxer1Points     = boxer1Points + 10;
                boxer2Points     = boxer2Points + 10;
                boxer1Total.text = boxer1Points.ToString();
                boxer2Total.text = boxer2Points.ToString();
            }
            boxer1HealthIncrease.roundIncrease();
            boxer2HealthIncrease.roundIncrease();
            boxer1MaxStaminaDecrease.decreaseMaxStamina();
            boxer2MaxStaminaDecrease.decreaseMaxStamina();
            roundNumber++;
            knockDowns.boxer1RoundKDs = 0;
            knockDowns.boxer2RoundKDs = 0;
            boxer1KnockDowns          = 0;
            boxer2KnockDowns          = 0;
            if (roundNumber < 5)
            {
                roundTime = 120f;
                boxer1Position.resetPosition();
                boxer2Position.resetPosition();
                points.resetPoints();
            }
            else
            {
                if (boxer1Points > boxer2Points)
                {
                    player1Wins.enabled     = true;
                    round.enabled           = false;
                    roundTimer.enabled      = false;
                    roundNumberText.enabled = false;
                    gameOver = true;
                }
                else if (boxer1Points < boxer2Points)
                {
                    player2Wins.enabled     = true;
                    round.enabled           = false;
                    roundTimer.enabled      = false;
                    roundNumberText.enabled = false;
                    gameOver = true;
                }
                else
                {
                    draw.enabled            = true;
                    round.enabled           = false;
                    roundTimer.enabled      = false;
                    roundNumberText.enabled = false;
                    gameOver = true;
                }
            }
        }
    }