-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmine.cpp
More file actions
88 lines (75 loc) · 1.99 KB
/
mine.cpp
File metadata and controls
88 lines (75 loc) · 1.99 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
#include "mine.h"
Mine::Mine(sf::Vector2f _position, bool actualMine) {
sprite.setPosition(_position);
//makes it invisible
sprite.setColor(sf::Color(255,255,255,0));
exists = actualMine;
isDrawn = false;
//only needs a texture if it exists
if (exists) {
mineTexture.loadFromFile("images/mine.png");
sprite.setTexture(mineTexture);
isDrawn = true;
}
}
Mine::Mine() {
sprite.setPosition(0,0);
exists = false;
isDrawn = false;
}
sf::Vector2f Mine::getLocation() {
return sprite.getPosition();
}
sf::Color Mine::getColor() {
return sprite.getColor();
}
void Mine::setColor(sf::Color color) {
sprite.setColor(color);
}
//overload assignment operator
void Mine::operator=(Mine& m) {
//sets the variable to the pass
sprite.setPosition(m.getLocation());
sprite.setColor(m.getColor());
exists = m.doesExist();
nearMines = m.getNearMines();
neighbors = m.neighbors;
isDrawn = m.isDrawn;
//if it is supposed to exit it sets the texture to mine.png
if (exists)
{
mineTexture.loadFromFile("images/mine.png");
sprite.setTexture(mineTexture);
}
}
sf::Sprite* Mine::getSprite() {
return &sprite;
}
bool Mine::doesExist() {
return exists;
}
void Mine::setNeighbors(std::array<Mine*, 8> _neighbors) {
neighbors = _neighbors;
if (!this->doesExist())
{
//counts the number of nearby mines
nearMines = 0;
for(int i = 0; i < 8; i ++) {
if (neighbors[i] != nullptr) {
if(neighbors[i]->doesExist()) {
nearMines++;
}
}
}
if(nearMines != 0)
{
//leads in the correct file number then sets the sprite to look like it
isDrawn = true;
mineTexture.loadFromFile("images/number_" + std::to_string(nearMines) + ".png");
sprite.setTexture(mineTexture);
}
}
}
int Mine::getNearMines() {
return nearMines;
}