private void HandlePlayerDeathGM() { if (!classicMode) { deaths++; EntityManager.instance.UpdateDeathCount(deaths); saveFile.deathCount = deaths; GameSaver.SaveData(saveFile, dataPath); } else { lives--; EntityManager.instance.UpdateDeathCount(lives); saveFile.lifeCount = lives; GameSaver.SaveData(saveFile, dataPath); if (lives <= 0) { player.gameObject.SetActive(false); LoadLevel(GAME_OVER); PopGameState(); PushGameState(GameState.GAME_OVER); PushGameState(GameState.LOADING); } } }
public void QuitGame() { #if UNITY_EDITOR GameSaver.SaveData(saveFile, dataPath); UnityEditor.EditorApplication.isPlaying = false; #else GameSaver.SaveData(saveFile, dataPath); Application.Quit(); #endif }
static void Main() { Player player = new Player(100, 20); GameSaver gameSaver = new GameSaver(); player.Shoot(); gameSaver.SaveData(player); player.Shoot(); player.TakeDamage(20); Console.WriteLine(gameSaver.RestoreLastPlayerSave(ref player) ? "Data restored!" : "Can not restore data!"); player.Shoot(); player.TakeDamage(10); player.Shoot(); Console.ReadKey(); }
private void OnStateEntered() //similar to entry requirement for class game states- future... { switch (stateStack.Peek()) { case GameState.MAIN_MENU: AudioPlayer.instance.PlayMusic(Menu.instance.menuMusic); ContinueLevelText(); CompletionText(); break; case GameState.PLAYING: AudioPlayer.instance.NoMusic(); if (classicMode) { lives = saveFile.lifeCount; EntityManager.instance.UpdateDeathCount(lives); } else { EntityManager.instance.UpdateDeathCount(deaths); } player = FindObjectOfType <Player>(); player.onPlayerDeath += HandlePlayerDeathGM; //code to fix player dropping input on load scene here saveFile.currentLevel = levelIndex; saveFile.wasInGame = true; GameSaver.SaveData(saveFile, dataPath); break; case GameState.GAME_OVER: AudioPlayer.instance.PlayMusic(Menu.instance.menuMusic); classicMode = false; saveFile.wasInGame = false; saveFile.currentLevel = 0; saveFile.inClassicMode = false; GameSaver.SaveData(saveFile, dataPath); break; case GameState.WIN: // AudioPlayer.instance.PlayMusic(Menu.instance.menuMusic); //eventually move this to menu or remove menu entirely... seems annoying to put here Text deathCount = GameObject.Find("deathcount").GetComponent <Text>(); Text secret = GameObject.Find("secret").GetComponent <Text>(); if (classicMode) { deathCount.text = (50 - lives).ToString(); secret.text = "that's all there is to it!"; } else { deathCount.text = deaths.ToString(); if (deaths < 5) { secret.text = "(try classic mode!)"; } } classicMode = false; saveFile.wasInGame = false; saveFile.currentLevel = 0; saveFile.inClassicMode = false; GameSaver.SaveData(saveFile, dataPath); break; } }
public void SaveGameInfo() { gameSaver.SaveData(this); }