Exemplo n.º 1
0
 public Save(List <Chapter> chaps, int nbPlay, StringIntDictionary mInt, StringFloatDictionary mFloat, SerializableDate dt)
 {
     chapters     = chaps;
     nbPlayer     = nbPlay;
     metaInt      = mInt;
     metaFloat    = mFloat;
     lastOpenDate = dt;
 }
Exemplo n.º 2
0
    /// <summary>
    /// Creates a Json file representing the empty save at the index "save"
    /// </summary>
    /// <param name="save"></param>
    /// <param name="nbPlayer"></param>
    public void CreateSaveFile(int save, int nbPlayer)
    {
        //création du file
        StreamWriter streamWriter = File.CreateText(Application.persistentDataPath + "/Saves/SaveFile" + save + ".json");

        //création des dictionnaires de metadonnées
        StringIntDictionary mInt = new StringIntDictionary();

        mInt.Add("jumpNumber1", 0);
        mInt.Add("playerDeath1", 0);

        StringFloatDictionary mFloat = new StringFloatDictionary();

        mFloat.Add("distance1", 0);
        mFloat.Add("totalTimePlayed", 0);

        List <Chapter> chapters = new List <Chapter>();

        if (nbPlayer == 1)
        {
            //On créer les chapitres et les tableaux, puis on l'écrit sur le nouveau fichier.
            List <Level> lvlPrologque_Solo = new List <Level>();
            lvlPrologque_Solo.Add(new Level(false, new bool[] { }, new bool[] { }, true));
            lvlPrologque_Solo.Add(new Level(false, new bool[] { }, new bool[] { }, false));
            lvlPrologque_Solo.Add(new Level(false, new bool[] { }, new bool[] { }, false));
            lvlPrologque_Solo.Add(new Level(false, new bool[] { }, new bool[] { }, false));
            lvlPrologque_Solo.Add(new Level(false, new bool[] { }, new bool[] { }, false));

            List <Level> lvlChap1_Solo = new List <Level>();
            lvlChap1_Solo.Add(new Level(false, new bool[] { }, new bool[] { }, true));        //0   - The entrance - 2 Collectibles
            lvlChap1_Solo.Add(new Level(false, new bool[] { false }, new bool[] { }, false)); //1
            lvlChap1_Solo.Add(new Level(false, new bool[] { }, new bool[] { }, false));       //2
            lvlChap1_Solo.Add(new Level(false, new bool[] { }, new bool[] { }, false));       //3
            lvlChap1_Solo.Add(new Level(false, new bool[] { }, new bool[] { }, false));       //4
            lvlChap1_Solo.Add(new Level(false, new bool[] { }, new bool[] { }, false));       //5
            lvlChap1_Solo.Add(new Level(false, new bool[] { false }, new bool[] { }, false)); //6
            lvlChap1_Solo.Add(new Level(false, new bool[] { }, new bool[] { }, true));        //7   - The room of a thousand stairs - 2 Collectibles
            lvlChap1_Solo.Add(new Level(false, new bool[] { }, new bool[] { }, false));       // GhostRoom
            lvlChap1_Solo.Add(new Level(false, new bool[] { }, new bool[] { }, false));       //8
            lvlChap1_Solo.Add(new Level(false, new bool[] { }, new bool[] { }, false));       //9
            lvlChap1_Solo.Add(new Level(false, new bool[] { }, new bool[] { }, false));       //10
            lvlChap1_Solo.Add(new Level(false, new bool[] { }, new bool[] { }, false));       //11
            lvlChap1_Solo.Add(new Level(false, new bool[] { false }, new bool[] { }, false)); //12
            lvlChap1_Solo.Add(new Level(false, new bool[] { false }, new bool[] { }, false)); //13
            lvlChap1_Solo.Add(new Level(false, new bool[] { }, new bool[] { }, true));        //14 - The second encounter - 3 Collectibles
            lvlChap1_Solo.Add(new Level(false, new bool[] { }, new bool[] { }, false));       //15
            lvlChap1_Solo.Add(new Level(false, new bool[] { false }, new bool[] { }, false)); //16
            lvlChap1_Solo.Add(new Level(false, new bool[] { }, new bool[] { }, false));       //17
            lvlChap1_Solo.Add(new Level(false, new bool[] { }, new bool[] { }, false));       //18
            lvlChap1_Solo.Add(new Level(false, new bool[] { false }, new bool[] { }, false)); //19
            lvlChap1_Solo.Add(new Level(false, new bool[] { false }, new bool[] { }, false)); //20
            lvlChap1_Solo.Add(new Level(false, new bool[] { }, new bool[] { }, false));       //21
            lvlChap1_Solo.Add(new Level(false, new bool[] { }, new bool[] { }, false));       //22
            lvlChap1_Solo.Add(new Level(false, new bool[] { }, new bool[] { }, true));        //  - Fresh air - 4 Collectibles
            lvlChap1_Solo.Add(new Level(false, new bool[] { }, new bool[] { }, false));       //23
            lvlChap1_Solo.Add(new Level(false, new bool[] { false }, new bool[] { }, false)); //24
            lvlChap1_Solo.Add(new Level(false, new bool[] { false }, new bool[] { }, false)); //25
            lvlChap1_Solo.Add(new Level(false, new bool[] { false }, new bool[] { }, false)); //26
            lvlChap1_Solo.Add(new Level(false, new bool[] { }, new bool[] { }, false));       //27
            lvlChap1_Solo.Add(new Level(false, new bool[] { }, new bool[] { }, false));       //28
            lvlChap1_Solo.Add(new Level(false, new bool[] { }, new bool[] { }, false));       //29
            lvlChap1_Solo.Add(new Level(false, new bool[] { false }, new bool[] { }, false)); //30
            lvlChap1_Solo.Add(new Level(false, new bool[] { }, new bool[] { }, true));        //31 - The third encounter - 3 Collectibles
            lvlChap1_Solo.Add(new Level(false, new bool[] { }, new bool[] { }, false));       //32
            lvlChap1_Solo.Add(new Level(false, new bool[] { false }, new bool[] { }, false)); //33
            lvlChap1_Solo.Add(new Level(false, new bool[] { false }, new bool[] { }, false)); //34
            lvlChap1_Solo.Add(new Level(false, new bool[] { }, new bool[] { }, false));       //35
            lvlChap1_Solo.Add(new Level(false, new bool[] { false }, new bool[] { }, false)); //36
            lvlChap1_Solo.Add(new Level(false, new bool[] { }, new bool[] { }, true));        //37 - The show - 0 Collectibles
            lvlChap1_Solo.Add(new Level(false, new bool[] { }, new bool[] { }, false));       //38
            lvlChap1_Solo.Add(new Level(false, new bool[] { }, new bool[] { }, false));       //39
            lvlChap1_Solo.Add(new Level(false, new bool[] { }, new bool[] { }, false));       //40
            lvlChap1_Solo.Add(new Level(false, new bool[] { }, new bool[] { }, false));       //41
            lvlChap1_Solo.Add(new Level(false, new bool[] { }, new bool[] { }, false));       //42
            lvlChap1_Solo.Add(new Level(false, new bool[] { }, new bool[] { }, true));        //43 - The confrontation - 0 Collectibles

            chapters.Add(new Chapter(lvlPrologque_Solo));
            chapters.Add(new Chapter(lvlChap1_Solo));
        }

        if (nbPlayer == 2)
        {
            mInt.Add("jumpNumber2", 0);
            mInt.Add("playerDeath2", 0);
            mFloat.Add("distance2", 0);

            //On créer les chapitres et les tableaux, puis on l'écrit sur le nouveau fichier.
            List <Level> lvlPrologque_Duo = new List <Level>();
            lvlPrologque_Duo.Add(new Level(false, new bool[] { }, new bool[] { }, true));
            lvlPrologque_Duo.Add(new Level(false, new bool[] { }, new bool[] { }, false));
            lvlPrologque_Duo.Add(new Level(false, new bool[] { }, new bool[] { }, false));
            lvlPrologque_Duo.Add(new Level(false, new bool[] { }, new bool[] { }, false));
            lvlPrologque_Duo.Add(new Level(false, new bool[] { }, new bool[] { }, false));

            List <Level> lvlChap1_Duo = new List <Level>();
            lvlChap1_Duo.Add(new Level(false, new bool[] { }, new bool[] { }, true));              //0   - The entrance - 2 Collectibles
            lvlChap1_Duo.Add(new Level(false, new bool[] { }, new bool[] { false }, false));       //1
            lvlChap1_Duo.Add(new Level(false, new bool[] { }, new bool[] { }, false));             //2
            lvlChap1_Duo.Add(new Level(false, new bool[] { }, new bool[] { }, false));             //3
            lvlChap1_Duo.Add(new Level(false, new bool[] { }, new bool[] { }, false));             //4
            lvlChap1_Duo.Add(new Level(false, new bool[] { }, new bool[] { }, false));             //5
            lvlChap1_Duo.Add(new Level(false, new bool[] { }, new bool[] { false }, false));       //6
            lvlChap1_Duo.Add(new Level(false, new bool[] { }, new bool[] { }, true));              //7   - The room of a thousand stairs - 4 Collectibles
            lvlChap1_Duo.Add(new Level(false, new bool[] { }, new bool[] { }, false));             // GhostRoom
            lvlChap1_Duo.Add(new Level(false, new bool[] { }, new bool[] { }, false));             //8
            lvlChap1_Duo.Add(new Level(false, new bool[] { }, new bool[] { false }, false));       //9
            lvlChap1_Duo.Add(new Level(false, new bool[] { }, new bool[] { }, false));             //10
            lvlChap1_Duo.Add(new Level(false, new bool[] { }, new bool[] { }, false));             //11
            lvlChap1_Duo.Add(new Level(false, new bool[] { false }, new bool[] { false }, false)); //12
            lvlChap1_Duo.Add(new Level(false, new bool[] { false }, new bool[] { }, false));       //13
            lvlChap1_Duo.Add(new Level(false, new bool[] { }, new bool[] { }, true));              //14 - The second encounter - 3 Collectibles
            lvlChap1_Duo.Add(new Level(false, new bool[] { }, new bool[] { }, false));             //15
            lvlChap1_Duo.Add(new Level(false, new bool[] { false }, new bool[] { }, false));       //16
            lvlChap1_Duo.Add(new Level(false, new bool[] { }, new bool[] { }, false));             //17
            lvlChap1_Duo.Add(new Level(false, new bool[] { }, new bool[] { }, false));             //18
            lvlChap1_Duo.Add(new Level(false, new bool[] { false }, new bool[] { }, false));       //19
            lvlChap1_Duo.Add(new Level(false, new bool[] { }, new bool[] { false }, false));       //20
            lvlChap1_Duo.Add(new Level(false, new bool[] { }, new bool[] { }, false));             //21
            lvlChap1_Duo.Add(new Level(false, new bool[] { }, new bool[] { }, false));             //22
            lvlChap1_Duo.Add(new Level(false, new bool[] { }, new bool[] { }, true));              //  - Fresh air - 5 Collectibles
            lvlChap1_Duo.Add(new Level(false, new bool[] { }, new bool[] { }, false));             //23
            lvlChap1_Duo.Add(new Level(false, new bool[] { }, new bool[] { }, false));             //24
            lvlChap1_Duo.Add(new Level(false, new bool[] { false }, new bool[] { }, false));       //25
            lvlChap1_Duo.Add(new Level(false, new bool[] { false }, new bool[] { false }, false)); //26
            lvlChap1_Duo.Add(new Level(false, new bool[] { }, new bool[] { }, false));             //27
            lvlChap1_Duo.Add(new Level(false, new bool[] { }, new bool[] { }, false));             //28
            lvlChap1_Duo.Add(new Level(false, new bool[] { }, new bool[] { }, false));             //29
            lvlChap1_Duo.Add(new Level(false, new bool[] { false }, new bool[] { false }, false)); //30
            lvlChap1_Duo.Add(new Level(false, new bool[] { }, new bool[] { }, true));              //31 - The third encounter - 4 Collectibles
            lvlChap1_Duo.Add(new Level(false, new bool[] { }, new bool[] { }, false));             //32
            lvlChap1_Duo.Add(new Level(false, new bool[] { }, new bool[] { false }, false));       //33
            lvlChap1_Duo.Add(new Level(false, new bool[] { false }, new bool[] { }, false));       //34
            lvlChap1_Duo.Add(new Level(false, new bool[] { }, new bool[] { }, false));             //35
            lvlChap1_Duo.Add(new Level(false, new bool[] { false }, new bool[] { false }, false)); //36
            lvlChap1_Duo.Add(new Level(false, new bool[] { }, new bool[] { }, true));              //37 - The show - 0 Collectibles
            lvlChap1_Duo.Add(new Level(false, new bool[] { }, new bool[] { }, false));             //38
            lvlChap1_Duo.Add(new Level(false, new bool[] { }, new bool[] { }, false));             //39
            lvlChap1_Duo.Add(new Level(false, new bool[] { }, new bool[] { }, false));             //40
            lvlChap1_Duo.Add(new Level(false, new bool[] { }, new bool[] { }, false));             //41
            lvlChap1_Duo.Add(new Level(false, new bool[] { }, new bool[] { }, false));             //42
            lvlChap1_Duo.Add(new Level(false, new bool[] { }, new bool[] { }, true));              //43 - The confrontation - 0 Collectibles

            chapters.Add(new Chapter(lvlPrologque_Duo));
            chapters.Add(new Chapter(lvlChap1_Duo));
        }


        // chapters.Add(new Chapter(lvlChap1));

        //enfin, on créer la save qui contient toutes les informations
        Save createdSave = new Save(chapters, nbPlayer, mInt, mFloat, new SerializableDate(DateTime.Now));


        string saveFileContent = JsonUtility.ToJson(createdSave, true);

        //On rempli le nouveau SaveFile
        streamWriter.Write(saveFileContent);
        streamWriter.Close();

        LoadSaveFile(save);
    }