-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMine.cpp
More file actions
69 lines (67 loc) · 2.07 KB
/
Copy pathMine.cpp
File metadata and controls
69 lines (67 loc) · 2.07 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
#include "Mine.h"
#include "Toolbox.h"
#include <iostream>
Mine::Mine(sf::Vector2f position) : Tile(position), hasMine(true) {
hasMine = true;
state = HIDDEN;
coordinate = position;
}
void Mine::setState(State _state) {
state = _state;
// Should trigger other behaviors related to the state change (including visualization)
}
Mine::State Mine::getState() {
return state;
}/*
void Mine::setNeighbors(std::array<Mine*, 8> _neighbors) {
neighbors = _neighbors;
}*/
void Mine::onClickLeft() {
if (state == HIDDEN) {
state = EXPLODED;
}
}
void Mine::onClickRight() {
if (state == HIDDEN) {
state = FLAGGED;
}
else if (state == FLAGGED){
state = HIDDEN;
// add one to mine count
}
}
void Mine::draw() {
Toolbox& toolbox = Toolbox::getInstance();
if (state == HIDDEN) {
// Create a sprite and set its texture
sf::Sprite sprite(toolbox.hiddenTile);
// Set the position of the sprite
sprite.setPosition(coordinate.x, coordinate.y);
toolbox.window.draw(sprite);
}
else if (state == FLAGGED) {
// Load the flag texture
// subtract one from mine count
sf::Sprite sprite(toolbox.hiddenTile);
// Set the position of the sprite
sprite.setPosition(coordinate.x, coordinate.y);
toolbox.window.draw(sprite);
sf::Sprite sprite2(toolbox.flag);
sprite2.setPosition(coordinate.x, coordinate.y);
// Draw the flag on top of the tile
toolbox.window.draw(sprite2);
}
else if (state == EXPLODED) {
// subtract one from mine count
sf::Sprite sprite(toolbox.revealedTile);
// Set the position of the sprite
sprite.setPosition(coordinate.x, coordinate.y);
toolbox.window.draw(sprite);
sf::Sprite sprite2(toolbox.mine);
sprite2.setPosition(coordinate.x, coordinate.y);
// Draw the mine on top of the tile
toolbox.window.draw(sprite2);
toolbox.gameState->setPlayStatus(GameState::LOSS);
toolbox.gameState->getPlayStatus();
}
}