void SaveLevelToFile(ValidLevels level) { if (fp == null) { fp = new ValidSeedListFileParse(); } fp.SerializeALevel(level); }
void LoadNewLevel(ValidLevels _aSpecificLevel, bool isFromAppointment) { // if this isn't a level from the clipboard, it needs to be set as the clipboard's nextLevelUp b/c that's where the NetworkMgr looks for it if (!isFromAppointment) { gameManager.GetClipboard().GetNextLevelUp().myLevel = _aSpecificLevel; } SceneManager.LoadScene("Scene_Appointment", LoadSceneMode.Additive); }
public List<ValidLevels> DeseriealizeLevels() { List<ValidLevels> _list = new List<ValidLevels>(); string listText = fileIO.GetFileText(); List<string> _eachLine = new List<string>(); _eachLine.AddRange(listText.Split('\n')); if (_eachLine.Contains("")) { _eachLine.Remove(""); } // remove possible trailing line foreach (string line in _eachLine) { if (!line.StartsWith("//")) { Difficulty thisDifficulty = Difficulty.Unknown; int thisSeed = 0; int thisLevel = 0; int thisCantTouch = 0; bool thisOneClick = false; int thisNumClick = 0; string lineWithoutEnding = line.Split('\r')[0]; string[] tokens = lineWithoutEnding.Split(','); int a; bool b; if (int.TryParse((tokens[0].Split(':')[1]), out a)) { thisLevel = a; } // set the level string _diff = tokens[1].Split(':')[1]; // set the difficulty if (_diff == "VeryEasy") { thisDifficulty = Difficulty.VeryEasy; } else if (_diff == "Easy") { thisDifficulty = Difficulty.Easy; } else if (_diff == "Medium") { thisDifficulty = Difficulty.Medium; } else if (_diff == "Hard") { thisDifficulty = Difficulty.Hard; } if (int.TryParse((tokens[2].Split(':')[1]), out a)) { thisSeed = a; } // set the seed if (int.TryParse((tokens[3].Split(':')[1]), out a)) { thisNumClick = a; } // set the numClicks if (bool.TryParse((tokens[4].Split(':')[1]), out b)) { thisOneClick = b; } // set the oneClick possibility if (int.TryParse((tokens[5].Split(':')[1]), out a)) { thisCantTouch = a; } // set who you cant touch, if possible ActionTrail thisPath = new ActionTrail(tokens[6]); ActionTrail thisCantTouchPath = new ActionTrail(tokens[7]); ValidLevels lvl = new ValidLevels(thisLevel, thisDifficulty, thisSeed, thisCantTouch, thisOneClick, thisNumClick, thisCantTouchPath.trail.Count); lvl.path = thisPath; lvl.cantTouchPath = thisCantTouchPath; _list.Add(lvl); } } return _list; }
IEnumerator DisplayShowMeSeries() { inputManager.IgnoreUserInput(); ValidLevels currentLevel = GameObject.FindGameObjectWithTag("clipboard").GetComponent <Clipboard>().GetNextLevelUp().myLevel; ActionTrail currentLevelPath; if (currentLevel.isCantTouch) { currentLevelPath = currentLevel.cantTouchPath; } else { currentLevelPath = currentLevel.path; } List <Person> allPeople = GameObject.FindGameObjectWithTag("networkManager").GetComponent <NetworkManager>().GetAllPeople(); for (int i = 0; i < currentLevelPath.trail.Count; i++) { Vector3 personPos = allPeople[currentLevelPath.trail[i].Key].gameObject.transform.position; Vector2 personPosOffset = (Vector2)personPos - m_finger.GetFingerTipOffset(); m_finger.SendFinger(personPosOffset); yield return(new WaitForSeconds(showMeInterval)); ClickAtFinger(); yield return(new WaitForSeconds(showMeInterval)); if (currentLevelPath.trail[i].Value) { m_finger.SendFinger(screenPos_greenButton); } else { m_finger.SendFinger(screenPos_redButton); } yield return(new WaitForSeconds(showMeInterval)); ClickAtFinger(); yield return(new WaitForSeconds(showMeInterval)); } m_finger.SendFingerAway(false); inputManager.ResumeUserInput(); GameObject.FindGameObjectWithTag("clipboard").GetComponent <Clipboard>().Callback_CompletedShowMe(); EndNotification(); }
public ValidLevels GetALevel(Difficulty _difficulty, int _level, bool _fallToRed, bool _oneClick, bool _cantTouch, bool _noLines, int _seed, bool isCreatingNewLevel) { // if a seed is entered, then find that exact level if (_seed != -1) { if (isCreatingNewLevel) { ValidLevels returnLevel = new ValidLevels(_level, _difficulty, _seed, false, false, false, false); return(returnLevel); } else { foreach (ValidLevels level in GenerateValidLevelList()) { if (level.seed == _seed && level.difficulty == _difficulty && level.level == _level) { // set special attributes, if any level.SetOnlySpecialAttributes(_fallToRed, _oneClick, _cantTouch, _noLines); return(level); } } Debug.LogException(new System.Exception("A requested level was not found in the level list")); } } // otherwise, find all matching levels List <ValidLevels> LevelList = GenerateValidLevelList(); var levelsToChooseFrom = (from level in LevelList where level.level == _level where level.difficulty == _difficulty where (_oneClick == true && level.oneClick) || (_oneClick == false) where (_cantTouch == true && level.cantTouch >= 0) || (_cantTouch == false) select level).ToList(); if (levelsToChooseFrom.Count == 0) // if there aren't any found for this level { Debug.LogException(new System.Exception("No seed found for this level")); } if (levelsToChooseFrom.Count == 0) { Debug.LogException(new System.Exception("warning: no level found to match request. returning null.")); return(null); } // if none were found to match, return null ValidLevels levelToReturn = levelsToChooseFrom[Random.Range(0, levelsToChooseFrom.Count)]; // choose a matching level at random levelToReturn.SetOnlySpecialAttributes(_fallToRed, _oneClick, _cantTouch, _noLines); // explicitly set all special attributes on this level return(levelToReturn); }
// save seed used whether randomly generated or user set public int SeedTheLevel() { int _usedSeed; currentLevelInfo = GameObject.FindWithTag("clipboard").GetComponent <Clipboard>().GetNextLevelUp().myLevel; if (currentLevelInfo.difficulty == Difficulty.VeryEasy) { isReadingSeedFromFile = true; } else if (currentLevelInfo.difficulty == Difficulty.Easy) { isReadingSeedFromFile = true; } else if (currentLevelInfo.difficulty == Difficulty.Medium) { isReadingSeedFromFile = true; } else if (currentLevelInfo.difficulty == Difficulty.Hard) { isReadingSeedFromFile = true; } else if (currentLevelInfo.difficulty == Difficulty.Unknown) { isReadingSeedFromFile = false; isUsingSeed = false; } else { print("error -- difficulty could not be read (generating level randomly)"); isReadingSeedFromFile = false; isUsingSeed = false; } if (isReadingSeedFromFile) // if using a level from a file { _usedSeed = currentLevelInfo.seed; Random.seed = _usedSeed; } else if (isUsingSeed) // if using a set seed { Random.seed = randomSeed; _usedSeed = randomSeed; // save the seed used } else // if using a random seed { _usedSeed = currentLevelInfo.seed; Random.seed = _usedSeed; // save the seed used // copy used seed to the clipboard (windows clipboard) TextEditor te = new TextEditor(); te.content = new GUIContent(_usedSeed.ToString()); te.SelectAll(); te.Copy(); } return(_usedSeed); }
public void SerializeALevel(ValidLevels level) { string formattedString = string.Format("level:{0},difficulty:{1},seed:{2},clicks:{3},oneClick:{4},cantTouch:{5},path:{6},cantTouchPath:{7}\n", level.level.ToString(), level.difficulty.ToString(), level.seed.ToString(), level.numClicks.ToString(), level.oneClick, level.cantTouch.ToString(), level.path, level.cantTouchPath ); fileIO.AppendToFile(formattedString); }
public ValidLevels GetALevel(Difficulty _difficulty, int _level, bool _fallToRed, bool _oneClick, bool _cantTouch, bool _noLines, int _seed, bool isCreatingNewLevel) { // if a seed is entered, then find that exact level if (_seed != -1) { if (isCreatingNewLevel) { ValidLevels returnLevel = new ValidLevels(_level, _difficulty, _seed, false, false, false, false); return returnLevel; } else { foreach (ValidLevels level in GenerateValidLevelList ()) { if (level.seed == _seed && level.difficulty == _difficulty && level.level == _level) { // set special attributes, if any level.SetOnlySpecialAttributes(_fallToRed, _oneClick, _cantTouch, _noLines); return level; } } Debug.LogException(new System.Exception("A requested level was not found in the level list")); } } // otherwise, find all matching levels List<ValidLevels> LevelList = GenerateValidLevelList(); var levelsToChooseFrom = (from level in LevelList where level.level == _level where level.difficulty == _difficulty where (_oneClick == true && level.oneClick) || (_oneClick == false) where (_cantTouch == true && level.cantTouch >= 0) || (_cantTouch == false) select level).ToList(); if (levelsToChooseFrom.Count == 0) // if there aren't any found for this level { Debug.LogException(new System.Exception("No seed found for this level")); } if (levelsToChooseFrom.Count == 0) { Debug.LogException(new System.Exception("warning: no level found to match request. returning null.")); return null; } // if none were found to match, return null ValidLevels levelToReturn = levelsToChooseFrom[Random.Range(0, levelsToChooseFrom.Count)]; // choose a matching level at random levelToReturn.SetOnlySpecialAttributes(_fallToRed, _oneClick, _cantTouch, _noLines); // explicitly set all special attributes on this level return levelToReturn; }
public void UpdateScore(Difficulty diff, int numActionsTaken, bool isSpecial) { // add score for perfect number of actions ValidLevels thisLevel = GameObject.Find("Clipboard").GetComponent <Clipboard>().GetNextLevelUp().myLevel; int requiredClicks = (thisLevel.isCantTouch ? thisLevel.cantTouchNumClicks : thisLevel.numClicks); if (numActionsTaken == requiredClicks) { score = 3; } else if (numActionsTaken == (requiredClicks + 1)) { score = 2; } else { score = 1; } }
public void GetStartFromClipboard() { Appointment _nextAppointment = gameManager.GetClipboard().GetNextLevelUp(); ValidLevels _incomingLevel = _nextAppointment.myLevel; difficultySelection = _incomingLevel.difficulty; LoadNewLevel(_incomingLevel); // showing notifications at beginning of sessions if (_nextAppointment.GetMyDayIndex() == 0 && _nextAppointment.levelIndex == 0) { GameObject.Find("NotificationManager").GetComponent <NotificationManager>().DisplayNotification(2, false); } else if (_nextAppointment.GetMyDayIndex() == 0 && _nextAppointment.levelIndex == 1) { GameObject.Find("NotificationManager").GetComponent <NotificationManager>().DisplayNotification(6, false); } else if (_nextAppointment.GetMyDayIndex() == 0 && _nextAppointment.levelIndex == 2) { GameObject.Find("NotificationManager").GetComponent <NotificationManager>().DisplayNotification(18, false); } else if (_nextAppointment.GetMyDayIndex() == 1 && _nextAppointment.levelIndex == 0) { GameObject.Find("NotificationManager").GetComponent <NotificationManager>().DisplayNotification(5, false); } else if (_nextAppointment.GetMyDayIndex() == 2 && _nextAppointment.levelIndex == 0) { GameObject.Find("NotificationManager").GetComponent <NotificationManager>().DisplayNotification(7, false); } else if (_nextAppointment.GetMyDayIndex() == 3 && _nextAppointment.levelIndex == 0) { GameObject.Find("NotificationManager").GetComponent <NotificationManager>().DisplayNotification(8, false); } else if (_nextAppointment.GetMyDayIndex() == 4 && _nextAppointment.levelIndex == 2) { GameObject.Find("NotificationManager").GetComponent <NotificationManager>().DisplayNotification(10, false); } }
// save seed used whether randomly generated or user set public int SeedTheLevel() { int _usedSeed; currentLevelInfo = GameObject.FindWithTag("clipboard").GetComponent<Clipboard>().GetNextLevelUp().myLevel; if (currentLevelInfo.difficulty == Difficulty.VeryEasy) { isReadingSeedFromFile = true; } else if (currentLevelInfo.difficulty == Difficulty.Easy) { isReadingSeedFromFile = true; } else if (currentLevelInfo.difficulty == Difficulty.Medium) { isReadingSeedFromFile = true; } else if (currentLevelInfo.difficulty == Difficulty.Hard) { isReadingSeedFromFile = true; } else if (currentLevelInfo.difficulty == Difficulty.Unknown) { isReadingSeedFromFile = false; isUsingSeed = false; } else { print ("error -- difficulty could not be read (generating level randomly)"); isReadingSeedFromFile = false; isUsingSeed = false; } if (isReadingSeedFromFile) // if using a level from a file { _usedSeed = currentLevelInfo.seed; Random.seed = _usedSeed; } else if (isUsingSeed) // if using a set seed { Random.seed = randomSeed; _usedSeed = randomSeed; // save the seed used } else // if using a random seed { _usedSeed = currentLevelInfo.seed; Random.seed = _usedSeed; // save the seed used // copy used seed to the clipboard (windows clipboard) TextEditor te = new TextEditor(); te.content = new GUIContent(_usedSeed.ToString()); te.SelectAll(); te.Copy(); } return _usedSeed; }
public void SetSpecificLevel(ValidLevels levelRequested) { specificLevelsRequested.Add(levelRequested); }
// method overload void LoadNewLevel(ValidLevels _aSpecificLevel) { LoadNewLevel(_aSpecificLevel, true); }
public List <ValidLevels> DeseriealizeLevels() { List <ValidLevels> _list = new List <ValidLevels>(); string listText = fileIO.GetFileText(); List <string> _eachLine = new List <string>(); _eachLine.AddRange(listText.Split('\n')); if (_eachLine.Contains("")) { _eachLine.Remove(""); } // remove possible trailing line foreach (string line in _eachLine) { if (!line.StartsWith("//")) { Difficulty thisDifficulty = Difficulty.Unknown; int thisSeed = 0; int thisLevel = 0; int thisCantTouch = 0; bool thisOneClick = false; int thisNumClick = 0; string lineWithoutEnding = line.Split('\r')[0]; string[] tokens = lineWithoutEnding.Split(','); int a; bool b; if (int.TryParse((tokens[0].Split(':')[1]), out a)) { thisLevel = a; } // set the level string _diff = tokens[1].Split(':')[1]; // set the difficulty if (_diff == "VeryEasy") { thisDifficulty = Difficulty.VeryEasy; } else if (_diff == "Easy") { thisDifficulty = Difficulty.Easy; } else if (_diff == "Medium") { thisDifficulty = Difficulty.Medium; } else if (_diff == "Hard") { thisDifficulty = Difficulty.Hard; } if (int.TryParse((tokens[2].Split(':')[1]), out a)) { thisSeed = a; } // set the seed if (int.TryParse((tokens[3].Split(':')[1]), out a)) { thisNumClick = a; } // set the numClicks if (bool.TryParse((tokens[4].Split(':')[1]), out b)) { thisOneClick = b; } // set the oneClick possibility if (int.TryParse((tokens[5].Split(':')[1]), out a)) { thisCantTouch = a; } // set who you cant touch, if possible ActionTrail thisPath = new ActionTrail(tokens[6]); ActionTrail thisCantTouchPath = new ActionTrail(tokens[7]); ValidLevels lvl = new ValidLevels(thisLevel, thisDifficulty, thisSeed, thisCantTouch, thisOneClick, thisNumClick, thisCantTouchPath.trail.Count); lvl.path = thisPath; lvl.cantTouchPath = thisCantTouchPath; _list.Add(lvl); } } return(_list); }
bool RunOneLevelTrial() { FindNetworkManager(); ValidLevels thisLevel = new ValidLevels(); LevelValidator lv = new LevelValidator(); levelTesterState_s bestWinState = lv.PathfindLevel_BreadthFirst(); if (bestWinState.numStepsToReach == -1) { return false; } else { thisLevel.numClicks = bestWinState.numStepsToReach; // set number of clicks } thisLevel.level = networkMgr.GetNumPeople(); // set how many people on this level if (thisLevel.level == 3) { thisLevel.difficulty = Difficulty.VeryEasy; } // set difficulty from number of clicks and level else if (thisLevel.level == 4 && thisLevel.numClicks < 3) { thisLevel.difficulty = Difficulty.VeryEasy; } else if (thisLevel.level == 4 && thisLevel.numClicks >= 3) { thisLevel.difficulty = Difficulty.Easy; } else if (thisLevel.level == 5 && thisLevel.numClicks < 4) { thisLevel.difficulty = Difficulty.Easy; } else if (thisLevel.level == 5 && thisLevel.numClicks >= 4) { thisLevel.difficulty = Difficulty.Medium; } else if (thisLevel.level == 6 && thisLevel.numClicks < 3) { return false; } // this level is too easy else if (thisLevel.level == 6 && thisLevel.numClicks < 5) { thisLevel.difficulty = Difficulty.Medium; } else if (thisLevel.level == 6 && thisLevel.numClicks >= 5) { thisLevel.difficulty = Difficulty.Hard; } else if (thisLevel.level == 7 && thisLevel.numClicks < 3) { return false; } // this level is too easy else if (thisLevel.level == 7 && thisLevel.numClicks < 5) { thisLevel.difficulty = Difficulty.Medium; } else if (thisLevel.level == 7 && thisLevel.numClicks >= 5) { thisLevel.difficulty = Difficulty.Hard; } else if (thisLevel.level == 8 && thisLevel.numClicks < 3) { return false; } // this level is too easy else if (thisLevel.level == 8 && thisLevel.numClicks < 5) { thisLevel.difficulty = Difficulty.Medium; } else if (thisLevel.level == 8 && thisLevel.numClicks >= 5) { thisLevel.difficulty = Difficulty.Hard; } else { Debug.LogException(new System.Exception("Level and number of clicks wasn't handled by levelTester class (" + thisLevel.level + ", " + thisLevel.numClicks + ")")); } thisLevel.seed = networkMgr.usedSeed; // set used seed thisLevel.path = bestWinState.pathOfActions; if (lv.CheckIfLevelCanBeOneClick(bestWinState)) { thisLevel.oneClick = true; } // find a person for the cantTouch special level bool foundCantClickPerson = false; for (int i = 0; i < bestWinState.pathOfActions.trail.Count; i++) { int personToExclude = bestWinState.pathOfActions.trail[i].Key; networkMgr.ReloadStartingState(); LevelValidator lv2 = new LevelValidator(); levelTesterState_s bestWinState2 = lv2.PathfindLevel_BreadthFirst(personToExclude); if (bestWinState2.numStepsToReach != -1) { foundCantClickPerson = true; thisLevel.cantTouch = personToExclude; //print (bestWinState.numStepsToReach + ":" + bestWinState2.numStepsToReach); thisLevel.cantTouchPath = bestWinState2.pathOfActions; } } if (!foundCantClickPerson) { thisLevel.cantTouch = -1; } if (thisLevel.difficulty != Difficulty.Impossible) { lv.levelList.Add(thisLevel); if (fp == null) { fp = new ValidSeedListFileParse(); } fp.SerializeALevel(thisLevel); } return true; }
bool RunOneLevelTrial() { FindNetworkManager(); ValidLevels thisLevel = new ValidLevels(); LevelValidator lv = new LevelValidator(); levelTesterState_s bestWinState = lv.PathfindLevel_BreadthFirst(); if (bestWinState.numStepsToReach == -1) { return(false); } else { thisLevel.numClicks = bestWinState.numStepsToReach; // set number of clicks } thisLevel.level = networkMgr.GetNumPeople(); // set how many people on this level if (thisLevel.level == 3) { thisLevel.difficulty = Difficulty.VeryEasy; } // set difficulty from number of clicks and level else if (thisLevel.level == 4 && thisLevel.numClicks < 3) { thisLevel.difficulty = Difficulty.VeryEasy; } else if (thisLevel.level == 4 && thisLevel.numClicks >= 3) { thisLevel.difficulty = Difficulty.Easy; } else if (thisLevel.level == 5 && thisLevel.numClicks < 4) { thisLevel.difficulty = Difficulty.Easy; } else if (thisLevel.level == 5 && thisLevel.numClicks >= 4) { thisLevel.difficulty = Difficulty.Medium; } else if (thisLevel.level == 6 && thisLevel.numClicks < 3) { return(false); } // this level is too easy else if (thisLevel.level == 6 && thisLevel.numClicks < 5) { thisLevel.difficulty = Difficulty.Medium; } else if (thisLevel.level == 6 && thisLevel.numClicks >= 5) { thisLevel.difficulty = Difficulty.Hard; } else if (thisLevel.level == 7 && thisLevel.numClicks < 3) { return(false); } // this level is too easy else if (thisLevel.level == 7 && thisLevel.numClicks < 5) { thisLevel.difficulty = Difficulty.Medium; } else if (thisLevel.level == 7 && thisLevel.numClicks >= 5) { thisLevel.difficulty = Difficulty.Hard; } else if (thisLevel.level == 8 && thisLevel.numClicks < 3) { return(false); } // this level is too easy else if (thisLevel.level == 8 && thisLevel.numClicks < 5) { thisLevel.difficulty = Difficulty.Medium; } else if (thisLevel.level == 8 && thisLevel.numClicks >= 5) { thisLevel.difficulty = Difficulty.Hard; } else { Debug.LogException(new System.Exception("Level and number of clicks wasn't handled by levelTester class (" + thisLevel.level + ", " + thisLevel.numClicks + ")")); } thisLevel.seed = networkMgr.usedSeed; // set used seed thisLevel.path = bestWinState.pathOfActions; if (lv.CheckIfLevelCanBeOneClick(bestWinState)) { thisLevel.oneClick = true; } // find a person for the cantTouch special level bool foundCantClickPerson = false; for (int i = 0; i < bestWinState.pathOfActions.trail.Count; i++) { int personToExclude = bestWinState.pathOfActions.trail[i].Key; networkMgr.ReloadStartingState(); LevelValidator lv2 = new LevelValidator(); levelTesterState_s bestWinState2 = lv2.PathfindLevel_BreadthFirst(personToExclude); if (bestWinState2.numStepsToReach != -1) { foundCantClickPerson = true; thisLevel.cantTouch = personToExclude; //print (bestWinState.numStepsToReach + ":" + bestWinState2.numStepsToReach); thisLevel.cantTouchPath = bestWinState2.pathOfActions; } } if (!foundCantClickPerson) { thisLevel.cantTouch = -1; } if (thisLevel.difficulty != Difficulty.Impossible) { lv.levelList.Add(thisLevel); if (fp == null) { fp = new ValidSeedListFileParse(); } fp.SerializeALevel(thisLevel); } return(true); }