Games::Cards::Undo -- undoing/redoing moves in Games::Cards games
use Games::Cards::Undo; $Undo = new Games::Cards::Undo(100); # Make undo engine to save 100 moves $Undo->undo; # undo last move $Undo->redo; # redo last undone move $Undo->end_move; # tell undo engine we're done with a move
This is the package for methods to undo & redo moves. The GC::Undo object has no publicly accessible fields. But it stores an array of the preceding moves. Note that a "move" is made up of several "atoms" (objects of the private class GC::Undo::Atom and its subclassess). For example, moving a card from one column to another in solitaire involves one or more Splice atoms (removing or adding card(s) to a CardSet) and possibly a Face atom (turning a card over).
Many of the GC::Undo methods (and all of the GC::Undo::Atom methods) will be called by other Games::Cards methods, but not by the actual games. Here are the publicly accesssible methods:
Initialize the Undo engine. MOVES is the number of atoms to save. 0 (or no argument) allows infinite undo.
This method must be called before any undo-able moves are made (i.e., it can be called after the hands are dealt). This method will also re-initialize the engine for a new game.
End the current move. Everything between the last call to end_move and now is considered one move. This tells undo how much to undo.
Undo a move.
Redo a move that had been undone with undo.