Example #1
0
        private void FillSubtractionModeNumbers()
        {
            System.Random rnd = new System.Random();

            int correctNumberOne;
            int correctNumberTwo;

            // Dicculty Setting
            if (_instance.CurrentDiffulty == GameDifficulty.Easy)
            {
                _GUIManager._instance.NumberToFind.text = Random.Range(1, EASY_NUMBERS_RANGE).ToString();

                // Get the two correct numbers
                correctNumberOne = Random.Range(int.Parse(_GUIManager._instance.NumberToFind.text), EASY_NUMBERS_MAX);
                //int correctNumberOne = rnd.Next(maxReference);
                correctNumberTwo = correctNumberOne - int.Parse(_GUIManager._instance.NumberToFind.text);
            }

            else if (_instance.CurrentDiffulty == GameDifficulty.Normal)
            {
                _GUIManager._instance.NumberToFind.text = Random.Range(1, NORMAL_NUMBERS_RANGE).ToString();

                // Get the two correct numbers
                correctNumberOne = Random.Range(int.Parse(_GUIManager._instance.NumberToFind.text), NORMAL_NUMBERS_MAX);
                //int correctNumberOne = rnd.Next(maxReference);
                correctNumberTwo = correctNumberOne - int.Parse(_GUIManager._instance.NumberToFind.text);
            }

            else
            {
                _GUIManager._instance.NumberToFind.text = Random.Range(1, HARD_NUMBERS_RANGE).ToString();

                // Get the two correct numbers
                correctNumberOne = Random.Range(int.Parse(_GUIManager._instance.NumberToFind.text), HARD_NUMBERS_MAX);
                //int correctNumberOne = rnd.Next(maxReference);
                correctNumberTwo = correctNumberOne - int.Parse(_GUIManager._instance.NumberToFind.text);
            }

            // Add random number to all buttons
            foreach (var button in _GUIManager._instance.NumericAnswers)
            {
                // Get children(text)
                Text buttonText = button.GetComponentInChildren <Text>();
                button.interactable = true;

                buttonText.text = Random.Range(1, int.Parse(_GUIManager._instance.NumberToFind.text)).ToString();
            }

            // Insert the two correct answers into the list
            Text buttonOneText = _GUIManager._instance.NumericAnswers[0].GetComponentInChildren <Text>();

            buttonOneText.text = correctNumberOne.ToString();
            Text buttonTwoText = _GUIManager._instance.NumericAnswers[1].GetComponentInChildren <Text>();

            buttonTwoText.text = correctNumberTwo.ToString();

            // Randomize the list
            ListHelpers.RandomizeList(_GUIManager._instance.NumericAnswers);
        }