예제 #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));
    }
예제 #2
0
    private IEnumerator _DisplayTranslation()
    {
        char[]        letters    = FinnishAlphabet.Niceify(_currentTranslation).ToCharArray();
        char[]        finLetters = FinnishAlphabet.Niceify(_currentWord).ToCharArray();
        StringBuilder sb         = new StringBuilder();

        currentWordText_FI.color = Color.green;

        PlayWord(1);
        for (int i = finLetters.Length; i > 0; i--)
        {
            currentWordText_FI.text = "";
            for (int j = finLetters.Length - i; j < (finLetters.Length - i) + 1; j++)
            {
                Debug.Log(j);
                sb.Append(finLetters[j]);
            }
            currentWordText_FI.text = sb.ToString();
            yield return(new WaitForSeconds(0.2f));
        }

        currentWordText_FI.color = Color.white;
        sb.Length = 0;
        yield return(new WaitForSeconds(0.5f));

        currentWordText_EN.color = Color.green;
        PlayWord(0);
        for (int i = letters.Length; i > 0; i--)
        {
            currentWordText_EN.text = "";
            for (int j = letters.Length - i; j < (letters.Length - i) + 1; j++)
            {
                Debug.Log(j);
                sb.Append(letters[j]);
            }
            currentWordText_EN.text = sb.ToString();
            yield return(new WaitForSeconds(0.2f));
        }
        currentWordText_EN.color = Color.white;

        yield return(new WaitWhile(() => _audioSource.isPlaying));

        if (_dictionary.Count == 0)
        {
            _EndSet();
            yield break;
        }
        newWordButton.SetActive(true);
    }
예제 #3
0
    public void ClickTile(GameObject g)
    {
        char c    = char.Parse(g.name);
        char next = _currentWordChars.First(x => x != '#');

        if (c != next)
        {
            Debug.Log(string.Format("{0} is not {1}!", c, next));
            _audioSource.PlayOneShot(wrongSfx, 0.15f);
            return;
        }

        if (!_currentWordChars.Contains(c))
        {
            Debug.Log(string.Format("{0} is not a character in {1}", c, _currentWord));
            _audioSource.PlayOneShot(wrongSfx, 0.15f);
            return;
        }

        int i = Array.FindIndex(_currentWordChars, x => x == c); //Find the index position of the selected character in the current word.

        _currentWordChars[i] = '#';                              //set it to a char that is never used to avoid null references.
        _selectedChars[i]    = c;
        selected.text        = "";
        _lettersFound++;
        _audioSource.PlayOneShot(correctSfx, 0.15f);

        StringBuilder sb = new StringBuilder();

        foreach (var letter in _selectedChars)
        {
            //We want to use "__" rather than "_" to increase the space taken up.
            sb.Append(string.Format("{0}", letter == '_' ? "_" : letter.ToString()));
        }

        selected.text = FinnishAlphabet.Niceify(sb.ToString());

        Destroy(g);

        if (_currentWordChars.Count() == _lettersFound)
        {
            selected.text = "You found the word!";
            // Time.timeScale = 0;
            FoundWord();
        }

        return;
    }
예제 #4
0
    private void CreateCards()
    {
        var rng = new System.Random();

        spawnLocs = ShuffleList(spawnLocs);
        spawnLocs.Sort((x, y) => rng.Next(0, 1));
        int index = 0;

        for (int i = 0; i < 20; i += 2)
        {
            GameObject imageCard = Instantiate(imageCardPrefab, spawnLocs[i].position, Quaternion.identity) as GameObject;
            GameObject textCard  = Instantiate(textCardPrefab, spawnLocs[i + 1].position, Quaternion.identity) as GameObject;
            KeyValuePair <string, string> item = _dictionary.ElementAt(index);
            Sprite         s    = GetSprite(item.Value.ToLower());
            SpriteRenderer rend = imageCard.GetComponentInChildren <SpriteRenderer>();
            var            c    = s == null?GetColour(item.Value.ToLower()) : new Color32(255, 255, 255, 255);

            //Make changes to the cards.
            textCard.GetComponent <TextMesh>().text            = FinnishAlphabet.Niceify(item.Key);
            imageCard.GetComponentInChildren <TextMesh>().text = item.Value == "ORANGE-FRUIT" ? "Orange" : FinnishAlphabet.Niceify(item.Value);
            rend.sprite = s == null ? square : s;
            rend.color  = c;

            if (s == null)
            {
                rend.transform.localScale = new Vector3(1, 1);
            }

            textCard.name  = item.Value.ToLower();
            imageCard.name = item.Value.ToLower();
            index++;
            spawnedItem.Add(imageCard);
            spawnedItem.Add(textCard);
        }

        for (int i = 0; i < 10; i++)
        {
            _dictionary.Remove(_dictionary.ElementAt(0).Key);
        }
        Debug.Log(_dictionary.Count);
    }