diff options
-rw-r--r-- | cell.cpp | 23 | ||||
-rw-r--r-- | cell.h | 11 | ||||
-rw-r--r-- | qtminesweeper.cpp | 3 | ||||
-rw-r--r-- | selector.h | 1 | ||||
-rw-r--r-- | square.cpp | 8 | ||||
-rw-r--r-- | square.h | 7 |
6 files changed, 48 insertions, 5 deletions
@@ -15,4 +15,27 @@ */ #include "cell.h" +#include <stdio.h> +cell::cell(int flag) +{ + setflags(flag); +} + +void cell::setflags(int flag) +{ + flags = (enum flagtype)flag; +} + +void cell::flagcheck() +{ + puts("cell flags:"); + if (flags & MINE) + puts("mine"); + if (flags & REVEALED) + puts("revealed"); + if (flags & FLAG) + puts("flag"); + if (flags & NUMBER) + puts("number"); +} @@ -23,10 +23,21 @@ class cell : public square { public: + explicit cell(int flag); + enum flagtype + { + REVEALED = 1 << 0, /* square is revealed */ + FLAG = 1 << 1, /* square is a selected flag */ + MINE = 1 << 2, /* square is a mine */ + NUMBER = 1 << 3 /* square is a number */ + }; + void flagcheck(); private: + void setflags(int flag); protected: + enum flagtype flags; }; #endif diff --git a/qtminesweeper.cpp b/qtminesweeper.cpp index 6fd583a..6fc5f2e 100644 --- a/qtminesweeper.cpp +++ b/qtminesweeper.cpp @@ -20,7 +20,8 @@ qtminesweeper::qtminesweeper() { - + cell cell1(cell::MINE | cell::REVEALED); + cell1.flagcheck(); } void qtminesweeper::paintEvent(QPaintEvent *event) @@ -23,7 +23,6 @@ class cur : public square { public: - int test = 1; private: @@ -60,7 +60,15 @@ int square::getgridy() return gridy; } +void square::movetorealpos(int x, int y) +{ + setrealx(x); + setrealy(y); +} + void square::movetogridpos(int x, int y) { + setgridx(x); + setgridy(y); } @@ -24,8 +24,6 @@ class square explicit square(); /* init function */ private: - - protected: /* * real* indicates the pixel position * grid* indicates grid position @@ -42,13 +40,16 @@ class square void setgridx(int x); void setgridy(int y); + void movetorealpos(int x, int y); + int getrealx(); int getrealy(); + protected: int getgridx(); int getgridy(); - void movetogridpos(int x, int y) + void movetogridpos(int x, int y); }; #endif |