Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

StoneField.h

Go to the documentation of this file.
00001 /* Yo Emacs, this is -*- C++ -*- */
00002 /*
00003  *   ksame 0.4 - simple Game
00004  *   Copyright (C) 1997,1998  Marcus Kreutzberger
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
00017  *   along with this program; if not, write to the Free Software
00018  *   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
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 

Generated on Sat Nov 5 16:17:28 2005 for OPIE by  doxygen 1.4.2