示例#1
0
文件: Program.cs 项目: vblz/TankFight
        private static IMapInfo GenerateMapInfo()
        {
            var data = JsonConvert.DeserializeObject <JObject>(File.ReadAllText(@"d:/maps/1/objects.json"));
            var map  = new MapInfo
            {
                Height = data["Height"].Value <byte>(),
                Width  = data["Width"].Value <byte>(),
            };

            List <ICellContentInfo> objects = new List <ICellContentInfo>();

            foreach (var mapObject in data["MapObjects"].Children())
            {
                var x = mapObject["Coordinates"]["X"].Value <int>();
                var y = mapObject["Coordinates"]["Y"].Value <int>();

                switch (mapObject["CellContentType"].Value <string>())
                {
                case "Barrier":
                    byte health = mapObject["HealthCount"].Value <byte>();
                    objects.Add(CellContentInfo.Barrier(x, y, health));
                    break;

                case "NotDestroyable":
                    objects.Add(CellContentInfo.Mountain(x, y));
                    break;

                case "Spawn":
                    objects.Add(CellContentInfo.Spawn(x, y));
                    break;

                case "Water":
                    objects.Add(CellContentInfo.Water(x, y));
                    break;
                }
            }


            objects.Add(CellContentInfo.Spawn(1, 1));
            objects.Add(CellContentInfo.Spawn(1, 2));

            map.MapObjects = objects.AsReadOnly();
            return(map);
        }
示例#2
0
        private IMapInfo LoadMap(BattleInfo loadingBattleInfo)
        {
            // FIXME код из TestConsole. Отрефакторить.
            var data = JsonConvert.DeserializeObject <JObject>(File.ReadAllText(Path.Combine(loadingBattleInfo.Map, "objects.json")));
            var map  = new MapInfo
            {
                Height = data["Height"].Value <byte>(),
                Width  = data["Width"].Value <byte>(),
            };

            List <ICellContentInfo> objects = new List <ICellContentInfo>();

            foreach (var mapObject in data["MapObjects"].Children())
            {
                var x = mapObject["Coordinates"]["X"].Value <int>();
                var y = mapObject["Coordinates"]["Y"].Value <int>();

                switch (mapObject["CellContentType"].Value <string>())
                {
                case "Barrier":
                    byte health = mapObject["HealthCount"].Value <byte>();
                    objects.Add(CellContentInfo.Barrier(x, y, health));
                    break;

                case "NotDestroyable":
                    objects.Add(CellContentInfo.Mountain(x, y));
                    break;

                case "Spawn":
                    objects.Add(CellContentInfo.Spawn(x, y));
                    break;

                case "Water":
                    objects.Add(CellContentInfo.Water(x, y));
                    break;
                }
            }

            map.MapObjects = objects.AsReadOnly();
            return(map);
        }