コード例 #1
0
    // Create a new Quip from the Tag and Quip text
    // box, and save it into the XML file.
    public void createElement()
    {
        Debug.Log("create");
        Quip tempPlayer = new Quip();

        tempPlayer.Id   = quipList.Count + 1;
        tempPlayer.name = QuipText.text;
        tempPlayer.tags = TagText.text;
        quipList.Add(tempPlayer);
        displayPlayeData(tempPlayer);

        XmlNode    parentNode = xmlDoc.SelectSingleNode("Quips");
        XmlElement element    = xmlDoc.CreateElement("Quip");

        element.SetAttribute("id", tempPlayer.Id.ToString());
        element.AppendChild(createNodeByName("name", tempPlayer.name));
        element.AppendChild(createNodeByName("tags", tempPlayer.tags));
        parentNode.AppendChild(element);
        xmlDoc.Save(getPath() + ".xml");

        Debug.Log("New Quip " + quipList[quipList.Count - 1].Id + " added to qipList");
        TagText.text  = "";
        QuipText.text = "";
        Refresh();
    }
コード例 #2
0
 private void readXml()
 {
     foreach (XmlElement node in xmlDoc.SelectNodes("Quips/Quip"))
     {
         Quip tempPlayer = new Quip();
         tempPlayer.Id   = int.Parse(node.GetAttribute("id"));
         tempPlayer.name = node.SelectSingleNode("name").InnerText;
         tempPlayer.tags = node.SelectSingleNode("tags").InnerText;
         quipList.Add(tempPlayer);
         displayPlayeData(tempPlayer);
     }
 }
コード例 #3
0
    // Depreciated, saved for hoarding purposes.
    public void CheckForRelevantQuipBackUp()
    {
        Quip bestQuip          = new Quip();
        int  highestMatchSoFar = 0;

        if (relevantQuips.Count > 0)
        {
            relevantQuips.Clear();
        }
        int allQuips = 0;

        foreach (Quip quippet in quipList)
        {
            int tempMatch = GetRelevance(quippet.tags, quippet.name);


            if (tempMatch >= highestMatchSoFar)
            {
                allQuips++;
                if (tempMatch > highestMatchSoFar)
                {
                    highestMatchSoFar = tempMatch;
                    relevantQuips.Clear();
                }
                else
                {
                    Debug.Log("lower, no kill " + tempMatch + "<" + highestMatchSoFar + " of " + allQuips);
                }
                relevantQuips.Add(quippet);
            }
        }

        if (highestMatchSoFar > 1)
        {
            int rando = Random.Range(0, relevantQuips.Count);
            bestQuip = relevantQuips[rando];
            matchDisplayText.text = bestQuip.name;
        }

        else
        {
            matchDisplayText.text = "No matches";
        }
    }
コード例 #4
0
    // Hooked up to Button, displays quip in matchDisplayText
    // Quip must match at least one variable
    public void CheckForRelevantQuip()
    {
        // string bestMatch = "";
        Quip bestQuip          = new Quip();
        int  highestMatchSoFar = 0;

        if (relevantQuips.Count > 0)
        {
            relevantQuips.Clear();
        }
        int allQuips = 0;

        foreach (Quip quippet in quipList)
        {
            int tempMatch = GetRelevance(quippet.tags, quippet.name);

            if (tempMatch > highestMatchSoFar)
            {
                highestMatchSoFar = tempMatch;
                relevantQuips.Clear();
                relevantQuips.Add(quippet);
            }

            else if (tempMatch == highestMatchSoFar)
            {
                relevantQuips.Add(quippet);
            }
        }


        Debug.Log("Found " + relevantQuips.Count + " relevant quips.");
        int rando = Random.Range(0, relevantQuips.Count);

        bestQuip = relevantQuips[rando];
        matchDisplayText.text = bestQuip.name;
    }
コード例 #5
0
 // Displays All Quips in a textbox for testing
 private void displayPlayeData(Quip tempPlayer)
 {
     allQuipDisplay.text += tempPlayer.name + "\t\t (" + tempPlayer.tags + ") \n";
 }