Esempio n. 1
0
        public void LoadGame(GameState gameState, string gameName)
        {
            var path     = gameState.SaveDirectory;
            var fileName = $"{gameName}.json";

            if (Directory.Exists(path) && File.Exists(Path.Combine(path, fileName)))
            {
                var str        = File.ReadAllText(Path.Combine(path, $"{gameName}.json"));
                var loadedGame = JsonConvert.DeserializeObject <GameSave>(str);
                gameState.Miner            = Miner.FromState(loadedGame.Miner);
                gameState.Store.StoreState = StoreInventory.From(loadedGame.MinerStore);
                gameState.Mode             = loadedGame.Mode;
                gameState.SaveDirectory    = path;
                gameState.SaveName         = gameName;
                gameState.GameTime.Restart();
            }
        }