summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordaniel-Jones <daniel@danieljon.es>2018-09-04 20:34:39 +0930
committerdaniel-Jones <daniel@danieljon.es>2018-09-04 20:34:39 +0930
commit06aca0d336b4c6fc08f1b448c271ce8b4e5144e8 (patch)
tree89e871a2a746734cd9cda34c3ab72686fb409bc1
parentd986eabb3c0009b1180707cbbc88125312f9212a (diff)
downloadqtminesweeper-06aca0d336b4c6fc08f1b448c271ce8b4e5144e8.tar.gz
qtminesweeper-06aca0d336b4c6fc08f1b448c271ce8b4e5144e8.zip
added BUGS file, created and placed cells
However, the cells will soon use std::vector instead of a qt list.
-rw-r--r--BUGS4
-rw-r--r--cell.cpp5
-rw-r--r--cell.h1
-rw-r--r--qtminesweeper.cpp39
-rw-r--r--qtminesweeper.h2
-rw-r--r--square.h8
6 files changed, 41 insertions, 18 deletions
diff --git a/BUGS b/BUGS
new file mode 100644
index 0000000..ba206ea
--- /dev/null
+++ b/BUGS
@@ -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)
+
+
diff --git a/cell.cpp b/cell.cpp
index e4035ba..d32fa6e 100644
--- a/cell.cpp
+++ b/cell.cpp
@@ -39,3 +39,8 @@ void cell::flagcheck()
if (flags & NUMBER)
puts("number");
}
+
+int cell::getflags()
+{
+ return flags;
+}
diff --git a/cell.h b/cell.h
index 846f9d0..8ede3fa 100644
--- a/cell.h
+++ b/cell.h
@@ -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;
diff --git a/square.h b/square.h
index 46a513b..254f905 100644
--- a/square.h
+++ b/square.h
@@ -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;