Exemplo n.º 1
0
        public IClearMine LoadGame(string path, Type gameType)
        {
            if (!File.Exists(path))
            {
                throw new FileNotFoundException(ResourceHelper.FindText("SavedGamePathNotFound"), path);
            }

            if (gameType == null || gameType.GetInterface(typeof(IClearMine).FullName) == null)
            {
                throw new InvalidOperationException(ResourceHelper.FindText("InvalidClearMineGameType", gameType.FullName));
            }

            IClearMine newgame    = null;
            var        gameLoader = new XmlSerializer(gameType);

            using (var file = File.Open(path, FileMode.Open, FileAccess.Read))
            {
                newgame = gameLoader.Deserialize(file) as IClearMine;
            }

            if (newgame.CheckHash())
            {
                MessageManager.SendMessage <GameLoadMessage>(newgame);
                newgame.ResumeGame();
            }
            else
            {
                MessageBox.Show(ResourceHelper.FindText("CorruptedSavedGameMessage"), ResourceHelper.FindText("CorruptedSavedGameTitle"));
            }

            return(newgame);
        }