Beispiel #1
0
    /// <summary>
    ///     Get next word.
    /// </summary>
    public void NextWord()
    {
        List <WordMapNode> foundNodes = null;

        if (_currentNode == null)
        {
            WordMapNode newNode = _wordBank.StartingNodes[Random.Range(0, _wordBank.StartingNodes.Count - 1)];
            SetCurrentNodeAndGetNextChoices(newNode);
        }
        else
        {
            foundNodes = _currentNode.GetWeightedRandomChildren(3);

            if (foundNodes.Count > 0)
            {
                _wordChoiceSpawner.SpawnWords(foundNodes, SetCurrentNodeAndGetNextChoices);
            }
            else
            {
                print("End of prophecy!");
                _currentNode = null;
                _prophecyDisplay.ClearProphecy();
                NextWord();
            }
        }

        if (foundNodes == null)
        {
            return;
        }
        foreach (WordMapNode foundNode in foundNodes)
        {
            print($"Choice: {foundNode.Word} id: {foundNode.NodeId}");
        }
    }
Beispiel #2
0
    public void SpawnWords(List <WordMapNode> nodes, UnityAction <WordMapNode> onChoose)
    {
        // Clear previous choices
        for (var i = _choiceObjects.Count - 1; i >= 0; i--)
        {
            WordChoice choiceObject = _choiceObjects[i];
            Destroy(choiceObject.gameObject);
            _choiceObjects.Remove(choiceObject);
        }

        // For each node, spawn a choice object and fill in its info
        foreach (WordMapNode wordMapNode in nodes)
        {
            var obj = Instantiate(_wordChoicePrefab).GetComponent <WordChoice>();
            _choiceObjects.Add(obj);
            obj.transform.SetParent(_wordChoiceParent);

            WordMapNode node = wordMapNode;
            obj.GetComponent <Button>().onClick.AddListener(() => onChoose(node));

            obj.SetNode(wordMapNode);
        }
    }
Beispiel #3
0
 private void SetCurrentNodeAndGetNextChoices(WordMapNode newNode)
 {
     _currentNode = newNode;
     _prophecyDisplay.AddToProphecy(newNode.Word);
     NextWord();
 }
Beispiel #4
0
 public void SetNode(WordMapNode newNode)
 {
     _wordText.text = newNode.Word;
     choiceNode     = newNode;
 }