-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcell.cpp
157 lines (132 loc) · 3.47 KB
/
cell.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
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
//
// Created by funny on 4/16/2023.
//
#include "cell.h"
#include <iostream>
using namespace std;
cell::cell(textures* ptr, int x, int y) {
texturemanager = ptr;
revealed = false;
flagged = false;
type = "0";
backsprite.setTexture(*ptr->gettexture("tile_hidden"));
backsprite.setPosition(x * 32, y * 32);
flagsprite.setTexture(*ptr->gettexture("flag"));
flagsprite.setPosition(x * 32, y * 32);
frontsprite.setPosition(x * 32, y * 32);
frontspriteptr = &frontsprite;
backspriteptr = & backsprite;
flagspriteptr = &flagsprite;
xindex = x;
yindex = y;
}
void cell::setnearbycellsvect(std::vector<cell*> vect) {
for (int i = 0; i < vect.size(); i++) {
nearbycellsvect.push_back(vect[i]);
}
}
int cell::getxindex() {
return xindex;
}
int cell::getyindex() {
return yindex;
}
void cell::printcellvect() {
for (int i = 0; i < nearbycellsvect.size(); i++) {
nearbycellsvect[i]->printcords();
cout << " ";
}
}
void cell::printcords() {
cout << "(" << xindex << ", " << yindex << ")";
}
void cell::settype(std::string s) {
type = s;
}
std::string cell::gettype() {
return type;
}
void cell::setnearbybombcount() {
int count = 0;
for (int i = 0; i < nearbycellsvect.size(); i++) {
if (nearbycellsvect[i]->gettype() == "X")
count++;
}
type = to_string(count);
}
sf::Sprite *cell::getfrontspriteptr() {
return frontspriteptr;
}
sf::Sprite *cell::getbackspriteptr() {
return backspriteptr;
}
bool cell::leftclick() {
if (!flagged and !revealed) {
revealed = true;
backsprite.setTexture(*texturemanager->gettexture("tile_revealed"));
if (type == "0")
clearsurroundingzeroes();
if (type == "X") {
return false;
}
}
return true;
}
void cell::clearsurroundingzeroes() {
revealed = true;
flagged = false;
backsprite.setTexture(*texturemanager->gettexture("tile_revealed"));
for (int i = 0; i < nearbycellsvect.size(); i++) {
if (!nearbycellsvect[i]->revealed and !nearbycellsvect[i]->flagged)
if (nearbycellsvect[i]->type == "0") {
nearbycellsvect[i]->clearsurroundingzeroes();
}
else if (nearbycellsvect[i]->type != "X") {
nearbycellsvect[i]->revealed = true;
nearbycellsvect[i]->backsprite.setTexture(*texturemanager->gettexture("tile_revealed"));
nearbycellsvect[i]->flagged = false;
}
}
}
bool cell::isrevealed() {
return revealed;
}
bool cell::rightclick() {
flagged = !flagged;
return flagged;
}
bool cell::isflagged() {
return flagged;
}
sf::Sprite *cell::getflagspriteptr() {
return flagspriteptr;
}
void cell::setcellsprite() {
if (type == "X") {
frontsprite.setTexture(*texturemanager->gettexture("mine"));
}
else
frontsprite.setTexture(*texturemanager->gettexture("number_" + type));
}
void cell::clearcell() {
delete this;
}
void cell::pause() {
backsprite.setTexture(*texturemanager->gettexture("tile_revealed"));
}
void cell::unpause() {
if (!revealed)
backsprite.setTexture(*texturemanager->gettexture("tile_hidden"));
}
void cell::setflagged(bool f) {
flagged = f;
}
void cell::setrevealed(bool f) {
revealed = f;
if (f) {
backsprite.setTexture(*texturemanager->gettexture("tile_revealed"));
}
}
void cell::setred() {
backsprite.setColor(sf::Color(250, 0, 0));
}