-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLifeTile.hpp
More file actions
200 lines (159 loc) · 3.13 KB
/
LifeTile.hpp
File metadata and controls
200 lines (159 loc) · 3.13 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#ifndef LIFETILE_HPP_INCLUDED
#define LIFETILE_HPP_INCLUDED
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <SFML/Graphics.hpp>
#include <SFML/System/Time.hpp>
//#include <SFML/Mouse.hpp>
void pause()
{
std::cin.sync();
std::cin.ignore();
}
class Tile
{
private:
bool Alive;
bool Dying;
bool Spawning;
public:
Tile()
{
Alive = false;
Dying = false;
Spawning = false;
tile.setSize(sf::Vector2f(25,25));
tile.setFillColor(sf::Color::White);
tile.setOutlineColor(sf::Color::Black);
tile.setOutlineThickness(1);
Clear();
}
Tile(sf::Vector2f pos)
{
Alive = false;
Dying = false;
Pos = pos;
tile.setPosition(Pos);
tile.setSize(sf::Vector2f(20,20));
tile.setFillColor(sf::Color::White);
tile.setOutlineColor(sf::Color::Black);
tile.setOutlineThickness(1);
}
bool Place(sf::Vector2f pos)
{
Pos = pos;
tile.setPosition(Pos);
Clear();
return true;
}
sf::Vector2f Pos;
sf::RectangleShape tile;
bool UP;
bool DOWN;
bool LEFT;
bool RIGHT;
bool UPLEFT;
bool UPRIGHT;
bool DNLEFT;
bool DNRIGHT;
int Neighbors()
{
int Total = 0;
if(UP)
{
Total++;
}
if(DOWN)
{
Total++;
}
if(LEFT)
{
Total++;
}
if(RIGHT)
{
Total++;
}
if(UPLEFT)
{
Total++;
}
if(UPRIGHT)
{
Total++;
}
if(DNLEFT)
{
Total++;
}
if(DNRIGHT)
{
Total++;
}
return Total;
}
void Clear()
{
UP = false;
DOWN = false;
LEFT = false;
RIGHT = false;
UPLEFT = false;
UPRIGHT = false;
DNLEFT = false;
DNRIGHT = false;
}
void Status()
{
std::cout << "UPLEFT:" << UPLEFT << " UP:" << UP << " UPRIGHT:" << UPRIGHT << " LEFT:" << LEFT << " RIGHT:" << RIGHT << " DNLEFT:" << DNLEFT << " DOWN:" << DOWN << " DNRIGHT:" <<DNRIGHT << std::endl;
}
void Spawn()
{
Alive = true;
Dying = false;
Spawning = true;
tile.setFillColor(sf::Color::Green);
}
void dying()
{
Alive = false;
Spawning = false;
Dying = true;
tile.setFillColor(sf::Color::Red);
//tile.setFillColor(sf::Color::White);
}
void Live()
{
}
void Kill()
{
Alive = false;
Spawning = false;
Dying = false;
tile.setFillColor(sf::Color::White);
}
bool alive()
{
return Alive;
}
void Resolve()
{
if(Dying)
{
Kill();
return;
}
if(Spawning)
{
Alive = true;
Dying = false;
Spawning = false;
tile.setFillColor(sf::Color::Black);
return;
}
Live();
}
};
#endif // LIFETILE_HPP_INCLUDED