public static List <int> GenerateRandomNumbers(List <string> operatorValue) { List <int> values = new List <int>(); System.Random rnd = new System.Random(); //Populate List model = LevelController.LevelDifficulty(difficulties, level); //values[0] = 2 * rnd.Next(model.minNumber / 2, model.maxNUmber / 2); for (int i = 0; i < model.operatorIndex; i++) { values.Add(0); values[i] = rnd.Next(model.minNumber, model.maxNUmber); } values.Add(0); for (int i = 0; i < model.operatorIndex; i++) { if (operatorValue[i] == "/") { values[i + 1] = GetDivisibleNumber(values[i], model.minNumber); } values[i + 1] = rnd.Next(model.minNumber, model.maxNUmber); } return(values); }
public static int GetTopPerLevel(this LevelModel model) { if (!PlayerPrefs.HasKey(model.tag)) { PlayerPrefs.SetInt(model.tag, 0); } return(PlayerPrefs.GetInt(model.tag)); }
private void OnLevelStart() { EventManager.Get <LevelStartEvent> ().Unsubscribe(OnLevelStart); _currentLevel = (LevelController)FindObjectOfType(typeof(LevelController)); _levelModel = new LevelModel(_currentLevelData); _currentLevel.Attach(_levelModel); _levelModel.Start(); }
//returns a random operator public List <string> GetOperator() { model = LevelController.LevelDifficulty(difficulties, level); int operatorCount = model.operators.Count; List <string> operatorInUse = new List <string>(); for (int i = 0; i < model.operatorIndex; i++) { System.Random rnd = new System.Random(); int index = rnd.Next(operatorCount); operatorInUse.Add(model.operators[index]); } return(operatorInUse); }
public void ShowQuestion() { canJump = false; UIManager.instance.questionPanel.SetActive(true); UIManager.instance.panel.SetActive(true); UIManager.instance.questionBackground.SetActive(true); UIManager.instance.OptionBtn1.onClick.RemoveAllListeners(); UIManager.instance.OptionBtn2.onClick.RemoveAllListeners(); UIManager.instance.OptionBtn3.onClick.RemoveAllListeners(); LevelModel model = LevelController.LevelDifficulty(difficulties, level); List <string> getOperator = GetOperator(); List <int> values = GenerateRandomNumbers(getOperator); List <float> floatValues = convertIntegersTofloat(values); UIManager.instance.question.text = DataLogic.GenerateQuestionString(values, getOperator); answer = GetCorrectAnswer(floatValues, getOperator); AssignButtonEvents(); }
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); }
public static void SaveTopPerLevel(this LevelModel model, int topScore) { PlayerPrefs.SetInt(model.tag, topScore); }