コード例 #1
0
        public List <NPC> CreateNPC()
        {
            XmlSerializer serializer = new XmlSerializer(typeof(List <NPC>), new XmlRootAttribute("NPCs"));

            using (XmlReader reader = XmlReader.Create(@"..\..\data\npc.xml"))
            {
                NPCs = (List <NPC>)serializer.Deserialize(reader);
                NPCs.ForEach(i => XMLReference <Item> .Link(i.Items, Items));
                return(NPCs);
            }
        }
コード例 #2
0
        public List <Container> CreateContainers()
        {
            XmlSerializer serializer = new XmlSerializer(typeof(List <Container>), new XmlRootAttribute("Containers"));

            using (XmlReader reader = XmlReader.Create(@"..\..\data\containers.xml"))
            {
                Containers = (List <Container>)serializer.Deserialize(reader);
                Containers.ForEach(i => XMLReference <Item> .Link(i.Contents, Items));
                return(Containers);
            }
        }
コード例 #3
0
        /* CreateRoom is a little different in that it calls upon an XMLReference object
         * kudos to my friend Matthew Hatch for coming up with that idea
         * basically he suggested that I "smarten" C#'s deserializer in this regard
         * I approached these XML files thinking about it like a SQL database,
         * XMLReference objects basically act as INNER JOIN
         */
        public void CreateRoom()
        {
            XmlSerializer serializer = new XmlSerializer(typeof(List <Room>), new XmlRootAttribute("Rooms"));

            using (XmlReader reader = XmlReader.Create(@"..\..\data\room.xml"))
            {
                Rooms = (List <Room>)serializer.Deserialize(reader);
                // Rooms are generated with specific Item and NPC ID's
                // We can parse through them with XMLReference lists.
                Rooms.ForEach(i => XMLReference <Item> .Link(i.Items, Items));
                Rooms.ForEach(i => XMLReference <NPC> .Link(i.NPCs, NPCs));
                Rooms.ForEach(i => XMLReference <Door> .Link(i.Doors, Doors));
                Rooms.ForEach(i => XMLReference <Container> .Link(i.Containers, Containers));
                // Printing is just for testing purposes, presently
                // Rooms.ForEach(r => PrintRoomDescription(r));
            }
        }