Ejemplo n.º 1
0
    //set the whole scene after coming from menu or from a photosphere
    private void startGame(bool resume = false)
    {
        if (!resume)
        {
            foreach (CountryObject c in CountryPopulator.countryList)
            {
                c.chosen = false;
            }
            GlobalVariables.correctGuesses = 0;
            GlobalVariables.startedPlaying = true;
            int index = Random.Range(1, CountryPopulator.countryList.Count + 1);
            GlobalVariables.correctCountry = GlobalVariables.getCountry(index);
            IOOperations.WriteToSave("Category:" + GlobalVariables.category, true, false, true);
            CountryPopulator.setUpHint(GlobalVariables.correctCountry, GlobalVariables.category);
        }
        else
        {
            CountryPopulator.setUpHint(GlobalVariables.correctCountry, GlobalVariables.category);
            GlobalVariables.resume = false;
            photosphered           = false;
        }

        guessTimer = 0f;
    }
Ejemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        //camera update
        Transform cg1 = GameObject.Find("QuestionCanvasGroup").transform;

        cg1.transform.eulerAngles = new Vector3(90, 0, -Camera.main.transform.eulerAngles.y);

        //set the whole scene after coming from menu or from a photosphere
        if ((lookAtHint && !GlobalVariables.startedPlaying) || (lookAtHint && GlobalVariables.resume))
        {
            //photosphere
            if (GlobalVariables.resume)
            {
                setText("", "CountdownTimer");
                startGame(true);
            }

            //menu
            else
            {
                //hold on to the "Are You Ready?" message
                if (introTimer > 0)
                {
                    CountryPopulator.setUpFirstHint(GlobalVariables.category);
                    introTimer -= Time.deltaTime;
                    GameObject.Find("CountdownTimer").GetComponent <Text>().text = Mathf.CeilToInt(introTimer).ToString();
                }
                //set the first question
                else if (introTimer < 0)
                {
                    startGame();
                    setText("", "CountdownTimer");
                }
            }
        }

        //update variables
        correctCountry = GlobalVariables.correctCountry;
        guessTimer    += Time.deltaTime;

        //if question of all the countries were already done, go back to menu
        if (GlobalVariables.correctGuesses >= GlobalVariables.countryList.Count)
        {
            GlobalVariables.startedPlaying = false;
            resetGame();
            SceneManager.LoadScene("Main Menu", LoadSceneMode.Single);
        }

        else //set everything related to te question
        {
            //adjust the song volume as the user approach the right answer
            if (correctCountry != null && !answeredCorrectly)
            {
                float score = correctCountry.score();
                float value = -1 * score;
                value += 235;
                value  = (value * 0.95f) / 235.05f;
                value  = Mathf.Min(1, Mathf.Max(0.05f, value));
                GameObject.Find("GameMusic").GetComponent <AudioSource>().volume = value;
            }

            //time to display some hints?
            if ((correctCountry != null && !string.IsNullOrEmpty(correctCountry.countryName)) && !answeredCorrectly)
            {
                elapsedTime     += Time.deltaTime;
                correctContinent = correctCountry.continent;

                //hint 1: dim the light of the continents that don't contain the answer
                if (correctContinent != activeContinent)
                {
                    wrongContGaze += Time.deltaTime;
                    if (wrongContGaze > dimTime)
                    {
                        hint1 = true;
                        dimLights(0.001f, correctCountry.weather);
                    }
                }
            }

            //if user exceeds time limit (which will be an adptive value in the future), displays the correct answer
            if (correctCountry != null && guessTimer > (questionTimeOut) && !answeredCorrectly)
            {
                timeOut = true;
            }

            //when the user gets the right answer
            if ((selectedCountry != null && correctCountry.Equals(selectedCountry)) || timeOut || answeredCorrectly)
            {
                elapsedTime = 0f;

                if (!answeredCorrectly)
                {
                    GameObject.Find("GameMusic").GetComponent <AudioSource>().PlayOneShot(correctSound);
                    GameObject.Find("DownArrow").GetComponent <SpriteRenderer>().enabled = true;                       //arrow indicates where to look to get the description of the topic
                    writeToLog(correctCountry.countryName, guessTimer.ToString(), hint1.ToString(), hint2.ToString()); //TODO: ADD WEATHER HINT AND ADJUST DIM HINT (now it is always true)
                    answeredCorrectly = true;
                    displayInfo       = true;
                    timeOut           = false;
                }

                //update the Canvas that stays bellow the user
                if (displayInfo)
                {
                    infoTimer += Time.deltaTime;
                    string description     = XmlParser.getInfo(GlobalVariables.category, correctCountry.countryName);
                    float  descriptionTime = (5 + descriptionTimeFactor * (description.Length));

                    //shows the description of the asked topic, during a time relative to the number of chars in the description text.
                    //right now the descriptionTimeFactor is fixed, but it should be adaptive in the future
                    if (infoTimer < descriptionTime)
                    {
                        GameObject.Find("HintImage").GetComponent <Image>().enabled = false;
                        setText(description, "QuestionText");
                    }

                    //if the country has a photosphere, show a warning about it to the user and then take him to it
                    else
                    {
                        if (GlobalVariables.photosphereCountries.Contains(correctCountry.countryName))
                        {
                            Text questionText = GameObject.Find("QuestionText").GetComponent <Text>();
                            questionText.text = "\n\n\nLet's take a trip to " + correctCountry.countryName + "!!";

                            //warning done, let's travel
                            if (infoTimer > (descriptionTime + photosphereWarningTime))
                            {
                                SceneManager.LoadSceneAsync(correctCountry.countryName, LoadSceneMode.Single);
                                displayInfo  = false;
                                photosphered = true;
                            }
                        }
                        else
                        {
                            displayInfo = false;
                        }
                    }
                }

                //after the description, reset the parameters and get a new question, if any
                if (!displayInfo)
                {
                    if (!photosphered)
                    {
                        GameObject.Find("GameMusic").GetComponent <AudioSource>().Stop();
                    }

                    infoTimer     = 0;
                    wrongContGaze = 0;
                    guessTimer    = 0f;

                    answeredCorrectly = false;
                    hint1             = false;
                    hint2             = false;

                    //mark the country as already seen in the global variables
                    GlobalVariables.correctGuesses++;
                    CountryObject temp = GlobalVariables.countryList.Find(c => c.Equals(correctCountry));
                    temp.chosen = true;

                    if (GlobalVariables.correctGuesses < GlobalVariables.countryList.Count)
                    {
                        GlobalVariables.correctCountry = GlobalVariables.getRandomNonChosen();
                        if (!photosphered)
                        {
                            CountryPopulator.setUpHint(GlobalVariables.correctCountry, GlobalVariables.category);
                        }
                    }
                }
            }
        }
    }