/// <summary> /// 读档 /// </summary> /// <param name="recordFile">记录文件(XML)</param> public void Load(string recordFile) { /* * 1. 加载魔塔地图和当前楼层 * * 2. 加载人物 * * 3. 加载抵达楼层信息 * * 4. 道具包 * */ XDocument recordDocument = XDocument.Load(recordFile); XElement record = recordDocument.Root; XElement mapArgs = record.Element("map"); XElement heroArgs = record.Element("hero"); //加载当前楼层 int curFloor = LoadCurFloor(mapArgs); //加载地图 bool[] reached = LoadMap(mapArgs); //加载人物 Hero player = Hero.Create(heroArgs); //关闭无关窗口 MotaWorld.GetInstance().CloseWindow(); CurGame.Initialize(curFloor, player, reached); }
/// <summary> /// 根据事件类型码创建相应的事件元素 /// </summary> /// <param name="createArgs">事件参数</param> /// <param name="existCoord">出现坐标</param> /// <returns>事件元素</returns> public static MapEvent CreateInstance(XElement createArgs, Coord existCoord) { XElement eventArgs = createArgs.Element(EVENT_TYPE_STR); EventType typeCode = (EventType)int.Parse(eventArgs.Value); MapEvent mapEvent; switch (typeCode) { case EventType.Empty: mapEvent = EmptyEvent.Create(eventArgs, existCoord); break; case EventType.Box: mapEvent = Box.Create(eventArgs, existCoord); break; case EventType.Door: mapEvent = Door.Create(eventArgs, existCoord); break; case EventType.Equip: mapEvent = Equip.Create(eventArgs, existCoord); break; case EventType.Hero: mapEvent = Hero.Create(eventArgs); break; case EventType.Monster: mapEvent = Monster.Create(eventArgs, existCoord); break; case EventType.Shop: mapEvent = ShopEvent.Create(eventArgs, existCoord); break; case EventType.Weapon: mapEvent = Weapon.Create(eventArgs, existCoord); break; case EventType.NullEvent: return(null); default: throw new Exception("不存在的类型码"); } mapEvent.SetEvent(createArgs.Element(EVENT_ADD_STR)); return(mapEvent); }