-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Main Logic Works, Have to add customizability, UI etc.
- Loading branch information
Showing
9 changed files
with
102 additions
and
16 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,51 @@ | ||
#include "headers/Cell.hpp" | ||
#include <SFML/Graphics.hpp> | ||
|
||
#include "Headers/Grid.hpp" | ||
#include "Headers/Cell.hpp" | ||
|
||
Cell::Cell() | ||
{ | ||
} | ||
|
||
Cell::Cell(int i, int j, float x) | ||
Cell::Cell(int i, int j, float size) | ||
{ | ||
x = i; | ||
y = j; | ||
alive = rand() % 2; | ||
shape = sf::RectangleShape(sf::Vector2f(size, size)); | ||
shape.setPosition(i * size, j * size); | ||
} | ||
|
||
void Cell::render() | ||
{ | ||
shape = sf::RectangleShape(sf::Vector2f(x, x)); | ||
shape.setPosition(i * x, j * x); | ||
shape.setFillColor(sf::Color::White); | ||
shape.setOutlineThickness(1.0f); | ||
shape.setOutlineColor(sf::Color(255, 0, 0)); | ||
if (alive) | ||
{ | ||
shape.setFillColor(sf::Color::White); | ||
} | ||
else | ||
{ | ||
shape.setFillColor(sf::Color::Black); | ||
} | ||
} | ||
|
||
void Cell::setNeighbors(int _neighbors) | ||
{ | ||
neighbors = _neighbors; | ||
} | ||
|
||
void Cell::update() | ||
{ | ||
|
||
if (neighbors > 3 && alive) | ||
{ | ||
alive = false; | ||
} | ||
else if (neighbors == 3 and !alive) | ||
{ | ||
alive = true; | ||
} | ||
else if (neighbors < 2 && alive) | ||
{ | ||
alive = false; | ||
} | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,19 @@ | ||
#pragma once | ||
#include <SFML/Graphics.hpp> | ||
|
||
class Cell | ||
{ | ||
private: | ||
bool nextAliveState; | ||
int x, y; | ||
int neighbors; | ||
|
||
public: | ||
sf::RectangleShape shape; | ||
bool alive; | ||
void render(); | ||
void update(); | ||
|
||
void setNeighbors(int _neighbors); | ||
|
||
Cell(); | ||
Cell(int i, int j, float size); | ||
}; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,19 @@ | ||
#pragma once | ||
|
||
#include "Cell.hpp" | ||
class Grid | ||
{ | ||
private: | ||
int x, y; | ||
int size; | ||
Cell *cells = nullptr; | ||
|
||
public: | ||
int size; | ||
Grid(int _size, int _x, int _y); | ||
|
||
void update(); | ||
void render(sf::RenderWindow &window); | ||
|
||
Cell *getCell(int xpos, int ypos); | ||
void setNeighbors(int xpos, int ypos); | ||
}; |
This file contains 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