示例#1
0
        public static AbstractMap2D Load(string mapName)
        {
            AbstractMap2D loadedMap = new AbstractMap2D();

            string loadedData = LoadMapWithFileName(mapName);

            loadedMap = ParseJSONMapToAbstractMap2D.ParseJSONMap(loadedData);

            return loadedMap;
        }
示例#2
0
        // Methods
        public static Dictionary<string, object> Build(AbstractMap2D abstractMap)
        {
            MapBuilder.AbstractMap = abstractMap;
            Dictionary<string, object> buildedMapDict = new Dictionary<string, object>();
            buildedMapDict["Difficulty"] = BuildDifficulty();
            buildedMapDict["Size"] = BuildSize();
            buildedMapDict["Origin"] = BuildOrigin();
            buildedMapDict["GameObjects"] = BuildGameObjects();
            buildedMapDict["Name"] = BuildName();
            buildedMapDict["TimeLimit"] = BuildTimeLimit();
            buildedMapDict["MoveLimit"] = BuildMoveLimit();

            return buildedMapDict;
        }
示例#3
0
        // Methods
        public static AbstractMap2D Load(string mapName, string sourceType = "file/JSON")
        {
            ClearLoadedMap();
            switch (sourceType)
            {
                case "file/JSON":
                    MapLoader.LoadedMap = FileJSONMapLoader.Load(mapName);
                    break;
                case "hardcodedTest":
                    MapLoader.LoadedMap = HardcodedMapLoader.Load(mapName);
                    break;
                default:
                    throw new WrongSourceTypeException("The Source type: '{0}' is spelled incorrectly or such type does not exist.", sourceType);
            }

            return MapLoader.LoadedMap;
        }
        public static AbstractMap2D ParseJSONMap(string jsonText)
        {
            // Get the JSON Object
            JObject jsonData = JObject.Parse(jsonText);

            string mapName = ParseName(jsonData);
            int[] size = ParseSize(jsonData);
            int[] origin = ParseOrigin(jsonData);
            string difficulty = ParseDifficulty(jsonData);
            int timeLimit = ParseTimeLimit(jsonData);
            int moveLimit = ParseMoveLimit(jsonData);

            // Game Objects
            Dictionary<string, List<int[]>> gameObjects = ParseGameObjects(jsonData);

            // Create the AbstractMap
            AbstractMap2D parsedAbstractMap = new AbstractMap2D(mapName, gameObjects, size, origin, difficulty, timeLimit, moveLimit);

            return parsedAbstractMap;
        }
示例#5
0
文件: Map.cs 项目: Bezideiko/OOP
        // Build Map
        private void MapBuilderDirector(AbstractMap2D loadedMap)
        {
            Dictionary<string, object> buildedMap = MapBuilder.Build(loadedMap);

            // Assign the current map properties
            AssignProperties(buildedMap);
        }
示例#6
0
        private static AbstractMap2D ParseMapFromCharMatix(Dictionary<string, object> mapDict)
        {
            // Init Map meta properties
            char[,] charMap = (char[,])mapDict["Map"];
            int[] origin = new int[] { 0, 0 };
            int[] size = new int[] { charMap.GetLength(1), charMap.GetLength(0) };
            string difficulty = "test";
            string name = "Test Level";
            int timeLimit = (int)mapDict["TimeLimit"];
            int moveLimit = (int)mapDict["MoveLimit"];

            Dictionary<string, List<int[]>> gameObjects = new Dictionary<string, List<int[]>>();

            for (int y = 0; y < charMap.GetLength(0); y++)
            {
                for (int x = 0; x < charMap.GetLength(1); x++)
                {

                    string type = "";
                    char charSymbol = charMap[y, x];
                    if (CharToObjectTypesDict.ContainsKey(charSymbol))
                    {
                        type = CharToObjectTypesDict[charSymbol];
                        int[] objectCoordinates = new int[]{x, y};
                        if (!gameObjects.ContainsKey(type))
                        {
                            gameObjects[type] = new List<int[]>();
                        }
                        gameObjects[type].Add(objectCoordinates);
                    }
                    else
                    {
                        throw new UnknownSymbolInHardcodedMapException("Unknown char symbol: '{0}' in Hardcoded map: '{1}'",
                            charSymbol, HardcodedMapLoader.MapName);
                    }
                }
            }

            AbstractMap2D parsedMap = new AbstractMap2D(name, gameObjects, size, origin, difficulty, timeLimit, moveLimit);

            return parsedMap;
        }