Beispiel #1
0
    public void Go_Pressed()
    {
        bool allPlayersReady = false; // NetMan.AllPlayersReady is inconsistent upon reloading lobby scene so using this instead

        foreach (var player in NetMan.roomSlots)
        {
            allPlayersReady = player.readyToBegin;
            if (allPlayersReady == false)
            {
                break;
            }
        }

        if (IsHost() && allPlayersReady)
        {
            GameObject roundInfo = GameObject.Find("RoundInfo");
            if (roundInfo != null)
            {
                PersistentRoundInfo pri = roundInfo.GetComponent <PersistentRoundInfo>();
                pri.currentRound   = 1;
                pri.playerOneScore = 0;
                pri.playerTwoScore = 0;
            }
            LocalPlayer.CmdStartGame();

            return;
        }

        // toggle the ready state
        LocalPlayer.CmdChangeReadyState(!LocalPlayer.readyToBegin);
    }
Beispiel #2
0
    void Update()
    {
        PersistentRoundInfo currentRoundHolder = FindObjectOfType <PersistentRoundInfo>();

        currentRound = currentRoundHolder.currentRound;

        myText.text = "Round " + currentRound.ToString();
    }
Beispiel #3
0
    // Start is called before the first frame update
    void Start()
    {
        PersistentRoundInfo currentRoundHolder = FindObjectOfType <PersistentRoundInfo>();

        currentRound = currentRoundHolder.currentRound;

        myText      = gameObject.GetComponent <Text>();
        myText.text = "Round " + currentRound.ToString();
    }
Beispiel #4
0
    // Update is called once per frame
    void Update()
    {
        PersistentRoundInfo currentScoreHolder = FindObjectOfType <PersistentRoundInfo>();

        if (isPlayerOne)
        {
            score = currentScoreHolder.playerOneScore;
        }
        else
        {
            score = currentScoreHolder.playerTwoScore;
        }

        myText.text = score.ToString();
    }
Beispiel #5
0
    // Start is called before the first frame update
    void Start()
    {
        PersistentRoundInfo currentScoreHolder = FindObjectOfType <PersistentRoundInfo>();

        if (isPlayerOne)
        {
            score = currentScoreHolder.playerOneScore;
        }
        else
        {
            score = currentScoreHolder.playerTwoScore;
        }

        myText      = gameObject.GetComponent <Text>();
        myText.text = score.ToString();
    }
Beispiel #6
0
    private void CalculateWinner()
    {
        PersistentRoundInfo thisRoundInfo = FindObjectOfType <PersistentRoundInfo>();

        //Game needs to go on to next round
        if (thisRoundInfo.currentRound < 3)
        {
            if (playerOneScore > playerTwoScore)
            {
                winScreen.GetComponent <Text>().color = new Color(0, 255, 255);
                winScreen.GetComponent <Text>().text  = playerOneName + " Wins!";
                thisRoundInfo.playerOneScore         += 1;
                thisRoundInfo.currentRound           += 1;
            }
            else if (playerTwoScore > playerOneScore)
            {
                winScreen.GetComponent <Text>().color = new Color(0.92f, 0.5f, 0.04f, 1);
                winScreen.GetComponent <Text>().text  = playerTwoName + " Wins!";
                thisRoundInfo.playerTwoScore         += 1;
                thisRoundInfo.currentRound           += 1;
            }
            else
            {
                winScreen.GetComponent <Text>().color = new Color(255, 255, 255);
                winScreen.GetComponent <Text>().text  = "Draw!";
                thisRoundInfo.currentRound           += 1;
            }
            SoundControl.PlayWinSound();
            winScreen.SetActive(true);
            StartCoroutine(NextRound(thisRoundInfo.currentRound));
        }
        //Game done
        else
        {
            if (playerOneScore > playerTwoScore)
            {
                FindObjectOfType <PersistentRoundInfo>().playerOneScore += 1;
            }
            else if (playerTwoScore > playerOneScore)
            {
                FindObjectOfType <PersistentRoundInfo>().playerTwoScore += 1;
            }

            if (thisRoundInfo.playerOneScore > thisRoundInfo.playerTwoScore)
            {
                winScreen.GetComponent <Text>().color = new Color(0, 255, 255);
                winScreen.GetComponent <Text>().text  = "Game Over! \n" + playerOneName + " Wins!";
            }
            else if (thisRoundInfo.playerTwoScore > thisRoundInfo.playerOneScore)
            {
                winScreen.GetComponent <Text>().color = new Color(0.92f, 0.5f, 0.04f, 1);
                winScreen.GetComponent <Text>().text  = "Game Over! \n" + playerTwoName + " Wins!";
            }

            else
            {
                winScreen.GetComponent <Text>().color = new Color(255, 255, 255);
                winScreen.GetComponent <Text>().text  = "Game Over! \n Draw!";
            }

            SoundControl.PlayWinSound();
            winScreen.SetActive(true);
            StartCoroutine(EndGame());
        }
    }