summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordaniel-Jones <daniel@danieljon.es>2018-09-02 11:47:15 +0930
committerdaniel-Jones <daniel@danieljon.es>2018-09-02 11:47:15 +0930
commit12f885b28b9740349dcee6a7c57d7b774017fd05 (patch)
treea1f19acd069ba42dd757c006783157013a53aed5
parent34eab2a4cd9a20f7deae3b7225a11678c240ede9 (diff)
downloadqtminesweeper-12f885b28b9740349dcee6a7c57d7b774017fd05.tar.gz
qtminesweeper-12f885b28b9740349dcee6a7c57d7b774017fd05.zip
initial cell flag system setup
-rw-r--r--cell.cpp23
-rw-r--r--cell.h11
-rw-r--r--qtminesweeper.cpp3
-rw-r--r--selector.h1
-rw-r--r--square.cpp8
-rw-r--r--square.h7
6 files changed, 48 insertions, 5 deletions
diff --git a/cell.cpp b/cell.cpp
index d99789b..e4035ba 100644
--- a/cell.cpp
+++ b/cell.cpp
@@ -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");
+}
diff --git a/cell.h b/cell.h
index a53ee8b..f3d4d75 100644
--- a/cell.h
+++ b/cell.h
@@ -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)
diff --git a/selector.h b/selector.h
index c86b651..78f75c0 100644
--- a/selector.h
+++ b/selector.h
@@ -23,7 +23,6 @@ class cur : public square
{
public:
- int test = 1;
private:
diff --git a/square.cpp b/square.cpp
index 23e2e86..be0b32c 100644
--- a/square.cpp
+++ b/square.cpp
@@ -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);
}
diff --git a/square.h b/square.h
index 14377c1..fd37b58 100644
--- a/square.h
+++ b/square.h
@@ -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