aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdrian Kummerlaender2016-12-10 12:20:12 +0100
committerAdrian Kummerlaender2016-12-10 12:20:12 +0100
commit585e558afb23acc87d3ad71b2fef974281a185dd (patch)
tree42f588ecfe1bf93fd3a75fc90eafcfd5e45b02bf /src
parentb72dcd74717366f145b029d89ae11a085a5f5997 (diff)
downloadtermlife-585e558afb23acc87d3ad71b2fef974281a185dd.tar
termlife-585e558afb23acc87d3ad71b2fef974281a185dd.tar.gz
termlife-585e558afb23acc87d3ad71b2fef974281a185dd.tar.bz2
termlife-585e558afb23acc87d3ad71b2fef974281a185dd.tar.lz
termlife-585e558afb23acc87d3ad71b2fef974281a185dd.tar.xz
termlife-585e558afb23acc87d3ad71b2fef974281a185dd.tar.zst
termlife-585e558afb23acc87d3ad71b2fef974281a185dd.zip
Extract painting and display age of world
Diffstat (limited to 'src')
-rw-r--r--src/world.h42
1 files changed, 14 insertions, 28 deletions
diff --git a/src/world.h b/src/world.h
index 297d0c5..d951cf5 100644
--- a/src/world.h
+++ b/src/world.h
@@ -6,8 +6,6 @@
#include <tuple>
#include <cstdint>
-#include <termbox.h>
-
namespace life {
template<
@@ -24,15 +22,7 @@ class World {
}
}
- void summonLifeAt(std::size_t x, std::size_t y) {
- this->matrix_[y][x] = true;
- }
-
- void extinguishLifeAt(std::size_t x, std::size_t y) {
- this->matrix_[y][x] = false;
- }
-
- bool isLifeAt(std::ptrdiff_t x, std::ptrdiff_t y) {
+ bool isLifeAt(std::ptrdiff_t x, std::ptrdiff_t y) const {
if ( x >= 0 &&
x < WIDTH &&
y >= 0 &&
@@ -43,7 +33,7 @@ class World {
}
}
- std::uint8_t lifeDensityAt(std::size_t x, std::size_t y) {
+ std::uint8_t lifeDensityAt(std::size_t x, std::size_t y) const {
std::uint8_t counter = 0;
if ( this->isLifeAt(x - 1, y) ) {
@@ -74,6 +64,18 @@ class World {
return counter;
}
+ std::size_t getAge() const {
+ return this->age_;
+ }
+
+ void summonLifeAt(std::size_t x, std::size_t y) {
+ this->matrix_[y][x] = true;
+ }
+
+ void extinguishLifeAt(std::size_t x, std::size_t y) {
+ this->matrix_[y][x] = false;
+ }
+
void tick() {
this->age_++;
@@ -118,22 +120,6 @@ class World {
}
}
- void draw() {
- tb_clear();
-
- for ( std::size_t j = 0; j < HEIGHT; j++ ) {
- for ( std::size_t i = 0; i < WIDTH; i++ ) {
- if ( this->matrix_[j][i] ) {
- tb_change_cell(i, j, 0x2588, TB_BLACK, TB_GREEN);
- } else {
- tb_change_cell(i, j, 0x2591, TB_BLACK, TB_BLUE);
- }
- }
- }
-
- tb_present();
- }
-
private:
std::size_t age_ = 0;