void Start() { resolution = new Vector2(Screen.width, Screen.height); string path = Application.persistentDataPath + "/level.data"; if (File.Exists(path)) { BinaryFormatter formatter = new BinaryFormatter(); FileStream stream = new FileStream(path, FileMode.Open); data = formatter.Deserialize(stream) as OneLevelData; stream.Close(); finalAnswere = new bool[data.listOfWords.Count, data.numberOfBits]; for (int i = data.listOfWords.Count - 1; i >= 0; i--) { for (int j = data.numberOfBits - 1; j >= 0; j--) { int tempAfterShift = data.listOfWords[i] >> j; if ((tempAfterShift & 0x1) > 0) { finalAnswere[i, j] = true; } else { finalAnswere[i, j] = false; } } } buttonState = new bool[data.listOfWords.Count, data.numberOfBits]; wordsIsOk = new bool[data.listOfWords.Count]; MakeGui(); MakeAfterFinishInfo(); } else { Debug.LogError("Save file not found in " + path); } levelName.text = PlayerPrefs.GetString("LavelSelectedName", "No name"); }
public void CreateLevelTrigger() { int randomHowManyBits = 0, randomHowManyWords = 0; bool erroDetectInParse = false; string errorMesage = ""; try { randomHowManyBits = int.Parse(howManyBits.text); } catch { errorMesage += error1NoBitsNumber; erroDetectInParse = true; } try { randomHowManyWords = int.Parse(howManyWords.text); } catch { errorMesage += error2NoWordsNumber; erroDetectInParse = true; } errorInfo.text = errorMesage; if (erroDetectInParse == false) { bool isGoodNumberOfBits = false, isGoodNumberOfWords = false; if (randomHowManyBits < 4) { errorMesage += error3BitsTooSmall; } else if (randomHowManyBits > 10) { errorMesage += error4BitsTooBig; } else { isGoodNumberOfBits = true; } if (randomHowManyWords < 1) { errorMesage += error5WordsTooSmall; } else if (randomHowManyWords > 10) { errorMesage += error6WordsTooBig; } else { isGoodNumberOfWords = true; } errorInfo.text = errorMesage; if (isGoodNumberOfBits && isGoodNumberOfWords) { PlayerPrefs.SetInt("randomHowManyBits", randomHowManyBits); PlayerPrefs.SetInt("randomHowManyWords", randomHowManyWords); PlayerPrefs.SetInt("WhereToBack", 2); string levelName = levelRandNameText1 + randomHowManyWords.ToString() + levelRandNameText2 + randomHowManyBits.ToString() + levelRandNameText3; PlayerPrefs.SetString("LavelSelectedName", levelName); List <int> listOfWords = new List <int>(); int maxVal = System.Convert.ToInt16(Mathf.Pow(2, randomHowManyBits) - 1); int newRandomValue = 0; while (listOfWords.Count < randomHowManyWords) { newRandomValue = Random.Range(1, maxVal); if (!listOfWords.Contains(newRandomValue)) { listOfWords.Add(newRandomValue); } } OneLevelData randLevel = new OneLevelData(randomHowManyBits, listOfWords); BinaryFormatter formatter = new BinaryFormatter(); string path = Application.persistentDataPath + "/level.data"; FileStream stream = new FileStream(path, FileMode.Create); formatter.Serialize(stream, randLevel); stream.Close(); SceneManager.LoadScene(1); } } }