00001 /* 00002 * Sudoku: A plug-in for the Video Disk Recorder 00003 * 00004 * Copyright (C) 2008-2010, Thomas Günther <tom@toms-cafe.de> 00005 * 00006 * This program is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License as published by 00008 * the Free Software Foundation; either version 2 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License along 00017 * with this program; if not, write to the Free Software Foundation, Inc., 00018 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 00019 */ 00020 00021 #ifndef VDR_SUDOKU_HISTORY_H 00022 #define VDR_SUDOKU_HISTORY_H 00023 00024 #include "sudoku.h" 00025 00026 00027 namespace Sudoku 00028 { 00029 class PuzzleGame; 00030 class Pos; 00031 class Move; 00032 typedef Vector<Move*> Moves; 00033 00034 00035 //--- class Sudoku::History -------------------------------------------------- 00036 00037 class History 00038 { 00039 private: 00040 Moves history; 00041 unsigned int executed; 00042 00043 public: 00044 00045 /** Constructor */ 00046 History(); 00047 00048 /** Destructor */ 00049 ~History(); 00050 00051 /** Reset the history. */ 00052 void reset(); 00053 00054 /** Current move in the history */ 00055 Move* current(); 00056 00057 /** Add a new move. */ 00058 void add(Move* move); 00059 00060 /** Set previous move as current. */ 00061 void backward(); 00062 00063 /** Set next move as current. */ 00064 void forward(); 00065 00066 /** Are there executed moves in the history? */ 00067 bool movesExecuted() const; 00068 00069 /** Are there moves to execute in the history? */ 00070 bool movesToExecute() const; 00071 }; 00072 00073 00074 //--- class Sudoku::Move ----------------------------------------------------- 00075 00076 class Move 00077 { 00078 public: 00079 00080 /** Destructor */ 00081 virtual ~Move() {}; 00082 00083 /** Do the move. */ 00084 virtual void execute() = 0; 00085 00086 /** Undo the move. */ 00087 virtual void takeBack() = 0; 00088 }; 00089 00090 00091 //--- class Sudoku::SetMove -------------------------------------------------- 00092 00093 class SetMove : public Move 00094 { 00095 private: 00096 PuzzleGame& puzzle; 00097 unsigned int pos; 00098 unsigned int old_number; 00099 unsigned int new_number; 00100 00101 public: 00102 00103 /** Constructor */ 00104 SetMove(PuzzleGame& puzzle, unsigned int number); 00105 00106 /** Do the move. */ 00107 void execute(); 00108 00109 /** Undo the move. */ 00110 void takeBack(); 00111 }; 00112 00113 } // namespace Sudoku 00114 00115 #endif // VDR_SUDOKU_HISTORY_H