Example #1
0
        private static void AddQuests(Location location, XmlNodeList quests)
        {
            if (quests == null)
            {
                return;
            }

            foreach (XmlNode questNode in quests)
            {
                location.QuestsAvailableHere
                .Add(QuestFactory.GetQuestByID(questNode.GetXmlAttributeAsInt("ID")));
            }
        }
Example #2
0
        internal static World CreateWorld(string playerName)
        {
            World newWorld = new World();

            //Intro Specific
            newWorld.AddIntroLocation(0, 0, "Intro", playerName,
                                      "/Images/Avatars/Hero.jpg");

            newWorld.LocationAt(0, 0).QuestsAvailableHere.Add(QuestFactory.GetQuestByID(0));
            //Rest of the world

            if (File.Exists(GAME_DATA_FILENAME))
            {
                XmlDocument data = new XmlDocument();
                data.LoadXml(File.ReadAllText(GAME_DATA_FILENAME));
                string locationImagePath =
                    data.SelectSingleNode("/Locations/BasicLocations")
                    .GetXmlAttributeAsString("RootImagePath");

                string traderLocationImagePath =
                    data.SelectSingleNode("/Locations/TraderLocations").
                    GetXmlAttributeAsString("RootImagePath");

                LoadLocationsFromNodes(newWorld,
                                       locationImagePath,
                                       data.SelectNodes("/Locations/BasicLocations/Location"));
                LoadLocationsFromNodes(newWorld,
                                       traderLocationImagePath,
                                       data.SelectNodes("/Locations/TraderLocations/Location"));
            }
            else
            {
                throw new FileNotFoundException($"Missing data file: {GAME_DATA_FILENAME}");
            }

            return(newWorld);
        }