Пример #1
0
        private static string LoadGame()
        {
            Game?     game      = null;
            GameState?gameState = null;

            while (game == null)
            {
                Console.Clear();
                var saves = GameSaves.GetPlayableSaves();
                Console.WriteLine($"Available saves: {string.Join(", ", saves)}");
                var filename =
                    InputHandler.GetUserStringInput("Choose the game to load " +
                                                    $"(D - default name ({GameSaves.DefaultName}), X - exit):",
                                                    1, 30, "Enter a valid name!", true);
                if (filename == null)
                {
                    return("");
                }
                if (filename.ToLower() == "d")
                {
                    filename = null;
                }
                gameState = GameSaves.LoadSave(filename);
                game      = gameState != null?JsonConvert.DeserializeObject <Game>(gameState.Data) : null;
            }
            _saveGame = game;
            return(gameState !.Opponent == 0 ? PlayGameTwoPlayers() : PlayGameComputer());
        }
Пример #2
0
        private static void SaveGame(Game game, int mode)
        {
            var playableSaves = GameSaves.GetPlayableSaves();

            Console.WriteLine($"Existing playable saves: {string.Join(", ", playableSaves)}");
            var finishedSaves = GameSaves.GetFinishedSaves();

            Console.WriteLine($"Existing finished saves: {string.Join(", ", finishedSaves)}");
            var filename = InputHandler.GetUserStringInput(
                $"Choose the name for a save (D - default name ({GameSaves.DefaultName}), X - drop the game):", 1, 30,
                "Enter a valid name!", true);

            if (filename == null)
            {
                return;
            }
            if (filename.ToLower() == "d")
            {
                filename = GameSaves.DefaultName;
            }
            string?rewriteFilename = filename;

            while (playableSaves.Contains(rewriteFilename) || finishedSaves.Contains(rewriteFilename))
            {
                rewriteFilename = InputHandler.GetUserStringInput(
                    "The save with this name already exists. Choose another name, or X to rewrite the save:", 1, 30,
                    "Enter a valid name!", true);
                if (rewriteFilename == null)
                {
                    break;
                }
            }
            GameSaves.Save(game, rewriteFilename ?? filename, mode);
        }
Пример #3
0
    public static void ClearUserData()
    {
        if (EditorApplication.isPlaying)
        {
            _log.Error($"Cannot delete during play mode.");
        }
        else
        {
            GameSaves.RefreshSavedGames();

            if (GameSaves.SaveExists("Default"))
            {
                GameSaves.UnloadCurrent();
                GameSaves.DeleteSave("Default");
            }
            else
            {
                _log.Warning("No game save data to delete.");
            }

            var user = UserSaves.LoadUser("Default");

            if (user.HasRegisteredGame("Default"))
            {
                user.UnregisterGame("Default");
            }
            else
            {
                _log.Warning("No game to unregister.");
            }

            UserSaves.SaveUser();
        }
    }
Пример #4
0
 private void Awake()
 {
     if (Instance != null && Instance != this)
     {
         Destroy(this.gameObject);
     }
     Instance = this;
 }
Пример #5
0
    public void Load()
    {
        string value = GameSaves.LoadValue(saveValueName);

        if (value.Length > 0)
        {
            m_nextLevel = byte.Parse(value);
            m_levelData[m_nextLevel - 1].upgrade.Invoke();
            DrawLevel();
        }
    }
Пример #6
0
    //Loads contents of save file
    void LoadGameSave()
    {
        if (File.Exists(Application.persistentDataPath + "/gameSave.dat"))
        {
            BinaryFormatter bf     = new BinaryFormatter();
            FileStream      file   = File.Open(Application.persistentDataPath + "/gameSave.dat", FileMode.Open);
            GameSaves       gSaves = (GameSaves)bf.Deserialize(file);
            _highscore = gSaves._savedhighscore;

            file.Close();
        }
    }
Пример #7
0
    private void StartGame()
    {
        GameSaves.RefreshSavedGames();
        GameSaves.LoadGame("Default");

        if (!GameSaves.HasSavedData)
        {
            StartCoroutine(HandlePrologueScreen());
        }

        InitializeScene();
    }
Пример #8
0
 public void Load()
 {
     if (loadCandy)
     {
         string value = GameSaves.LoadValue(saveValueName);
         if (value.Length > 0)
         {
             m_candyCount   = int.Parse(value);
             scoreText.text = m_candyCount.ToString();
         }
     }
 }
Пример #9
0
    //updates high score and saves it in a binary file
    void UpdateHighScore()
    {
        _highscore = _currentscore;

        BinaryFormatter bf    = new BinaryFormatter();
        FileStream      file  = File.Create(Application.persistentDataPath + "/gameSave.dat");
        GameSaves       gsave = new GameSaves();

        gsave._savedhighscore = _highscore;

        bf.Serialize(file, gsave);
        file.Close();
    }
Пример #10
0
        public ChunkBuilder GetBuilderAtPosition(IntVector2 worldPosition)
        {
            if (!_chunkBuildersByWorldPosition.TryGetValue(worldPosition, out var builder))
            {
                if (GameSaves.HasGameData(worldPosition.ToString() + "B"))
                {
                    builder = LoadBuilder(worldPosition);
                }
                else if (!GameSaves.HasGameData(worldPosition.ToString()))
                {
                    builder = AddBuilder(worldPosition);
                }
            }

            return(builder);
        }
Пример #11
0
        private void CreateChunk(IntVector2 worldPosition)
        {
            if (GetNearestChunkPosition(worldPosition) != worldPosition)
            {
                throw new InvalidOperationException($"Chunk cannot be spawned at {worldPosition}.");
            }

            if (_chunksByWorldPosition.ContainsKey(worldPosition))
            {
                return;
            }
            else
            {
                Chunk chunk;

                if (GameSaves.HasGameData(worldPosition.ToString()))
                {
                    _log.Info($"Loading Chunk at {worldPosition}.");
                    chunk = LoadChunk(worldPosition);
                }
                else
                {
                    _log.Info($"Building Chunk at {worldPosition}.");
                    chunk = BuildChunk(worldPosition);
                }

                Register(chunk);

                if (_chunkConstructionCoroutine == null)
                {
                    _chunkConstructionCoroutine = StartCoroutine(ChunkConstructionCoroutine());
                }

                foreach (var direction in Directions.Cardinals)
                {
                    if (_chunkBuildersByWorldPosition.TryGetValue(worldPosition + direction, out var neighborBuilder))
                    {
                        _spaceArchitect.CheckForSpaces(neighborBuilder);
                    }
                }
            }
        }
Пример #12
0
 void Save()
 {
     GameSaves.SaveValue(saveValueName, m_nextLevel.ToString());
 }
Пример #13
0
 void Save()
 {
     GameSaves.SaveValue(saveValueName, m_candyCount.ToString());
 }