Example #1
0
        /// <summary>
        /// 初始化地图元素
        /// </summary>
        private void InitMap()
        {
            if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + @"MapData\map.txt"))
            {
                string str = File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + @"MapData\map.txt");
                JArray ja  = (JArray)JsonConvert.DeserializeObject(str);
                foreach (var item in ja)
                {
                    Enums.MapType mt = Enums.MapType.Walls;
                    switch (item["type"].ToString())
                    {
                    case "Walls":
                        mt = Enums.MapType.Walls;
                        break;

                    case "Steels":
                        mt = Enums.MapType.Steels;
                        break;

                    case "Grass":
                        mt = Enums.MapType.Grass;
                        break;

                    case "Water":
                        mt = Enums.MapType.Water;
                        break;
                    }
                    int        x  = Convert.ToInt32(item["X"]) * 60;
                    int        y  = Convert.ToInt32(item["Y"]) * 60;
                    MapElement me = new MapElement(x, y, mt);
                    mapList.Add(me);
                }
            }
        }
Example #2
0
        private static Image SetImg(Enums.MapType type)
        {
            Image mg;

            if (type == Enums.MapType.Walls)
            {
                mg = imgs[0];
            }
            else if (type == Enums.MapType.Steels)
            {
                mg = imgs[1];
            }
            else if (type == Enums.MapType.Grass)
            {
                mg = imgs[2];
            }
            else if (type == Enums.MapType.Water)
            {
                mg = imgs[3];
            }
            else
            {
                mg = imgs[0];
            }

            return(mg);
        }
Example #3
0
        private void SetIsPass(Enums.MapType type)
        {
            switch (type)
            {
            case Enums.MapType.Walls:
            case Enums.MapType.Steels:
                this.isPass = false;
                break;

            case Enums.MapType.Grass:
            case Enums.MapType.Water:
                this.isPass = true;
                break;
            }
        }
Example #4
0
 public MapElement(int x, int y, Enums.MapType type)
     : base(x, y, SetImg(type))
 {
     this.mapType = type;
     SetIsPass(type);
 }