Exemplo n.º 1
0
    public void SpawnWords()
    {
        if (WordSet == null)
        {
            Debug.LogError("WordSet is null !!!");
            return;
        }

        ClearTable();

        // Find center
        _bounds = WordSet.GetBound();

        Vector3 boundsCenter = _bounds.center;

        boundsCenter.x = Mathf.Round(boundsCenter.x);
        boundsCenter.y = Mathf.Round(boundsCenter.y);
        boundsCenter.z = 0;

        _bounds.center = boundsCenter;

        // Spawn new words
        foreach (SWord sWord in WordSet.Words)
        {
            SpawnWord(sWord);
        }

        // PostProcess
        WordManager.GetWordsFormChilds();
        LetterController.ConnectAdjacentLetters();
    }
Exemplo n.º 2
0
    public void Rotate()
    {
        WordManager
            .GetComponentsInChildren<Word>()
            .ToList()
            .ForEach(w =>
            {
                Undo(w, "Rotate");
                w.Direction =
                    (w.Direction == WordDirection.Horizontal) ?
                    WordDirection.Vertical : WordDirection.Horizontal;
            });

        LetterController
            .AllLetters
            .ForEach(l =>
            {
                Vector3 position = l.transform.position;
                position.x = l.transform.position.y;
                position.y = l.transform.position.x;

                Undo(l.transform, "Rotate");
                l.transform.position = position;
            });

        LetterController.ConnectAdjacentLetters();
    }
Exemplo n.º 3
0
    public void SpawnWordsExtraZoom(bool extra)
    {
        if (WordSet == null)
        {
            Debug.LogError("WordSet is null !!!");
            return;
        }

        ClearTable();

        // Find center
        _bounds = WordSet.GetBound();

        Vector3 boundsCenter = _bounds.center;

        boundsCenter.x = Mathf.Round(boundsCenter.x);
        boundsCenter.y = Mathf.Round(boundsCenter.y);
        boundsCenter.z = 0;

        _bounds.center = boundsCenter;

        // Spawn new words
        foreach (SWord sWord in WordSet.Words)
        {
            SpawnWord(sWord);
        }

        // PostProcess
        WordManager.GetWordsFormChilds();
        LetterController.ConnectAdjacentLetters();

        if (Application.isPlaying)
        {
            StartCoroutine(CameraController.FocusAllLettersExtra(extra));
            if (SpawnPartByPart)
            {
                StartCoroutine(EnableParts());
            }
            else
            {
                LetterController.AllLetters.ForEach(l => l.gameObject.SetActive(true));
            }
        }
        else
        {
            LetterController.AllLetters.ForEach(l => l.gameObject.SetActive(true));
        }
    }
Exemplo n.º 4
0
    private bool TryPartition()
    {

        LetterController.ConnectAdjacentLetters();

        // Clear partitions
        if (Paritions == null)
            Paritions = new List<List<Letter>>();

        Paritions.Clear();

        // Add first partition with all letters
        Paritions.Add(
            WordManager
                .GetComponentsInChildren<Word>()
                .SelectMany(w => w.Letters)
                .Distinct()
                .ToList());


        while (Paritions.Max(p => p.Count) > MaxSize)
        {
            // Get random letter from biggest partition
            List<Letter> biggestPartition = Paritions.OrderByDescending(p => p.Count).First();
            Letter letter = GetRandomMember(biggestPartition);

            // Get connected letters
            List<Letter> newPartition = new List<Letter>();
            GetConnectedLetters(letter, newPartition, Random.Range(MinSize + 1, MaxSize + 1));

            // Disconnect newPartition and add to list
            Disconnect(biggestPartition, newPartition);
            Paritions.Add(newPartition);

            // Separate Biggest partition in two -- if possible
            Separate(biggestPartition);

            if (Paritions.Min(p => p.Count) < MinSize)
                return false;
        }

        return true;
    }