Created
March 16, 2015 11:46
-
-
Save Tasemu/2c67e66b4c2485aec1fe to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SFML/Graphics.hpp> | |
#include <stdlib.h> /* srand, rand */ | |
#include <time.h> /* time */ | |
#include <iostream> | |
#include <array> | |
class Node : public sf::CircleShape { | |
public: | |
bool isAlive() { | |
return alive; | |
} | |
void birth() { | |
alive = true; | |
} | |
void kill() { | |
alive = false; | |
} | |
private: | |
int width = 5; | |
int height = 5; | |
bool alive = false; | |
}; | |
int main(){ | |
int iSecret; | |
/* initialize random seed: */ | |
srand(time(NULL)); | |
/* generate secret number between 1 and 10: */ | |
std::array<std::array<Node, 100>, 100> grid; | |
sf::RenderWindow window(sf::VideoMode(640, 480), "SFML Application"); | |
for (int i = 0; i < 100; i++) | |
{ | |
for (int j = 0; j < 100; j++) | |
{ | |
iSecret = rand() % 10 + 1; | |
if (iSecret < 2) { | |
grid[i][j].birth(); | |
} | |
} | |
} | |
while (window.isOpen()){ | |
sf::Event event; | |
while (window.pollEvent(event)){ | |
if (event.type == sf::Event::Closed) | |
window.close(); | |
} | |
window.clear(); | |
for (int y = 0; y < 100; y++) | |
{ | |
for (int x = 0; x < 100; x++) | |
{ | |
if (grid[y][x].isAlive()) { | |
grid[y][x].setRadius(3.f); | |
grid[y][x].setPosition(0.f + (6.f * y), 0.f + (6.f * x)); | |
grid[y][x].setFillColor(sf::Color::Cyan); | |
window.draw(grid[y][x]); | |
} | |
} | |
} | |
window.display(); | |
} | |
} | |
/* | |
int coint = 0; | |
if (grid[u - 1][h].isAlive()) { | |
coint++; | |
} | |
if (grid[u - 1][h + 1].isAlive()) { | |
coint++; | |
} | |
if (grid[u][h + 1].isAlive()) { | |
coint++; | |
} | |
if (grid[u + 1][h + 1].isAlive()) { | |
coint++; | |
} | |
if (grid[u + 1][h].isAlive()) { | |
coint++; | |
} | |
if (grid[u + 1][h - 1].isAlive()) { | |
coint++; | |
} | |
if (grid[u][h - 1].isAlive()) { | |
coint++; | |
} | |
if (grid[u - 1][h - 1].isAlive()) { | |
coint++; | |
} | |
if (coint < 2 || coint > 3) { | |
grid[u][h].kill(); | |
} | |
if (coint == 2) { | |
grid[u][h] = grid[u][h]; | |
} | |
if (coint == 3) { | |
grid[u][h].birth(); | |
} | |
if (grid[u][h].isAlive()) { | |
grid[u][h].setRadius(3.f); | |
grid[u][h].setPosition(0.f + (6.f * u), 0.f + (6.f * h)); | |
grid[u][h].setFillColor(sf::Color::Cyan); | |
window.draw(grid[u][h]); | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment