/** * Process undo and redo move actions */ private void ProcessMoveAction(MoveTypes moveType) { bool undoAction = moveType.Equals(MoveTypes.UNDO); CustomStack <Move> targetMoves = undoAction ? m_moves : m_undoneMoves; CustomStack <Move> altMoves = undoAction ? m_undoneMoves : m_moves; // Pop the last move from the moves list/stack Move move = targetMoves.Pop(); if (move.IsSpecial()) { // Special moves should only have one event Event ev = move.GetEvents()[0]; ev.Reverse(); // Swap the event type for proper redo Event.EventType evType = ev.GetEventType(); Event.EventType newEvType = Event.EventType.NONE; switch (evType) { case Event.EventType.REPLINISH: newEvType = Event.EventType.DEPLINISH; break; case Event.EventType.DEPLINISH: newEvType = Event.EventType.REPLINISH; break; } ev.SetType(newEvType); m_blocked = false; } else { // Take precedence over events in the move (execute them first) List <Event> events = move.GetEvents(); foreach (Event evt in events) { // Reverse the event evt.Reverse(); } // Perform the move; don't want to track changes so that undone moves are managed through here move.GetTopCard().MoveTo(undoAction ? move.GetPreviousParent() : move.GetNextParent(), move.GetCards(), moveType); } // Add the move to the redo stack altMoves.Push(move); }