Beispiel #1
0
    // Is more memory being used if we keep pressing Pick over and over
    public void PickRandomCrewMember()
    {
        Text murdererTextBox = xmlText;

        murdererTextBox.text = "";
        int randomID = Random.Range(1, 7);

        // Pick a new random number until we get one that has not already been used to pick a new member.
        while (_idAlreadyChosen.Contains(randomID))
        {
            randomID = Random.Range(1, 7);
        }
        // Add the randomID chosen to the _idAlreadyChosen List so that we can keep track of Crew Members we have already utilized
        _idAlreadyChosen.Add(randomID);

        //print ("RandomID: " + randomID);

        // Set up XMLReader
        Culprit culpritToReturn = new Culprit();
        //XmlReader culpritReader = XmlReader.Create ("Assets\\Resources\\" + xmlFileToRead);
        XmlReader         culpritReader = XmlReader.Create(new StringReader(xmlAsset.text));
        XmlWriterSettings ws            = new XmlWriterSettings();
        XmlWriter         writer        = XmlWriter.Create(output, ws);

        culpritReader.MoveToContent();
        // Read the xml file while there are still elements to read
        while (culpritReader.Read())
        {
            culpritReader.ReadToDescendant("crewMember");
            culpritReader.ReadToFollowing("id");
            int intToCompare = culpritReader.ReadElementContentAsInt();
            if (intToCompare == randomID)
            {
                culpritToReturn.id = intToCompare;
                culpritReader.ReadToNextSibling("title");
                culpritToReturn.title = culpritReader.ReadElementContentAsString();
                culpritReader.ReadToNextSibling("name");
                culpritToReturn.name = culpritReader.ReadElementContentAsString();
                culpritReader.ReadToNextSibling("description");
                culpritToReturn.description = culpritReader.ReadElementContentAsString();
                break;
            }
            else
            {
                culpritReader.Skip();
            }
        }

        // close xmlReader and xmlWriter
        culpritReader.Close();
        writer.Close();
        // Return culprit information to the appropriate textBox
        murdererTextBox.text += "ID: " + culpritToReturn.id + "\n"
                                + "Title: " + culpritToReturn.title + "\n"
                                + "Name: " + culpritToReturn.name + "\n"
                                + "Description: " + culpritToReturn.description;
    }
Beispiel #2
0
    Culprit ReturnCulpritInfo(int idNumber)
    {
        int intToCompare = 0;
        //Declare new culprit that will be returned once filled out with relevant data
        Culprit culpritToReturn = new Culprit();

        XmlReader         culpritReader = XmlReader.Create("Assets\\Resources\\" + xmlFileToRead);
        XmlWriterSettings ws            = new XmlWriterSettings();
        XmlWriter         writer        = XmlWriter.Create(output, ws);

        culpritReader.MoveToContent();

        while (culpritReader.Read())
        {
            culpritReader.ReadToDescendant("culprit");
            culpritReader.ReadToFollowing("id");
            // If the id in the xml matches the given parameter argument then gather information to
            // stated culprit to return.
            intToCompare = culpritReader.ReadElementContentAsInt();
            if (intToCompare == idNumber)
            {
                // Messed up by trying to call culpritReader.ReadElementContentAsInt() again and it didn't work. Why not?
                culpritToReturn.id = intToCompare;
                culpritReader.ReadToNextSibling("name");
                culpritToReturn.name = culpritReader.ReadElementContentAsString();
                culpritReader.ReadToNextSibling("title");
                culpritToReturn.title = culpritReader.ReadElementContentAsString();
                culpritReader.ReadToNextSibling("age");
                culpritToReturn.age = culpritReader.ReadElementContentAsInt();
                culpritReader.ReadToNextSibling("description");
                culpritToReturn.description = culpritReader.ReadElementContentAsString();
                break;
            }
            else
            {
                culpritReader.Skip();
            }
        }
        // close xmlReader and xmlWriter (Do we need to flush them?)
        culpritReader.Close();
        writer.Close();
        return(culpritToReturn);
    }
Beispiel #3
0
        public void AssertValid()
        {
            Id.ErrorIdAssertValid();
            TraceId.TraceIdAssertValid();
            TransactionId.TransactionIdAssertValid();
            ParentId.ParentIdAssertValid();
            Transaction.AssertValid();
            Context?.AssertValid();
            Culprit.NonEmptyAssertValid();
            Exception.AssertValid();

            if (Transaction.IsSampled)
            {
                Context.Should().NotBeNull();
            }
            else
            {
                Context.Should().BeNull();
            }
        }
    // Function that is in charge of picking the culprit and grabbing their corresponding clues
    public void AssignCulpritAndClues()
    {
        // Find corresponding Text to fill
        Text    murdererTextBox = GameObject.Find("MurdererInfo").GetComponent <Text>();
        Text    clueTextBox     = GameObject.Find("Clues").GetComponent <Text>();
        Culprit mainCulp        = new Culprit();

        JsonData data = JsonMapper.ToObject(JSONAsset.text);
        // Pick random id to determine the murderer
        int randomID = Random.Range(1, 3);

        _idAlreadyChosen.Add(randomID);
        _murdererID = randomID;
        print(randomID);
        // Indexing starts at 0 so we put id - 1
        // Start filling out the culprits information
        // Parse the string returned from data to an int.
        mainCulp.id          = System.Int32.Parse(data["crew"][randomID - 1]["id"].ToString());
        mainCulp.title       = data["crew"][randomID - 1]["title"].ToString();
        mainCulp.name        = data ["crew"] [randomID - 1] ["name"].ToString();
        mainCulp.description = data ["crew"] [randomID - 1] ["description"].ToString();

        // Fill out corresponding TextBox with Information
        murdererTextBox.text = "ID: " + mainCulp.id + "\n"
                               + "Title: " + mainCulp.title + "\n"
                               + "Name: " + mainCulp.name + "\n"
                               + "Description: " + mainCulp.description;

        // Fill out the corresponding TextBox for clues with the information and
        // Start adding the clues to the list murderClues
        for (int i = 1; i < 6; i++)
        {
            string clueNumber = "clue" + i.ToString();
            murdererClues.Add(data["crew"][randomID - 1][clueNumber].ToString());
            clueTextBox.text += "Clue " + i + ": " + murdererClues [i - 1] + "\n";
        }
    }