Ejemplo n.º 1
0
        private void PopulateObjectAndDictionary(XmlDocument doc)
        {
            objTable = new ObjTable();
            stringTable.AddEntry("YOU NOTICE NOTHING UNEXPECTED.");

            XmlNodeList list = doc.SelectNodes("//project/objects/object");

            foreach (XmlNode n in list)
            {
                string name = n.Attributes.GetNamedItem("name").Value;

                //get the child node with the description
                XmlNode child = n.ChildNodes[0];
                string  desc  = child.InnerText;

                //don't add blank descriptions
                if (desc != "")
                {
                    stringTable.AddEntry(desc);
                }

                //initial desc
                string initialDesc = n.SelectSingleNode("initialdescription").InnerText;

                if (initialDesc != "" && initialDesc != null)
                {
                    stringTable.AddEntry(initialDesc);
                }

                //break the name into words and put each word in the dictionary
                char[]   delimiterChars = { ' ' };
                string[] toks           = name.Split(delimiterChars);

                foreach (string s in toks)
                {
                    if (s != null && !s.Equals(""))
                    {
                        dictionary.AddEntry(s);
                    }
                }

                //create the object from the data
                GameObject gobj = new GameObject(n);
                objTable.Add(new ObjTableEntry(gobj, stringTable));


                //put synoyms in table
                foreach (string s in gobj.synonyms)
                {
                    if (!s.Equals(""))
                    {
                        dictionary.AddEntry(s);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void PopulateObjectAndDictionary(XmlDocument doc)
        {
            objTable = new ObjTable();
            stringTable.AddEntry("YOU NOTICE NOTHING UNEXPECTED.");

            XmlNodeList list      = doc.SelectNodes("//project/objects/object");
            int         idCounter = 0;

            foreach (XmlNode n in list)
            {
                string name = n.Attributes.GetNamedItem("name").Value;

                try
                {
                    //get the child node with the description
                    XmlNode child = n.ChildNodes[0];
                    string  desc  = child.InnerText;

                    //don't add blank descriptions
                    if (desc != "")
                    {
                        stringTable.AddEntry(desc);
                    }
                    else
                    {
                        stringTable.AddEntry("YOU NOTICE NOTHING UNEXPECTED.");
                        n.ChildNodes[0].InnerText = "YOU NOTICE NOTHING UNEXPECTED.";
                    }

                    //initial desc

                    try
                    {
                        string initialDesc = n.SelectSingleNode("initialdescription").InnerText.Trim();

                        if (initialDesc != "" && initialDesc != null)
                        {
                            stringTable.AddEntry(initialDesc);
                        }
                    }
                    catch
                    {
                    }
                    //break the name into words and put each word in the dictionary
                    char[]   delimiterChars = { ' ' };
                    string[] toks           = name.Split(delimiterChars);

                    foreach (string s in toks)
                    {
                        if (s != null && !s.Equals(""))
                        {
                            dictionary.AddEntry(s);
                        }
                    }

                    //create the object from the data
                    GameObject gobj = null;
                    try
                    {
                        gobj = new GameObject(n);
                        objTable.Add(new ObjTableEntry(gobj, stringTable));
                    }
                    catch (Exception ex)
                    {
                        throw new Exception("Unable to add object to name", ex);
                    }


                    //put synoyms in table
                    if (gobj.synonyms != null)
                    {
                        foreach (string s in gobj.synonyms)
                        {
                            if (!s.Equals(""))
                            {
                                dictionary.AddEntry(s);
                            }
                        }
                    }

                    //check for nogo messages
                    //if any movement dir has a corresponding entry in the nogo table
                    //set the atr to 255 - string id
                    foreach (string d in dirs)
                    {
                        if (gobj.HasNogoMsg(d))
                        {
                            string msg       = gobj.GetNogoMsg(d);
                            int    nogoIndex = nogoTable.GetEntryId(msg);
                            objTable.SetObjAttr(gobj.id, d.ToUpper(), (255 - nogoIndex) + 1);
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception("Error adding " + name + " to dictionary", ex);
                }
            }
        }