Ejemplo n.º 1
0
    private static MapSer CreatedMap()
    {
        string          deviceFileLocation = Application.persistentDataPath + "/" + "createdMaps.bat";
        BinaryFormatter bf   = new BinaryFormatter();
        FileStream      file = File.Open(deviceFileLocation, FileMode.Open);
        CreatedMaps     maps = (CreatedMaps)bf.Deserialize(file);

        file.Close();

        MapSer[] datas = new MapSer[maps.maps.Length + 1];
        for (int i = 0; i < maps.maps.Length; i++)
        {
            datas[i] = maps.maps[i];
        }
        return(datas[ActualMapData.createdMapIndex]);
    }
Ejemplo n.º 2
0
 public static void CalculateItemsMapSer(MapSer map)
 {
     for (int i = 0; i < map.heigth; i++)
     {
         for (int j = 0; j < map.width; j++)
         {
             if (map.mapMatrix[i, j] == Button)
             {
                 map.buttonCount++;
             }
             else if (map.mapMatrix[i, j] == LSwitch)
             {
                 map.laserSwitchCount++;
             }
         }
     }
 }
Ejemplo n.º 3
0
    private void Save(MapSer map)
    {
        MapSer[] datas = Read();
        datas[datas.Length - 1] = map;

        BinaryFormatter bf   = new BinaryFormatter();
        FileStream      file = File.Open(deviceCreatedMapFileLocation, FileMode.Open);
        CreatedMaps     data = (CreatedMaps)bf.Deserialize(file);

        file.Close();

        data.maps = datas;

        FileStream fileForSave = File.Create(deviceCreatedMapFileLocation);

        bf.Serialize(fileForSave, data);
        fileForSave.Close();
    }
Ejemplo n.º 4
0
    private static Map ConvertToMap(MapSer mapSer)
    {
        Map map = new Map();

        map.startPosition = new Vector3(mapSer.startPosition.x, mapSer.startPosition.y, mapSer.startPosition.z);
        map.charPosition  = new Vector3(mapSer.charPosition.x, mapSer.charPosition.y, mapSer.charPosition.z);
        map.mapMatrix     = mapSer.mapMatrix;
        map.heigth        = map.mapMatrix.GetLength(0);
        map.width         = map.mapMatrix.GetLength(1);
        map.boxNumber     = mapSer.boxNumber;
        map.boxLocations  = new Vector3[map.boxNumber];
        for (int i = 0; i < map.boxNumber; i++)
        {
            map.boxLocations[i] = new Vector3(mapSer.boxLocations[i].x, mapSer.boxLocations[i].y, mapSer.boxLocations[i].z);
        }
        map.Scarab3PartNumber = mapSer.Scarab3PartNumber;
        map.Scarab2PartNumber = mapSer.Scarab2PartNumber;
        map.itemType          = mapSer.itemType;
        return(map);
    }
Ejemplo n.º 5
0
    private MapSer[] Read()
    {
        if (File.Exists(deviceCreatedMapFileLocation))
        {
            BinaryFormatter bf   = new BinaryFormatter();
            FileStream      file = File.Open(deviceCreatedMapFileLocation, FileMode.Open);
            CreatedMaps     maps = (CreatedMaps)bf.Deserialize(file);
            file.Close();

            MapSer[] datas;
            if (maps.maps == null)
            {
                datas = new MapSer[1];
                return(datas);
            }
            else
            {
                datas = new MapSer[maps.maps.Length + 1];
            }
            for (int i = 0; i < maps.maps.Length; i++)
            {
                datas[i] = maps.maps[i];
            }
            return(datas);
        }
        else
        {
            BinaryFormatter bf   = new BinaryFormatter();
            FileStream      file = File.Open(deviceCreatedMapFileLocation, FileMode.Create);
            CreatedMaps     data = new CreatedMaps();
            data.maps = new MapSer[1];
            bf.Serialize(file, data);
            file.Close();

            return(new MapSer[1]);
        }
    }
Ejemplo n.º 6
0
    public void SaveMap()
    {
        MapSer map = new MapSer();

        map.name = saveName.text;
        map.Scarab2PartNumber = Convert.ToInt32(scarab2part.text);
        map.Scarab3PartNumber = Convert.ToInt32(scarab3part.text);

        int plusEdges = boxes.Count + 1;

        MapElement[,] mapElements = new MapElement[webCreator.RowCount + 2 * plusEdges, webCreator.ColumnCount + 2 * plusEdges];
        for (int i = plusEdges; i < webCreator.RowCount + plusEdges; i++)
        {
            for (int j = plusEdges; j < webCreator.ColumnCount + plusEdges; j++)
            {
                mapElements[i, j] = actMap[i - plusEdges, j - plusEdges];
            }
        }

        map.startPosition = new Vector3Ser(startPosition.x - plusEdges * SharedData.widhtUnit, startPosition.y, startPosition.z + plusEdges * SharedData.widhtUnit);

        Vector3 extraDistance = new Vector3(-1, 0, 1) * plusEdges * SharedData.widhtUnit;

        float charPositionX = startPosition.x + (joeMEB.Column + plusEdges) * SharedData.widhtUnit + extraDistance.x;
        float charPositionY = startPosition.y + joeMEB.PlaceHeight;
        float charPositionZ = startPosition.z - (joeMEB.Row + plusEdges) * SharedData.widhtUnit + extraDistance.z;

        map.charPosition = new Vector3Ser(charPositionX, charPositionY, charPositionZ);
        map.mapMatrix    = mapElements;
        map.heigth       = map.mapMatrix.GetLength(0);
        map.width        = map.mapMatrix.GetLength(1);
        map.boxNumber    = boxes.Count;
        map.boxLocations = new Vector3Ser[boxes.Count];
        for (int i = 0; i < boxes.Count; i++)
        {
            MapElementBox boxME        = boxes[i].GetComponent <MapElementBox>();
            float         boxLocationX = startPosition.x + (boxME.Column + plusEdges) * SharedData.widhtUnit + extraDistance.x;
            float         boxLocationY = startPosition.y + boxME.PlaceHeight;
            float         boxLocationZ = startPosition.z - (boxME.Row + plusEdges) * SharedData.widhtUnit + extraDistance.z;
            map.boxLocations[i] = new Vector3Ser(boxLocationX, boxLocationY, boxLocationZ);
        }

        if (itemType == MapElement.Key)
        {
            map.itemType = SharedData.KeyType;
        }
        else if (itemType == MapElement.Gem)
        {
            map.itemType = SharedData.GemType;
        }
        else if (itemType == MapElement.Relic)
        {
            map.itemType = SharedData.RelicType;
        }
        else
        {
            map.itemType = SharedData.DefaultType;
        }

        MapCollection.CalculateItemsMapSer(map);

        Save(map);

        SceneLoader.LoadSceneStatic(GameStructure.extraSceneName);
    }