-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCell.cpp
More file actions
138 lines (132 loc) · 3.96 KB
/
Cell.cpp
File metadata and controls
138 lines (132 loc) · 3.96 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#include "Cell.h"
Cell::Cell(const sf::Color &color, int indexX, int indexY, int width, bool mine, int number) :
indexX(indexX),
indexY(indexY),
width(width),
mine(mine),
flag(false),
visible(false),
wrongFlag(false),
number(number),
color(color) { }
void Cell::draw(sf::RenderWindow &window) const{
sf::RectangleShape shape;
shape.setSize({(float) this->width, (float) this->width});
shape.setFillColor(this->color);
shape.setPosition({(float) this->indexX * this->width, (float) this->indexY * this->width});
shape.setOutlineColor(sf::Color::Black);
//shape.setOutlineThickness(1.0);
window.draw(shape);
if(this->visible) {
if(this->mine && !this->wrongFlag){
sf::Texture t;
t.loadFromFile("assets/images/bomb.png");
sf::Sprite s;
s.setTexture(t, false);
s.setScale({3, 3});
s.setPosition({(float) this->indexX * this->width + 1, (float) this->indexY * this->width + 1});
window.draw(s);
}
if(this->number > 0){
sf::Texture t;
switch(this->number){
case 1: t.loadFromFile("assets/images/one.png");
break;
case 2: t.loadFromFile("assets/images/two.png");
break;
case 3: t.loadFromFile("assets/images/three.png");
break;
case 4: t.loadFromFile("assets/images/four.png");
break;
case 5: t.loadFromFile("assets/images/five.png");
break;
case 6: t.loadFromFile("assets/images/six.png");
break;
case 7: t.loadFromFile("assets/images/seven.png");
break;
case 8: t.loadFromFile("assets/images/eight.png");
break;
}
sf::Sprite s;
s.setTexture(t, false);
s.setScale({3, 3});
s.setPosition({(float) this->indexX * this->width + 1, (float) this->indexY * this->width + 1});
window.draw(s);
}
}
if(this->flag){
sf::Texture t;
if(this->wrongFlag){
t.loadFromFile("assets/images/Cross.png");
}else {
t.loadFromFile("assets/images/flag.png");
}
sf::Sprite s;
s.setTexture(t, false);
s.setScale({3, 3});
s.setPosition({(float) this->indexX * this->width + 1, (float) this->indexY * this->width + 1});
window.draw(s);
}
}
bool Cell::canOpen() const{
return (this->number >= 0 && !this->flag && !this->mine && !this->visible);
}
bool Cell::contains(int x, int y) const {
int this_X = this->indexX * this->width;
int this_Y = this->indexY * this->width;
return (x >= this_X && x <= this_X + this->width && y >= this_Y && y <= this_Y + this->width);
}
void Cell::setIndexY(int indexY){
this->indexY = indexY;
}
void Cell::setIndexX(int indexX){
this->indexX = indexX;
}
void Cell::setWidth(int width){
this->width = width;
}
void Cell::setNumber(int number){
this->number = number;
}
void Cell::setColor(sf::Color color){
this->color = color;
}
void Cell::setMine(bool mine){
this->mine = mine;
}
void Cell::setFlag(bool flag){
this->flag = flag;
}
void Cell::setVisible(bool visible){
this->visible = visible;
}
void Cell::setWrongFlag(bool wrongFlag){
this->wrongFlag = wrongFlag;
}
int Cell::getIndexY() const{
return this->indexX;
}
int Cell::getIndexX() const{
return this->indexY;
}
int Cell::getWidth() const{
return this->width;
}
int Cell::getNumber() const{
return this->number;
}
sf::Color Cell::getColor() const{
return this->color;
}
bool Cell::isMine() const{
return this->mine;
}
bool Cell::isFlag() const{
return this->flag;
}
bool Cell::isVisible() const{
return this->visible;
}
bool Cell::isWrongFlag() const {
return this->wrongFlag;
}