public void SetLevel(int level) { audioHandler.PlayUISound(); levelID = level; ui.scoreText.text = "Score: 0"; fourPopped = false; ui.levelCanvas.enabled = false; ui.hud.enabled = true; ui.SetButtons(false, false, false); ui.victoryImage.enabled = false; ui.loseImage.enabled = false; ui.loseImage.color = new Color(1f, 1f, 1f, 0f); LevelObjectiveData ehe = GetLevelData(); LoadLevel(ehe); ui.FlashText(ui.levelText, "Level " + levelID.ToString(), 1f, 1f); ui.FlashText(ui.headerText, objectiveHeader, 1f, 1f); ui.FlashText(ui.footerText, objectiveInfo, 1f, 1f); ui.tapToResumeButton.SetActive(true); }
public LevelObjectiveData(LevelObjectiveData meta) { LevelID = meta.LevelID; ObjectiveId = meta.ObjectiveId; ObjectiveScore = meta.ObjectiveScore; ObjectiveColor = meta.ObjectiveColor; ColorCount = meta.ColorCount; Title = meta.Title; Info = meta.Info; ObjectiveCount = meta.ObjectiveCount; Time = meta.Time; TutorialText = meta.TutorialText; TutorialTitle = meta.TutorialTitle; BubbleSpeed = meta.BubbleSpeed; FastBubbleTimer = meta.FastBubbleTimer; }
LevelObjectiveData GetLevelData() { string levelPrefabString = "Levels/" + "Level_" + levelID; TextAsset jsonAsset = Resources.Load(levelPrefabString) as TextAsset; if (jsonAsset != null) { string jsonText = jsonAsset.text; var meta = JsonConvert.DeserializeObject <LevelObjectiveData>(jsonText); lastLevelData = new LevelObjectiveData(meta); return(lastLevelData); } throw new System.Exception("Level Asset couldn't be loaded : " + levelPrefabString); }
public static int RateLevel(PopulationManager populationManager, LevelObjectiveData objective) { // Get an array of species stability data SpeciesStability[] speciesStabilities = ComputeSpeciesStability(populationManager, objective); // Return the best score if all species are stable if (speciesStabilities.All(species => species.isStable)) { return(2); } // Return medium score if some species are stable else if (speciesStabilities.Any(species => species.isStable)) { return(1); } // Return worst score if no species are stable else { return(0); } }
void LoadLevel(LevelObjectiveData leveldata) { objectiveColorList = new List <string>(); string[] words = Regex.Split(leveldata.ObjectiveColor, "-"); if (words.Length > 0 && words[0] != "") { foreach (string word in words) { objectiveColorList.Add(word.ToUpper()); } } score = 0; objectiveID = leveldata.ObjectiveId; objectiveScore = leveldata.ObjectiveScore; gemspawn.maxGem = leveldata.ColorCount; objectiveHeader = leveldata.Title; objectiveInfo = leveldata.Info; objectiveCount = leveldata.ObjectiveCount; objectiveTime = leveldata.Time; ObjectiveBubbleSpeed = leveldata.BubbleSpeed; gemspawn.ChangeBubbleSpeeds(ObjectiveBubbleSpeed); timer = objectiveTime; tutorialText = leveldata.TutorialText; tutorialTitle = leveldata.TutorialTitle; ui.timerText.text = ""; ui.scoreText.text = "0/" + objectiveScore; gemspawn.levelSpecialGemTime = leveldata.FastBubbleTimer; gemspawn.SetFastBubbleTimer(); if (objectiveColorList.Count > 0) { objectiveImage.SetImage(objectiveColorList[0], objectiveID, objectiveCount); } else { objectiveImage.SetImage("WHITE", objectiveID, objectiveCount); } }
public static SpeciesStability[] ComputeSpeciesStability(PopulationManager populationManager, LevelObjectiveData objective) { // Project the minimums of the species out several days SpeciesCount[] speciesCounts = ProjectNextSpeciesCount(populationManager); // Create the array to return SpeciesStability[] speciesStabilities = new SpeciesStability[speciesCounts.Length]; // Compute the stability of each species based on the projected minimum for (int i = 0; i < speciesCounts.Length; i++) { SpeciesType species = speciesCounts[i].species; // Add up the target population for every data that has the same species int targetAmount = objective.survivalObjectiveDatas .Where(data => data.targetSpecies.Species == species) .Sum(data => data.targetPopulationSize); // Species is stable if the projected minimum // is bigger than or equal to the target amount speciesStabilities[i] = new SpeciesStability() { species = species, isStable = speciesCounts[i].count >= targetAmount }; } return(speciesStabilities); }