Skip to content

Commit caa7229

Browse files
committed
Implemented cell marks.
Closes #4.
1 parent 6c9ffac commit caa7229

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

Cell.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ void Cell::reset()
1717
{
1818
m_haveMine = false;
1919
m_open = false;
20+
m_mark = 0;
2021
}
2122

2223
int Cell::minesAround() const
@@ -55,6 +56,15 @@ void Cell::open()
5556
}
5657
}
5758

59+
void Cell::toggleMark()
60+
{
61+
if (m_mark == 2) {
62+
m_mark = 0;
63+
} else {
64+
++m_mark;
65+
}
66+
}
67+
5868
void maybeAddCell(QVector<Cell*> *vector, Cell *cell)
5969
{
6070
if (cell) {

Cell.hpp

+5
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ class Cell
2323
bool isOpen() const { return m_open; }
2424
void open();
2525

26+
int mark() const { return m_mark; }
27+
void toggleMark();
28+
2629
QVector<Cell*> getNeighbors() const;
2730

2831
private:
@@ -34,6 +37,8 @@ class Cell
3437
bool m_haveMine;
3538
bool m_open;
3639

40+
int m_mark;
41+
3742
};
3843

3944
#endif // CELL_HPP

CellItem.cpp

+14-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,18 @@ void CellItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
4444
}
4545
} else {
4646
painter->fillRect(border, border, cellSize - border * 2, cellSize - border * 2, Qt::lightGray);
47-
m_text->setText("");
47+
48+
switch (m_cell->mark()) {
49+
case 1:
50+
m_text->setText("!");
51+
break;
52+
case 2:
53+
m_text->setText("?");
54+
break;
55+
default: // case 0
56+
m_text->setText("");
57+
break;
58+
}
4859
}
4960
m_text->setPos((cellSize - m_text->boundingRect().width()) / 2, (cellSize - m_text->boundingRect().height()) / 2);
5061
}
@@ -58,6 +69,8 @@ void CellItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
5869
{
5970
if (event->button() == Qt::LeftButton) {
6071
m_cell->open();
72+
} else if (event->button() == Qt::RightButton) {
73+
m_cell->toggleMark();
6174
}
6275

6376
update();

0 commit comments

Comments
 (0)