private void ArrangeCustomLevels() { string destination = Application.persistentDataPath + "/custom_levels_info.dat"; FileStream file; BinaryFormatter bf = new BinaryFormatter(); if (File.Exists(destination)) { file = File.OpenRead(destination); LevelsInfo data = (LevelsInfo)bf.Deserialize(file); int size = data.levelContent.Count; for (int i = 0; i < size; i++) { CreateLevelTitle(i + 1, GetContent(data.levelContent [i])); } file.Close(); //Now write the modified content file = File.OpenWrite(destination); bf.Serialize(file, data); } else { noLevelsText.SetActive(true); } }
void Awake() { if (mInstance != null) { throw new UnityException("Error in CGame(). You are not allowed to instantiate it more than once."); } //CGameConstants.HIGH_SCORE =int.Parse( System.IO.File.ReadAllText("score.txt")); mInstance = this; CMouse.init(); CurrentStageData.init(); LevelsInfo.init(); imgBackground = new CSprite(); //Handheld.PlayFullScreenMovie("IntroGame2.mp4", Color.black, FullScreenMovieControlMode.CancelOnInput); setState(new CMenuState()); mSpriteManager = new CSpriteManager(); //setImage("Sprites/Placeholders_Prototype/level_Background"); }
public void LoadLevels() { if (File.Exists(Application.persistentDataPath + "/Levels.dat")) { BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Open(Application.persistentDataPath + "/Levels.dat", FileMode.Open); LevelsInfo myLoadedInfo = (LevelsInfo)bf.Deserialize(file); levels = myLoadedInfo.levels; } }
public CLevelState(int stageNumber) { SoundList.instance.playLevelMusic(); CInfo stageInfo = LevelsInfo.getLevel(stageNumber); CGame.inst().setImage("Sprites/level_Background0" + stageInfo.building.ToString()); CurrentStageData.currentStage = stageNumber; switch (stageInfo.Kaiju) { case 1: monster = new Dinosaur(stageInfo.startStage, stageInfo.firstStage, stageInfo.secondStage); break; case 2: monster = new Kong(stageInfo.startStage, stageInfo.firstStage, stageInfo.secondStage); break; case 3: monster = new Kraken(stageInfo.startStage, stageInfo.firstStage, stageInfo.secondStage); break; } current_state = STATE_PLAYING; CurrentStageData.difficulty = stageInfo.dif; mBoard = new Board(0); //monster = new Kong(1, 53, 76); building = new Enemy(stageInfo.building); mText = new CText("TEST", CText.alignment.TOP_CENTER); mText.setX(0); mText.setY(0); mText.setColor(Color.black); mBoard.movementsLeft = stageInfo.movements; // MOVE TO CLASS mBoard.targetScore = stageInfo.TargetScore; // MOVE TO CLASS float scoreCoefficient = (float)70 / (float)mBoard.targetScore; skills = new SkillBar(stageInfo.Kaiju); CurrentStageData.assignData(monster, mBoard, scoreCoefficient, skills); screenDim = new CSprite(); screenDim.setSortingLayer("ScreenShade"); screenDim.setName("Sombra"); backMenuBttn = new CSprite(); backMenuBttn.setSortingLayer("TextUI"); tryAgainBttn = new CSprite(); tryAgainBttn.setSortingLayer("TextUI"); btnNextScreen = new CSprite(); btnNextScreen.setSortingLayer("TextUI"); optionsBttn = new CSprite(); optionsBttn.setImage(Resources.Load <Sprite>("Sprites/Buttons/Pause_Button")); optionsBttn.setXY(680, 40); optionsBttn.setSortingLayer("TextUI"); }
// Use this for initialization public void SaveLevelPassed() { BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Open(Application.persistentDataPath + "/Levels.dat", FileMode.OpenOrCreate); LevelsInfo myInfo = new LevelsInfo(); if (myInfo.levels < level) { myInfo.levels = level; } bf.Serialize(file, myInfo); file.Close(); }
private void SaveLevelInfo(string levelString) { string destination = Application.persistentDataPath + "/levels_info.dat"; FileStream file; BinaryFormatter bf = new BinaryFormatter(); if (File.Exists(destination)) { file = File.OpenRead(destination); LevelsInfo data = (LevelsInfo)bf.Deserialize(file); int size = data.levelContent.Count; int level = int.Parse(levelInput.text); if (level <= size) { int lockStatus = data.levelContent [level - 1].IndexOf("l"); data.levelContent [level - 1] = GetContent(levelString); if (lockStatus != -1) { data.levelContent [level - 1] = "l " + data.levelContent [level - 1]; } } else { data.levelContent.Add(GetContent(levelString)); } file.Close(); //Now write the modified content file = File.OpenWrite(destination); bf.Serialize(file, data); } else { file = File.Create(destination); List <string> levelsContent = new List <string> (); levelsContent.Add(GetContent(levelString)); LevelsInfo data = new LevelsInfo(levelsContent); bf.Serialize(file, data); return; } file.Close(); }
private int GetNoOfCustomLevels() { string destination = Application.persistentDataPath + "/custom_levels_info.dat"; FileStream file; BinaryFormatter bf = new BinaryFormatter(); if (File.Exists(destination)) { file = File.OpenRead(destination); LevelsInfo data = (LevelsInfo)bf.Deserialize(file); int size = data.levelContent.Count; file.Close(); return(size); } else { return(0); } }
private void SaveLevelInfo(string levelString) { string destination = Application.persistentDataPath + "/custom_levels_info.dat"; FileStream file; BinaryFormatter bf = new BinaryFormatter(); if (File.Exists(destination)) { file = File.OpenRead(destination); LevelsInfo data = (LevelsInfo)bf.Deserialize(file); int size = data.levelContent.Count; int level = size + 1; data.levelContent.Add(GetContent(levelString)); file.Close(); print("file exists"); //Now write the modified content file = File.OpenWrite(destination); bf.Serialize(file, data); file.Close(); } else { file = File.Create(destination); List <string> levelsContent = new List <string> (); levelsContent.Add(GetContent(levelString)); print("file doesn't exist"); LevelsInfo data = new LevelsInfo(levelsContent); bf.Serialize(file, data); file.Close(); } }
void ParseXml() { _levelsInfo = new LevelsInfo("levels"); }
private void ArrangeLevelScreen() { string destination = Application.persistentDataPath + "/levels_info.dat"; FileStream file; if (File.Exists(destination)) { file = File.OpenRead(destination); } else { Debug.LogError("File not found"); return; } BinaryFormatter bf = new BinaryFormatter(); LevelsInfo data = (LevelsInfo)bf.Deserialize(file); for (int i = 0; i < frames.childCount; i++) { GameObject level = frames.GetChild(i).gameObject; if (data.levelContent [i].IndexOf("q") != -1) { level.transform.GetChild(1).GetChild(0).gameObject.SetActive(true); } if (data.levelContent [i].IndexOf("h") != -1) { level.transform.GetChild(1).GetChild(1).gameObject.SetActive(true); } if (data.levelContent [i].IndexOf("w") != -1) { level.transform.GetChild(1).GetChild(2).gameObject.SetActive(true); } if (data.levelContent [i].IndexOf("te") != -1) { level.transform.GetChild(1).GetChild(3).gameObject.SetActive(true); } if (data.levelContent [i].IndexOf("r") != -1) { level.transform.GetChild(1).GetChild(4).gameObject.SetActive(true); } } //for the witch if (data.levelContent [9].IndexOf("q") != -1) { witch.transform.GetChild(0).GetChild(0).gameObject.SetActive(true); } if (data.levelContent [9].IndexOf("h") != -1) { witch.transform.GetChild(0).GetChild(1).gameObject.SetActive(true); } if (data.levelContent [9].IndexOf("w") != -1) { witch.transform.GetChild(0).GetChild(2).gameObject.SetActive(true); } if (data.levelContent [9].IndexOf("te") != -1) { witch.transform.GetChild(0).GetChild(3).gameObject.SetActive(true); } if (data.levelContent [9].IndexOf("r") != -1) { witch.transform.GetChild(0).GetChild(4).gameObject.SetActive(true); } file.Close(); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // TODO: use this.Content to load your game content here LevelsInfo.Init(this, Content); }
override public void update() { base.update(); //CSpriteManager.update(); CMouse.update(); if (current_state == STATE_PAUSE) { if (nextScreenClick()) { screenDim.setImage(null); backMenuBttn.setImage(null); btnNextScreen.setImage(null); current_state = STATE_PLAYING; } if (backToMenuClick()) { SoundList.instance.stopMusic(); SoundList.instance.playMenuMusic(); CGame.inst().setState(new CMenuState()); return; } return; } mBoard.update(); monster.update(); building.update(); screenDim.update(); mText.setText("Moves: " + mBoard.getMovementsLeft().ToString()); mText.update(); btnNextScreen.update(); optionsBttn.update(); skills.update(); backMenuBttn.update(); tryAgainBttn.update(); switch (current_state) { case STATE_PLAYING: if (optionsClick()) { current_state = STATE_PAUSE; backMenuBttn.setImage(Resources.Load <Sprite>("Sprites/BackMenuButton")); backMenuBttn.setXY(CGameConstants.SCREEN_WIDTH / 2, CGameConstants.SCREEN_HEIGHT / 2); screenDim.setImage(Resources.Load <Sprite>("Sprites/screenShade")); screenDim.setX(0); screenDim.setY(0); btnNextScreen.setImage(Resources.Load <Sprite>("Sprites/Buttons/Button_Continue")); btnNextScreen.setXY(CGameConstants.SCREEN_WIDTH / 2, CGameConstants.SCREEN_HEIGHT / 2 + 150); return; } if (mBoard.current_state == 0) { if (CurrentStageData.currentKaiju.scale >= 100) { current_state = STATE_WIN; SoundList.instance.stopMusic(); monster.setState(4); building.setState(1); } else { screenDim.setImage(Resources.Load <Sprite>("Sprites/screenShade")); screenDim.setX(0); screenDim.setY(0); //nextScreen.setVisible(true); current_state = STATE_LOSE; backMenuBttn.setImage(Resources.Load <Sprite>("Sprites/BackMenuButton")); backMenuBttn.setXY(CGameConstants.SCREEN_WIDTH / 2, CGameConstants.SCREEN_HEIGHT / 2); tryAgainBttn.setImage(Resources.Load <Sprite>("Sprites/tryAgainButton")); tryAgainBttn.setXY(CGameConstants.SCREEN_WIDTH / 2, CGameConstants.SCREEN_HEIGHT / 2 + 150); monster.setState(2); } } break; case STATE_WIN: if (!building.building.isEnded()) { CurrentStageData.cameraShake(); } else { screenDim.setImage(Resources.Load <Sprite>("Sprites/screenShade")); screenDim.setX(0); screenDim.setY(0); btnNextScreen.setImage(Resources.Load <Sprite>("Sprites/Buttons/Button_Continue")); btnNextScreen.setXY(CGameConstants.SCREEN_WIDTH / 2, CGameConstants.SCREEN_HEIGHT / 2); if (nextScreenClick()) { CurrentStageData.clearData(); if (CurrentStageData.currentStage >= LevelsInfo.getLevelsAmount()) { SoundList.instance.stopMusic(); SoundList.instance.playMenuMusic(); CGame.inst().setState(new CMenuState()); } else { CGame.inst().setState(new CLevelState(CurrentStageData.currentStage + 1)); } } if (Camera.main.transform.position.x > 360) { Camera.main.transform.Translate(new Vector3(-15, 0, 0)); } if (Camera.main.transform.position.x < 360) { Camera.main.transform.Translate(new Vector3(15, 0, 0)); } } break; case STATE_LOSE: if (backToMenuClick()) { backMenuBttn.setImage(Resources.Load <Sprite>("Sprites/BackMenuButton_P")); current_state = GO_BACKMENU; return; } if (tryAgainClick()) { tryAgainBttn.setImage(Resources.Load <Sprite>("Sprites/tryAgainButton_P")); current_state = GO_TRYAGAIN; return; } break; case GO_BACKMENU: CurrentStageData.clearData(); SoundList.instance.stopMusic(); SoundList.instance.playMenuMusic(); CGame.inst().setState(new CMenuState()); return; case GO_TRYAGAIN: CurrentStageData.clearData(); CGame.inst().setState(new CLevelState(CurrentStageData.currentStage)); return; } }