diff options
-rw-r--r-- | BUGS | 4 | ||||
-rw-r--r-- | cell.cpp | 5 | ||||
-rw-r--r-- | cell.h | 1 | ||||
-rw-r--r-- | qtminesweeper.cpp | 39 | ||||
-rw-r--r-- | qtminesweeper.h | 2 | ||||
-rw-r--r-- | square.h | 8 |
6 files changed, 41 insertions, 18 deletions
@@ -0,0 +1,4 @@ +If GRIDOFFSET isn't 10 You can't get to some edges of the grid +(see qtminesweeper::keyPressEvent(..) in qtminesweeper.cpp) + + @@ -39,3 +39,8 @@ void cell::flagcheck() if (flags & NUMBER) puts("number"); } + +int cell::getflags() +{ + return flags; +} @@ -32,6 +32,7 @@ class cell : public square NUMBER = 1 << 3 /* square is a number */ }; void flagcheck(); + int getflags(); private: enum flagtype flags; diff --git a/qtminesweeper.cpp b/qtminesweeper.cpp index e1e0272..8be08c3 100644 --- a/qtminesweeper.cpp +++ b/qtminesweeper.cpp @@ -29,15 +29,14 @@ qtminesweeper::qtminesweeper() bluepen = QPen(Qt::blue); /* create cells */ - int tmpx, tmpy; for (int c = 0; c < NUMBEROFCELLS; c++) { - cell tmp(cell::MINE); - generatecellpos(&tmp); + int f; + f = cell::MINE; + cell tmp(f); cells.append(tmp); - tmpx++; - tmpy++; } + generatecellpos(); cursor.movetogridpos(0, 0); } @@ -81,9 +80,12 @@ void qtminesweeper::drawcells(QPainter *painter) { for (int c = 0; c < cells.length(); c++) { - painter->drawText(cells[c].getrealx(), - cells[c].getrealy()+(SQUARESIZE/2), - "B"); + if (cells[c].getflags() & cell::REVEALED) + { + painter->drawText(cells[c].getrealx()+(SQUARESIZE/4), + cells[c].getrealy()+(SQUARESIZE/2+5), + "R"); + } } } @@ -119,6 +121,8 @@ void qtminesweeper::keyPressEvent(QKeyEvent *event) cursor.getgridy()); } break; + case Qt::Key_Space: + break; default: break; } @@ -126,10 +130,19 @@ void qtminesweeper::keyPressEvent(QKeyEvent *event) } -void qtminesweeper::generatecellpos(cell *c) +void qtminesweeper::generatecellpos() { - int dx, dy; - dx = dy = 0; - c->movetogridpos(dx, dy); - printf("%d\n", c->getrealx()); + int x, y, z; + x = y = 0; + int target = 0; + for (z = 0; z < GRIDHEIGHT/SQUARESIZE; z++) + { + for (x = 0; x < GRIDWIDTH/SQUARESIZE; x++) + { + cells[target].movetogridpos(x, y); + target++; + } + y++; + x = 0; + } } diff --git a/qtminesweeper.h b/qtminesweeper.h index 19d4240..7c8d914 100644 --- a/qtminesweeper.h +++ b/qtminesweeper.h @@ -41,7 +41,7 @@ class qtminesweeper : public QWidget void drawgrid(QPainter *painter); void drawcursor(QPainter *painter); void drawcells(QPainter *painter); - void generatecellpos(cell *c); + void generatecellpos(); selector cursor; QList<cell> cells; @@ -22,6 +22,10 @@ class square { + /* + * real* indicates the pixel position + * grid* indicates grid position + */ public: explicit square(); /* init function */ int getgridx(); @@ -31,10 +35,6 @@ class square void movetogridpos(int x, int y); private: - /* - * real* indicates the pixel position - * grid* indicates grid position - */ int realx; int realy; |