Exemplo n.º 1
0
    private void NewWord()
    {
        englishAudio.gameObject.SetActive(false);
        newWordButton.SetActive(false);
        GetWord();
        questionMark.text           = "?";
        currentWordText_EN.text     = "";
        currentWordImage.sprite     = null;
        currentWordImageDupe.sprite = null;
        currentWordImage.gameObject.SetActive(false);
        currentWordImageDupe.gameObject.SetActive(false);
        currentWordText_FI.text = FinnishAlphabet.Niceify(_currentWord);
        _currentWordChars       = _currentWord.ToCharArray();
        _selectedChars          = new char[_currentWord.Length];
        selected.text           = "";
        _lettersFound           = 0;

        for (int i = 0; i < _selectedChars.Length; i++)
        {
            _selectedChars[i] = '_';
            selected.text    += "_";
        }

        lettersFound.SetActive(true);

        for (int i = 0; i < _currentTranslation.Length; i++)
        {
            currentWordText_EN.text += "_ ";
        }


        List <char> tileChars = new List <char>();

        for (int i = 0; i <= 25; i++)
        {
            tileChars.Add(i < _currentWordChars.Length ? _currentWordChars[i] : FinnishAlphabet.RandomCharacter());
        }

        //Shuffle the letters so the first tile is not always the correct answer!
        var rng = new System.Random();

        tileChars.Sort((x, y) => rng.Next(0, 1));

        Vector2 spawnRef = _tileSpawnLoc;

        foreach (char c in tileChars)
        {
            CreateTile(c, spawnRef);
            spawnRef.x += 0.75f;
        }

        Debug.Log(string.Format("The current word is {0}. ({1})", _currentWord, _currentTranslation));
    }
Exemplo n.º 2
0
    /// <summary>
    /// Setup the letter tiles for the turn.
    /// </summary>
    private void CreateTiles()
    {
        _currentLetters.Clear();

        for (int i = 0; i < characterTiles.Length; i++)
        {
            char c = FinnishAlphabet.RandomCharacter();
            if (_currentLetters.Contains(c) || _lastLetter == c)
            {
                //  Debug.Log(string.Format("{0} is either the current letter or is currently in the tile list. Trying again.", c));
                i--;
            }
            else
            {
                _currentLetters.Add(c);
            }
        }

        //Shuffle the letters so the first tile is not always the correct answer!
        var rng = new System.Random();

        _currentLetters.Sort((x, y) => rng.Next(0, 1));

        _letterToGuess = _currentLetters[UnityEngine.Random.Range(0, 10)];
        Debug.Log(string.Format("The letter to guess this turn is '{0}'.", _letterToGuess));
        PlaySound();

        //Update the tile characters.
        for (int i = 0; i < _currentLetters.Count; i++)
        {
            characterTiles[i].GetComponentInChildren <Text>().text = _currentLetters[i].ToString();
        }

        _question++;
        questionNo.text = _question.ToString();
    }