Exemplo n.º 1
0
    /// <summary>  GameSetup scene - number of questions input field. </summary>
    /// <param name="incrementValue">Value to increment number of questions input field in
    /// GameSetup scene. Can be a negative value. Examples: 1, -1, 2, -3.</param>
    public void Btn_IncrementNumberOfQuestions(int incrementValue)
    {
        int maxQuestions = 15;
        int minQuestions = 5;

        // Link to GameSetup data object.
        GamePreprocessor gamePreprocessor
            = FindObjectOfType <GamePreprocessor>().GetComponent <GamePreprocessor>();

        // Ensures that the number of questions is within the specified range.
        if ((gamePreprocessor.GameSetupData.NumberOfQuestions + incrementValue) < minQuestions)
        {
            gamePreprocessor.GameSetupData.NumberOfQuestions = minQuestions;
        }
        else if ((gamePreprocessor.GameSetupData.NumberOfQuestions + incrementValue) > maxQuestions)
        {
            gamePreprocessor.GameSetupData.NumberOfQuestions = maxQuestions;
        }
        else // Value is valid.
        {
            gamePreprocessor.GameSetupData.NumberOfQuestions += incrementValue;
        }

        GameObject.Find("InputField").GetComponent <InputField>().text
            = gamePreprocessor.GameSetupData.NumberOfQuestions.ToString();

        GameObject.Find("Text_NumberOfQuestions").GetComponent <Text>().text
            = gamePreprocessor.GameSetupData.NumberOfQuestions.ToString();

        Debug.Log("Number of questions value changed to: "
                  + gamePreprocessor.GameSetupData.NumberOfQuestions.ToString());
    }
Exemplo n.º 2
0
    private void Start()
    {
        globalData       = FindObjectOfType <GlobalData>().GetComponent <GlobalData>();
        gameDefaults     = globalData.GameDefaults;
        gamePreprocessor = FindObjectOfType <GamePreprocessor>().GetComponent <GamePreprocessor>();
        gameSetupData    = gamePreprocessor.GameSetupData;
        audioManager     = globalData.AudioManager;

        activatedColor = gameDefaults.DefaultColors[Enum_Colors.GREEN_LIGHT];

        soundButtonImage           = GameObject.Find("Mute_Image").GetComponent <Image>();
        soundButtonImageBackground = GameObject.Find("Mute_Image_Background").GetComponent <Image>();

        GameObject.Find("Mute_Image_Background").GetComponent <Image>().color
            = gameDefaults.DefaultColors[Enum_Colors.GREEN_LIGHT];

        // Sets all 'activated state' button's/toggle's image colors.
        SetGameObjectColors();

        UpdateSetupData();
    }
Exemplo n.º 3
0
    void Start()
    {
        // Linking scripts.
        globalData         = FindObjectOfType <GlobalData>().GetComponent <GlobalData>();
        gameDefaults       = globalData.GameDefaults;
        audioManager       = FindObjectOfType <AudioManager>().GetComponent <AudioManager>();
        gamePreprocessor   = FindObjectOfType <GamePreprocessor>().GetComponent <GamePreprocessor>();
        playerScoreElement = FindObjectOfType <PlayerScoreElement>().GetComponent <PlayerScoreElement>();
        menuManager        = FindObjectOfType <MenuManager>().GetComponent <MenuManager>();


        // Initializes GameSetupData object.
        gamePreprocessor.NewQuestionsAndAnswers();
        gameTimeLimit = gamePreprocessor.GameSetupData.GameTimeLimit;


        // Finding gameobjects in game.
        answerButtons             = GameObject.FindGameObjectsWithTag("AnswerButton");
        answerFeedbackCanvasGroup = GameObject.Find("Image_AnswerFeedback").GetComponent <CanvasGroup>();
        answerText            = GameObject.Find("Answer_Text").GetComponent <Text>();
        answerTextCanvasGroup = GameObject.Find("Answer_Text").GetComponent <CanvasGroup>();
        clearAnswerButton     = GameObject.Find("Btn_ClearAnswer");
        questionText          = GameObject.Find("Area_Question_Text").GetComponent <Text>();

        gameFinishScreen         = GameObject.Find("GameFinishScreen");
        gameFinishScreenContent  = GameObject.Find("GameFinishScreenContent");
        gameFinishScreenSubTitle = GameObject.Find("GameFinishScreenSubTitle").GetComponent <Text>();
        gameFinishScreenTitle    = GameObject.Find("GameFinishScreenTitle").GetComponent <Text>();

        timerSliderFillLeft  = GameObject.Find("TimerSliderFillLeft").GetComponent <Image>();
        timerSliderFillRight = GameObject.Find("TimerSliderFillRight").GetComponent <Image>();
        timerSliderLeft      = GameObject.Find("TimerSliderLeft").GetComponent <Slider>();
        timerSliderRight     = GameObject.Find("TimerSliderRight").GetComponent <Slider>();
        timerText            = GameObject.Find("Text_TimeRemaining").GetComponent <Text>();

        // Adds listeners for answer button sounds.
        foreach (GameObject go in GameObject.FindGameObjectsWithTag("AnswerButton"))
        {
            go.GetComponentInChildren <Button>().onClick.AddListener(() => audioManager.Play("Btn_Click"));
        }


        // Disables gameFinishScreen.
        gameFinishScreen.GetComponent <CanvasGroup>().alpha        = 0f;
        gameFinishScreenContent.GetComponent <CanvasGroup>().alpha = 0f;


        // Time-limit.
        timerIsOn = true;
        incrementalSliderValue = gameTimeLimit / 4;

        timerSliderFillLeft.color  = gameDefaults.DefaultColors[Enum_Colors.GREEN];
        timerSliderFillRight.color = gameDefaults.DefaultColors[Enum_Colors.GREEN];

        timerSliderLeft.maxValue  = gameTimeLimit;
        timerSliderRight.maxValue = gameTimeLimit;

        timerSliderLeft.value  = gameTimeLimit;
        timerSliderRight.value = gameTimeLimit;


        // Initial labels update.
        UpdateQuestionText();
    }