man Games::Cards::Undo () - Games::Cards::Undo -- undoing/redoing moves in Games::Cards games

NAME

Games::Cards::Undo -- undoing/redoing moves in Games::Cards games

SYNOPSIS

    use Games::Cards::Undo;
    $Undo = new Games::Cards::Undo(1); # 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

DESCRIPTION

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:

new(MOVES)
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_move
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
Undo a move.
redo
Redo a move that had been undone with undo.