-
Notifications
You must be signed in to change notification settings - Fork 0
/
field.cpp
executable file
·72 lines (60 loc) · 1.01 KB
/
field.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include "field.hpp"
Field::Field(int x, int y) : x(x), y(y), flagged(false), discovered(false), numOfMinesAround(0)
{
}
void Field::showBomb()
{
}
void Field::revealField()
{
}
void Field::flagField()
{
if (!discovered)
{
flagged = !flagged;
emit flagField(x, y, flagged);
}
}
BombField::BombField(int x, int y): Field(x,y)
{
}
void BombField::revealField()
{
emit endGame(false);
}
void BombField::showBomb()
{
emit bombField(x, y);
}
void BombField::showField()
{
this->showBomb();
}
EmptyField::EmptyField(int x, int y): Field(x,y)
{
}
void EmptyField::revealField()
{
if (!discovered && !flagged)
{
this->discovered = true;
emit updateTile(x, y, numOfMinesAround, discovered);
emit revealField(x, y);
emit addToDiscoveredFields();
if (numOfMinesAround == 0)
{
for (int i=x-1; i<= x+1; i++)
{
for (int j = y-1; j<= y+1; j++)
{
emit revealField(i, j);
}
}
}
}
}
void EmptyField::showField()
{
emit updateTile(x, y, numOfMinesAround, true);
}