00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef MINEFIELD_H
00021 #define MINEFIELD_H
00022
00023 #include <qscrollview.h>
00024
00025 class Mine;
00026 class Config;
00027
00028 class MineField : public QScrollView
00029 {
00030 Q_OBJECT
00031 public:
00032 MineField( QWidget* parent = 0, const char* name = 0 );
00033 ~MineField();
00034
00035 enum State { Waiting, Playing, GameOver };
00036
00037 State state() const { return stat; }
00038
00039 void readConfig(Config&);
00040 void writeConfig(Config&) const;
00041
00042 int level() const { return lev; }
00043
00044 void setAvailableRect( const QRect & );
00045
00046 QSize sizeHint() const;
00047
00048 public slots:
00049 void setup( int level );
00050
00051 void showMines();
00052
00053 signals:
00054 void gameOver( bool won );
00055 void gameStarted();
00056 void mineCount( int );
00057
00058 protected:
00059
00060 void contentsMousePressEvent( QMouseEvent* );
00061 void contentsMouseReleaseEvent( QMouseEvent* );
00062 void keyPressEvent( QKeyEvent* );
00063 void keyReleaseEvent( QKeyEvent* );
00064 void drawContents( QPainter * p, int clipx, int clipy, int clipw, int cliph );
00065
00066 int getHint( int row, int col );
00067 void setHint( int r, int c );
00068 void updateMine( int row, int col );
00069 void paletteChange( const QPalette & );
00070 void updateCell( int r, int c );
00071 bool onBoard( int r, int c ) const { return r >= 0 && r < numRows && c >= 0 && c < numCols; }
00072 Mine *mine( int row, int col ) { return onBoard(row, col ) ? mines[row+numCols*col] : 0; }
00073 const Mine *mine( int row, int col ) const { return onBoard(row, col ) ? mines[row+numCols*col] : 0; }
00074
00075 protected slots:
00076 void cellPressed( int row, int col );
00077 void cellClicked( int row, int col );
00078 void held();
00079
00080 private:
00081 int findCellSize();
00082 void setCellSize( int );
00083
00084 State stat;
00085 void MineField::setState( State st );
00086 void MineField::placeMines();
00087 enum FlagAction { NoAction, FlagOn, FlagNext };
00088 FlagAction flagAction;
00089 bool ignoreClick;
00090 int currRow;
00091 int currCol;
00092 int numRows, numCols;
00093
00094 int minecount;
00095 int mineguess;
00096 int nonminecount;
00097 int lev;
00098 QRect availableRect;
00099 int cellSize;
00100 QTimer *holdTimer;
00101 Mine **mines;
00102 };
00103
00104 #endif // MINEFIELD_H