//Loads the game state that was saved public static void Load() { if (File.Exists(Application.persistentDataPath + "/PlayerMathsInfo.dat")) { BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Open(Application.persistentDataPath + "/playerMathsInfo.dat", FileMode.Open); PlayerData data = (PlayerData)(bf.Deserialize(file)); file.Close(); level = data.level; highScore = data.highScore; //EnumBase.GameChoice gameChoice = data.gameChoice; difficulties = data.difficulties; SceneManager.LoadScene(PlayerPrefs.GetInt("Level")); } else if (File.Exists(Application.persistentDataPath + "/PlayerPuzzleInfo.dat")) { BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Open(Application.persistentDataPath + "/PlayerPuzzleInfo.dat", FileMode.Open); PlayerData data = new PlayerData(); file.Close(); level = data.level; highScore = data.highScore; difficulties = data.difficulties; //EnumBase.GameChoice gameChoice = data.gameChoice; SceneManager.LoadScene(PlayerPrefs.GetInt("Level")); } }
public PuzzleData GetPuzzleQuestion(EnumBase.Difficulties Difficulty, int Level) { puzzleData = new List <PuzzleData>(); switch (Difficulty) { case EnumBase.Difficulties.easy: fileName = "EasyLevel" + Level; fileData = Resources.Load <TextAsset>(fileName); puzzleData = JsonConvert.DeserializeObject <List <PuzzleData> >(fileData.text); System.Random rand = new System.Random(); int index = rand.Next(0, 3); return(puzzleData[index]); case EnumBase.Difficulties.medium: fileName = "MediumLevel" + Level; fileData = Resources.Load <TextAsset>(fileName); puzzleData = JsonConvert.DeserializeObject <List <PuzzleData> >(fileData.text); System.Random random = new System.Random(); int i = random.Next(0, 3); return(puzzleData[i]); case EnumBase.Difficulties.hard: fileName = "HardLevel" + Level; fileData = Resources.Load <TextAsset>(fileName); puzzleData = JsonConvert.DeserializeObject <List <PuzzleData> >(fileData.text); System.Random randomm = new System.Random(); int num = randomm.Next(0, 3); return(puzzleData[num]); } return(puzzleData[0]); }
public static LevelModel LevelDifficulty(EnumBase.Difficulties difficulties, int level) { LevelModel model = new LevelModel(); switch (difficulties) { case EnumBase.Difficulties.easy: if (difficulties == EnumBase.Difficulties.easy && level > 0 && level < 5) { model.operators = new List <string>() { "+", "-", "/", "*" }; model.minNumber = 1; model.maxNUmber = 10; model.operatorIndex = 1; } else if (difficulties == EnumBase.Difficulties.easy && level >= 5 && level < 9) { model.operators = new List <string>() { "+", "-" }; model.minNumber = 1; model.maxNUmber = 20; model.operatorIndex = 1; } else if (difficulties == EnumBase.Difficulties.easy && level >= 9 && level < 13) { model.operators = new List <string>() { "+", "-" }; model.minNumber = 1; model.maxNUmber = 100; model.operatorIndex = 1; } break; case EnumBase.Difficulties.medium: if (difficulties == EnumBase.Difficulties.medium && level > 0 && level < 5) { model.operators = new List <string>() { "+", "-" }; model.minNumber = 1; model.maxNUmber = 100; model.operatorIndex = 1; } else if (difficulties == EnumBase.Difficulties.medium && level >= 5 && level < 9) { model.operatorIndex = 1; model.operators = new List <string>() { "+", "-" }; model.minNumber = 1; model.maxNUmber = 100; model.operatorIndex = 1; } else if (difficulties == EnumBase.Difficulties.medium && level >= 9 && level < 13) { model.operators = new List <string>() { "+", "-", "*", "/" }; model.minNumber = 1; model.maxNUmber = 100; model.operatorIndex = 2; } break; case EnumBase.Difficulties.hard: if (difficulties == EnumBase.Difficulties.hard && level > 0 && level < 5) { model.operators = new List <string>() { "+", "-", "*", "/" }; model.minNumber = 1; model.maxNUmber = 100; model.operatorIndex = 2; } else if (difficulties == EnumBase.Difficulties.hard && level >= 5 && level < 9) { model.operatorIndex = 2; model.operators = new List <string>() { "+", "-", "*", "/" }; model.minNumber = 1; model.maxNUmber = 100; } else if (difficulties == EnumBase.Difficulties.hard && level >= 9 && level < 13) { model.operatorIndex = 2; model.operators = new List <string>() { "+", "-", "*", "/" }; model.minNumber = 1; model.maxNUmber = 100; } break; default: break; } return(model); }