예제 #1
0
    //Called after each round; returns IEnumerator for timer use
    IEnumerator RoundFinished(PlayerRPS p1)
    {
        //Disables buttons for set time to prevent player from continuing round
        p1.buttonRock.interactable     = false;
        p1.buttonPaper.interactable    = false;
        p1.buttonScissors.interactable = false;

        //Timer to between rounds to display results
        yield return(new WaitForSeconds(2));

        //Resets buttons to working game state
        p1.ResetButtons();

        //Resets text to starting state
        resultGT.text = " ";
        p1TextGO.SetActive(false);
        p2TextGO.SetActive(false);
        vsGT.text = "Select Option";

        //Destroy images
        p1.DestroyP1IM();
        Destroy(p2IM);

        //Updates round number if game not finished
        if (roundNum <= totalRounds)
        {
            roundsGT.text = "Round: " + roundNum.ToString();
            p2Choice      = GetComputerChoice();
        }
        else
        {
            GameFinished(p1);
        }
    }
예제 #2
0
    //Called when game finishes (after round 10)
    //Displays overall game result
    void GameFinished(PlayerRPS p1)
    {
        vsGO.SetActive(false);
        gameOverGO.SetActive(true);

        //Player wins
        if (p1.score > p2Score)
        {
            resultGT.color = Color.green;
            resultGT.text  = "YOU WIN";
        }

        //Computer wins
        else if (p2Score > p1.score)
        {
            resultGT.color = Color.red;
            resultGT.text  = "YOU LOSE";
        }

        //Draw
        else
        {
            resultGT.color = Color.yellow;
            resultGT.text  = "DRAW";
        }

        //Activates play again and quit button
        p1.buttonRock.gameObject.SetActive(false);
        p1.buttonPaper.gameObject.SetActive(false);
        p1.buttonScissors.gameObject.SetActive(false);
        playAgain.gameObject.SetActive(true);
        quitGame.gameObject.SetActive(true);

        UserValidation.userList[UserValidation.activeUserIndex].AddGame("RPS", p1.score, UserValidation.userList[UserValidation.activeUserIndex].username, dateTime);
        UserValidation.Save();
    }
예제 #3
0
    //Main game logic
    public void Compare(PlayerRPS p1)
    {
        //Continues until game over (after round 10)
        if (roundNum <= totalRounds)
        {
            //Sets text based on game state
            p1TextGO.SetActive(true);
            p2TextGO.SetActive(true);
            vsGT.text = "VS";
            //Instantiate computer image
            p2IM = Instantiate(p2Prefab) as GameObject;

            //player and computer choice is the same
            if (PlayerRPS.choice == (int)p2Choice)
            {
                resultGT.color = Color.yellow;
                resultGT.text  = "Round Result: DRAW";
            }
            else
            {
                //Player chose Rock
                if (PlayerRPS.choice == 1)
                {
                    //Computer chose Scissors (YOU WIN)
                    if ((int)p2Choice == 3)
                    {
                        resultGT.color = Color.green;
                        resultGT.text  = "Round Result: YOU WIN";
                        p1.PlayerWin(p1.buttonRock);
                    }
                    //Computer chose Paper (YOU LOSE)
                    else
                    {
                        resultGT.color = Color.red;
                        resultGT.text  = "Round Result: YOU LOSE";
                        p1.ChangeButtonColor(p1.buttonRock, Color.red);
                        ComputerWin();
                    }
                }

                //Player chose Paper
                if (PlayerRPS.choice == 2)
                {
                    //Computer chose Rock (YOU WIN)
                    if ((int)p2Choice == 1)
                    {
                        resultGT.color = Color.green;
                        resultGT.text  = "Round Result: YOU WIN";
                        p1.PlayerWin(p1.buttonPaper);
                    }
                    //Computer chose Scissors (YOU LOSE)
                    else
                    {
                        resultGT.color = Color.red;
                        resultGT.text  = "Round Result: YOU LOSE";
                        p1.ChangeButtonColor(p1.buttonPaper, Color.red);
                        ComputerWin();
                    }
                }

                //Player chooses Scissors
                if (PlayerRPS.choice == 3)
                {
                    //Computer chose Paper (YOU WIN)
                    if ((int)p2Choice == 2)
                    {
                        resultGT.color = Color.green;
                        resultGT.text  = "Round Result: YOU WIN";
                        p1.PlayerWin(p1.buttonScissors);
                    }
                    //Computer chose Rock (YOU LOSE)
                    else
                    {
                        resultGT.color = Color.red;
                        resultGT.text  = "Round Result: YOU LOSE";
                        p1.ChangeButtonColor(p1.buttonScissors, Color.red);
                        ComputerWin();
                    }
                }
            }
            roundNum++;
        }

        //Couroutine used for timer
        StartCoroutine(RoundFinished(p1));
    }