00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef _STONEFIELD
00023 #define _STONEFIELD
00024
00025 #include <krandomsequence.h>
00026 #include <qlist.h>
00027
00028 struct Stone {
00029 unsigned char color;
00030 bool changed;
00031 bool marked;
00032 };
00033
00034 class StoneField;
00035 class StoneWidget;
00036
00037 class StoneFieldState {
00038 private:
00039 unsigned char *field;
00040
00041 int colors;
00042 unsigned int board;
00043 unsigned int score;
00044 int gameover;
00045
00046 public:
00047 StoneFieldState(const StoneField &stonefield);
00048 ~StoneFieldState();
00049 void restore(StoneField &stonefield) const;
00050 };
00051
00052
00053 class StoneField {
00054 friend class StoneFieldState;
00055 friend class StoneWidget;
00056 private:
00057
00058 int sizex;
00059 int sizey;
00060 int maxstone;
00061
00062 struct Stone *field;
00063
00064 int colors;
00065 unsigned int board;
00066 unsigned int score;
00067 mutable int gameover;
00068 bool m_gotBonus;
00069 int marked;
00070
00071 KRandomSequence random;
00072 QList<StoneFieldState> *undolist;
00073 public:
00074 StoneField(int width=15,int height=10,
00075 int colors=3,unsigned int board=0,
00076 bool undoenabled=true);
00077 ~StoneField();
00078
00079 int width() const;
00080 int height() const;
00081
00082 void newGame(unsigned int board,int colors);
00083
00084 void reset();
00085
00086
00087 int mark(int x,int y,bool force=false);
00088 void unmark();
00089
00090 int remove(int x,int y,bool force=false);
00091
00092 int undo(int count=1);
00093
00094 bool isGameover() const;
00095 bool gotBonus() const;
00096 void clearBonus();
00097 bool undoPossible() const;
00098 int getBoard() const;
00099 int getScore() const;
00100 int getColors() const;
00101 int getMarked() const;
00102
00103 protected:
00104 int getFieldSize() const;
00105 struct Stone *getField() const;
00106
00107 int map(int x,int y);
00108 void mark(int index,unsigned char color);
00109 };
00110
00111 #endif
00112
00113
00114