예제 #1
0
        /// <summary>
        /// 打开怪物手册
        /// </summary>
        /// <param name="data">楼层id</param>
        public override void Open(object data)
        {
            Enable = true;

            //搜寻当前楼层的所有怪物
            FloorNode curFloor = MotaWorld.GetInstance().MapManager.CurFloorNode;

            for (int i = 0; i < curFloor.FloorSize.Row; i++)
            {
                for (int j = 0; j < curFloor.FloorSize.Col; j++)
                {
                    if (curFloor.IsMonster(new Coord(j, i)))
                    {
                        //给怪物列表添加怪物, 不用重复
                        Monster oneMonster = curFloor.EventMap[i, j] as Monster;
                        if (!Monsters.Exists(o => o.MonsterId == oneMonster.MonsterId))
                        {
                            Monsters.Add(oneMonster);
                        }
                    }
                }
            }

            //按对勇士造成的伤害排序
            Monsters.Sort();

            //如果存在怪物,绑定第一个怪物的图像更新事件,实现在窗口中播放动态的怪物图像
            if (Monsters.Count > 0)
            {
                Monsters[0].FrameChangeEvent += new EventHandler(OneFlash);
            }

            ReDraw();
        }
예제 #2
0
        /// <summary>
        /// 创建路径计算对象
        /// </summary>
        /// <param name="sourceObj">源对象的引用</param>
        /// <param name="startPos">起点坐标</param>
        /// <param name="endPos">终点坐标</param>
        public PathCaculator(FloorNode sourceObj, Coord startPos, Coord endPos)
        {
            this.CurFloor  = sourceObj;
            this.StartPos  = startPos;
            this.TargetPos = endPos;

            //初始化内部字段
            Passed = new bool[this.CurFloor.FloorSize.Row, this.CurFloor.FloorSize.Col];
        }
예제 #3
0
        /// <summary>
        /// 创建路径计算对象
        /// </summary>
        /// <param name="sourceObj">源对象的引用</param>
        /// <param name="startPos">起点坐标</param>
        /// <param name="endPos">终点坐标</param>
        public PathCaculator(FloorNode sourceObj, Coord startPos, Coord endPos)
        {
            this.CurFloor = sourceObj;
            this.StartPos = startPos;
            this.TargetPos = endPos;

            //初始化内部字段
            Passed = new bool[this.CurFloor.FloorSize.Row, this.CurFloor.FloorSize.Col];
        }
예제 #4
0
        /// <summary>
        /// 根据一层楼的XML数据创建楼层元素
        /// </summary>
        /// <param name="oneFloorArgs">楼层数据</param>
        /// <returns>返回一个拥有数据的楼层对象</returns>
        public static FloorNode Create(XElement oneFloorArgs)
        {
            int    index;     //楼层索引
            string name;      //楼层名称
            int    rowNum;    //行数
            int    colNum;    //列数
            int    preFloor;  //前驱楼层
            int    nextFloor; //后继楼层
            int    upRow;     //上楼后的初始行
            int    upCol;     //上楼后的初始列
            int    downRow;   //下楼后的初始行
            int    downCol;   //下楼后的初始列

            try
            {
                index     = int.Parse(oneFloorArgs.Element("index").Value);
                rowNum    = int.Parse(oneFloorArgs.Element("rowNum").Value);
                colNum    = int.Parse(oneFloorArgs.Element("colNum").Value);
                preFloor  = int.Parse(oneFloorArgs.Element("preFloor").Value);
                nextFloor = int.Parse(oneFloorArgs.Element("nextFloor").Value);
                upRow     = int.Parse(oneFloorArgs.Element("heroRow").Value);
                upCol     = int.Parse(oneFloorArgs.Element("heroCol").Value);
                downRow   = int.Parse(oneFloorArgs.Element("downRow").Value);
                downCol   = int.Parse(oneFloorArgs.Element("downCol").Value);
                name      = oneFloorArgs.Element("name").Value;
            }
            catch (Exception)
            {
                throw new Exception("错误的楼层数据");
            }

            List <Swicther> autoSwitchs = new List <Swicther>();

            autoSwitchs.Clear();

            if (oneFloorArgs.Element("switchers") != null)
            {
                XElement switchers = oneFloorArgs.Element("switchers");
                foreach (var item in switchers.Elements("switcher"))
                {
                    autoSwitchs.Add(Swicther.CreateFromXml(item));
                }
            }

            FloorNode oneFloor = new FloorNode(index, name, new Coord(colNum, rowNum), nextFloor, preFloor, new Coord(upCol, upRow), new Coord(downCol, downRow), autoSwitchs);

            //加载地图层
            LoadBackLayer(oneFloorArgs, oneFloor);

            //加载事件层
            LoadEventLayer(oneFloorArgs, oneFloor);

            return(oneFloor);
        }
예제 #5
0
        /// <summary>
        /// 打开怪物信息窗口,显示怪物的详细数据
        /// </summary>
        /// <param name="pos">怪物的坐标(在当前楼层中)</param>
        private void ShowMonsterData(Coord pos)
        {
            FloorNode curFloor = MapManager.CurFloorNode;

            if (curFloor.IsMonster(pos))
            {
                MotaWorld.GetInstance().MiniBookWindow.Open(curFloor.EventMap[pos.Row, pos.Col] as Monster);
            }
            else
            {
                MotaWorld.GetInstance().MiniBookWindow.Close();
            }
        }
예제 #6
0
        /// <summary>
        /// 加载地图
        /// </summary>
        /// <param name="mapArgs">地图数据</param>
        /// <returns>返回一个布尔数组,记录抵达过的楼层</returns>
        private bool[] LoadMap(XElement mapArgs)
        {
            IEnumerable <XElement> floors = mapArgs.Elements("oneFloor");
            int count = floors.Count();

            bool[] reached = new bool[count];
            CurGame.Tower.Clear();

            foreach (var floor in floors)
            {
                FloorNode newFloor = FloorNode.Create(floor);
                CurGame.Tower.AddFloor(newFloor);

                //记录已经抵达过的楼层
                if (floor.Attribute("reached") != null)
                {
                    reached[newFloor.FloorIndex] = true;
                }
            }

            return(reached);
        }
예제 #7
0
        /// <summary>
        /// 加载事件层
        /// </summary>
        /// <param name="oneFloorArgs">事件层参数</param>
        /// <param name="oneFloor">待加载的楼层对象</param>
        private static void LoadEventLayer(XElement oneFloorArgs, FloorNode oneFloor)
        {
            XElement floorEventArgs = oneFloorArgs.Element("eventLayer");

            for (int row = 0; row < oneFloor.FloorSize.Row; row++)
            {
                //这里引入中间变量,为了提高查询速度
                XElement rowEventArgs = floorEventArgs.Elements("oneRow").ElementAt(row);
                for (int col = 0; col < oneFloor.FloorSize.Col; col++)
                {
                    try
                    {
                        oneFloor.EventMap[row, col] = MapEvent.CreateInstance(
                            rowEventArgs.Elements("oneEvent").ElementAt(col), new Coord(col, row));
                    }
                    catch (Exception)
                    {
                        oneFloor.EventMap[row, col] = null;
                    }
                }
            }
        }
예제 #8
0
        /// <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());
                    }
                }
            }
        }
예제 #9
0
 /// <summary>
 /// 添加新的楼层
 /// </summary>
 public void AddFloor(FloorNode newFloor)
 {
     Floors.Add(newFloor);
 }
예제 #10
0
 /// <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());
             }
         }
     }
 }
예제 #11
0
 /// <summary>
 /// 加载事件层
 /// </summary>
 /// <param name="oneFloorArgs">事件层参数</param>
 /// <param name="oneFloor">待加载的楼层对象</param>
 private static void LoadEventLayer(XElement oneFloorArgs, FloorNode oneFloor)
 {
     XElement floorEventArgs = oneFloorArgs.Element("eventLayer");
     for (int row = 0; row < oneFloor.FloorSize.Row; row++)
     {
         //这里引入中间变量,为了提高查询速度
         XElement rowEventArgs = floorEventArgs.Elements("oneRow").ElementAt(row);
         for (int col = 0; col < oneFloor.FloorSize.Col; col++)
         {
             try
             {
                 oneFloor.EventMap[row, col] = MapEvent.CreateInstance(
                     rowEventArgs.Elements("oneEvent").ElementAt(col), new Coord(col, row));
             }
             catch (Exception)
             {
                 oneFloor.EventMap[row, col] = null;
             }
         }
     }
 }
예제 #12
0
        /// <summary>
        /// 根据一层楼的XML数据创建楼层元素
        /// </summary>
        /// <param name="oneFloorArgs">楼层数据</param>
        /// <returns>返回一个拥有数据的楼层对象</returns>
        public static FloorNode Create(XElement oneFloorArgs)
        {
            int index;      //楼层索引
            string name;    //楼层名称
            int rowNum;     //行数
            int colNum;     //列数
            int preFloor;   //前驱楼层
            int nextFloor;  //后继楼层
            int upRow;      //上楼后的初始行
            int upCol;      //上楼后的初始列
            int downRow;    //下楼后的初始行
            int downCol;    //下楼后的初始列

            try
            {
                index = int.Parse(oneFloorArgs.Element("index").Value);
                rowNum = int.Parse(oneFloorArgs.Element("rowNum").Value);
                colNum = int.Parse(oneFloorArgs.Element("colNum").Value);
                preFloor = int.Parse(oneFloorArgs.Element("preFloor").Value);
                nextFloor = int.Parse(oneFloorArgs.Element("nextFloor").Value);
                upRow = int.Parse(oneFloorArgs.Element("heroRow").Value);
                upCol = int.Parse(oneFloorArgs.Element("heroCol").Value);
                downRow = int.Parse(oneFloorArgs.Element("downRow").Value);
                downCol = int.Parse(oneFloorArgs.Element("downCol").Value);
                name = oneFloorArgs.Element("name").Value;
            }
            catch (Exception)
            {
                throw new Exception("错误的楼层数据");
            }

            List<Swicther> autoSwitchs = new List<Swicther>();
            autoSwitchs.Clear();

            if (oneFloorArgs.Element("switchers") != null)
            {
                XElement switchers = oneFloorArgs.Element("switchers");
                foreach (var item in switchers.Elements("switcher"))
                {
                    autoSwitchs.Add(Swicther.CreateFromXml(item));
                }
            }
            
            FloorNode oneFloor = new FloorNode(index, name, new Coord(colNum, rowNum), nextFloor, preFloor, new Coord(upCol, upRow), new Coord(downCol, downRow), autoSwitchs);

            //加载地图层
            LoadBackLayer(oneFloorArgs, oneFloor);

            //加载事件层
            LoadEventLayer(oneFloorArgs, oneFloor);

            return oneFloor;
        }
예제 #13
0
 /// <summary>
 /// 添加新的楼层
 /// </summary>
 public void AddFloor(FloorNode newFloor)
 {
     Floors.Add(newFloor);
 }
예제 #14
0
파일: Path.cs 프로젝트: sleepandeat/Program
 /// <summary>
 /// 判断当前的目标位置在制定的楼层中是否可以通行
 /// </summary>
 /// <param name="floor">楼层</param>
 /// <returns>返回一个布尔值,标示是否可以通行</returns>
 public bool PassableIn(FloorNode floor)
 { 
     //委托楼层对象计算
     return floor.IsPassable(TargetPos, CurPathDiection);
 }
예제 #15
0
 /// <summary>
 /// 判断当前的目标位置在制定的楼层中是否可以通行
 /// </summary>
 /// <param name="floor">楼层</param>
 /// <returns>返回一个布尔值,标示是否可以通行</returns>
 public bool PassableIn(FloorNode floor)
 {
     //委托楼层对象计算
     return(floor.IsPassable(TargetPos, CurPathDiection));
 }