/// <summary> /// Saves a game /// </summary> /// <param name="data">Game to save</param> /// <param name="path">Filepath</param> /// <returns>True if successful, false if failure</returns> public static bool SaveGame(GameData data, string path) { data.BoardStates.ForEach(b => b.ChangeToNormalArray()); XmlSerializer serializerObj = new XmlSerializer(typeof(GameData)); TextWriter streamWriter = new StreamWriter(path); serializerObj.Serialize(streamWriter, data); streamWriter.Close(); return true; }
/// <summary> /// Constructor to resume a saved game /// </summary> /// <param name="data">Game to resume</param> public GameFlowHandler(GameData data) { Game = data; _boardStates = Game.BoardStates; GameHasStarted = true; LastTurnWasMill = false; LegimateTurns = 0; GameEventPlayer1 = GameEvent.NoEvent; GameEventPlayer2 = GameEvent.NoEvent; _lastBoardState = null; }
/// <summary> /// Constructor to start a new game /// </summary> /// <param name="gameType">Type of the game</param> public GameFlowHandler(GameType gameType) { Game = new GameData(gameType); _boardStates = Game.BoardStates; _boardStates.Add(new BoardState()); CurrentPlayer = PlaystoneState.Player1; ModelHelpFunctions.InitializePlaystoneStates(CurrentPlaystones, PlaystoneState.Selectable); GameHasStarted = false; LastTurnWasMill = false; LegimateTurns = 0; GameEventPlayer1 = GameEvent.NoEvent; GameEventPlayer2 = GameEvent.NoEvent; _lastBoardState = null; }
/// <summary> /// Loads a game /// </summary> /// <param name="data">Game to load</param> /// <param name="path">Filepath</param> /// <returns>True if successful, false if failure</returns> public static bool LoadGame(ref GameData data, string path) { XmlSerializer serializerObj = new XmlSerializer(typeof(GameData)); TextReader textReader = new StreamReader(path); if (!serializerObj.CanDeserialize(XmlReader.Create(textReader))) { textReader.Close(); return false; } textReader.Close(); textReader = new StreamReader(path); data = (GameData)serializerObj.Deserialize(textReader); textReader.Close(); data.BoardStates.ForEach(b => b.ChangeToDimensionalArray()); return true; }