/// <summary> /// 根据地图参数创建相应的地图元素 /// </summary> /// <param name="mapArgs">地图参数</param> /// <param name="existCoord">出现坐标</param> /// <returns>地图元素</returns> public static Background CreateInstance(XElement mapArgs, Coord existCoord) { int faceIndex; //图像索引 try { faceIndex = int.Parse(mapArgs.Element("faceIndex").Value); } catch (Exception) { throw new Exception("错误的地图类型 位置: " + existCoord.ToString()); } bool canDestory = false; if (mapArgs.Element("canDestory") != null) { canDestory = true; } Background oneBack = new Background((MotaElement)faceIndex, existCoord, canDestory); bool upAllow = false; if (mapArgs.Element("upAllow") != null) { upAllow = true; } bool downAllow = false; if (mapArgs.Element("downAllow") != null) { downAllow = true; } bool leftAllow = false; if (mapArgs.Element("leftAllow") != null) { leftAllow = true; } bool rightAllow = false; if (mapArgs.Element("rightAllow") != null) { rightAllow = true; } oneBack.PassLeft = leftAllow; oneBack.PassDown = downAllow; oneBack.PassRight = rightAllow; oneBack.PassUp = upAllow; return(oneBack); }
/// <summary> /// 根据地图参数创建相应的地图元素 /// </summary> /// <param name="mapArgs">地图参数</param> /// <param name="existCoord">出现坐标</param> /// <returns>地图元素</returns> public static Background CreateInstance(XElement mapArgs, Coord existCoord) { int faceIndex; //图像索引 try { faceIndex = int.Parse(mapArgs.Element("faceIndex").Value); } catch (Exception) { throw new Exception("错误的地图类型 位置: " + existCoord.ToString()); } bool canDestory = false; if (mapArgs.Element("canDestory") != null) { canDestory = true; } Background oneBack = new Background((MotaElement)faceIndex, existCoord, canDestory); bool upAllow = false; if (mapArgs.Element("upAllow") != null) { upAllow = true; } bool downAllow = false; if (mapArgs.Element("downAllow") != null) { downAllow = true; } bool leftAllow = false; if (mapArgs.Element("leftAllow") != null) { leftAllow = true; } bool rightAllow = false; if (mapArgs.Element("rightAllow") != null) { rightAllow = true; } oneBack.PassLeft = leftAllow; oneBack.PassDown = downAllow; oneBack.PassRight = rightAllow; oneBack.PassUp = upAllow; return oneBack; }
/// <summary> /// 加载地图层 /// </summary> /// <param name="oneFloorArgs">地图层参数</param> /// <param name="oneFloor">待加载的楼层对象</param> private static void LoadBackLayer(XElement oneFloorArgs, FloorNode oneFloor) { XElement floorBackArgs = oneFloorArgs.Element("backLayer"); for (int row = 0; row < oneFloor.FloorSize.Row; row++) { //这里引入中间变量,为了提高查询速度 XElement rowBackArgs = floorBackArgs.Elements("oneRow").ElementAt(row); for (int col = 0; col < oneFloor.FloorSize.Col; col++) { Coord pos = new Coord(col, row); try { oneFloor.BackMap[row, col] = Background.CreateInstance( rowBackArgs.Elements("oneBack").ElementAt(col), pos); } catch (Exception) { throw new Exception("地图层不可为空, 缺少位置: " + pos.ToString()); } } } }
/// <summary> /// 加载地图层 /// </summary> /// <param name="oneFloorArgs">地图层参数</param> /// <param name="oneFloor">待加载的楼层对象</param> private static void LoadBackLayer(XElement oneFloorArgs, FloorNode oneFloor) { XElement floorBackArgs = oneFloorArgs.Element("backLayer"); for (int row = 0; row < oneFloor.FloorSize.Row; row++) { //这里引入中间变量,为了提高查询速度 XElement rowBackArgs = floorBackArgs.Elements("oneRow").ElementAt(row); for (int col = 0; col < oneFloor.FloorSize.Col; col++) { Coord pos = new Coord(col, row); try { oneFloor.BackMap[row, col] = Background.CreateInstance( rowBackArgs.Elements("oneBack").ElementAt(col), pos); } catch (Exception) { throw new Exception("地图层不可为空, 缺少位置: " + pos.ToString()); } } } }