1 #include <Display/Animations/AnimationGameOfLife.hpp> 2 #include <Engine/Graphics/Colors.hpp> 3 #include <Engine/Helpers/Utils.hpp> 5 static ColorPair white;
6 static ColorPair yellow = Colors::pair(
"yellow",
"default");
8 AnimationGameOfLife::AnimationGameOfLife(Window* window):
12 AnimationGameOfLife::~AnimationGameOfLife()
16 void AnimationGameOfLife::load()
18 unsigned int width = window->getW();
19 unsigned int height = window->getH();
21 cells =
new Array2D<bool>(width, height);
24 for (
unsigned int i = 0; i < width; i++)
25 for (
unsigned int j = 0; j < height; j++)
26 cells->set(i, j, Utils::Random::booleanWithChance(0.20));
30 void AnimationGameOfLife::update()
33 if (timer.delta_ms() < 200)
37 for (
unsigned int i = 1; i < (cells->width() - 1); i++)
39 for (
unsigned int j = 1; j < (cells->height() - 1); j++)
51 n[0] = cells->at(i - 1, j - 1);
52 n[1] = cells->at(i , j - 1);
53 n[2] = cells->at(i + 1, j - 1);
54 n[3] = cells->at(i - 1, j );
55 n[4] = cells->at(i + 1, j );
56 n[5] = cells->at(i - 1, j + 1);
57 n[6] = cells->at(i , j + 1);
58 n[7] = cells->at(i + 1, j + 1);
61 for (
int x = 0; x < 8; x++)
69 cells->set(i, j,
false);
72 cells->set(i, j,
true);
75 cells->set(i, j,
false);
81 cells->set(i, j,
true);
88 void AnimationGameOfLife::draw()
90 for (
unsigned int i = 0; i < (cells->width()); i++)
92 for (
unsigned int j = 0; j < (cells->height()); j++)
102 window->printChar(c, i, j, p);