diff options
author | Adrian Kummerlaender | 2016-12-19 22:03:27 +0100 |
---|---|---|
committer | Adrian Kummerlaender | 2016-12-19 22:03:27 +0100 |
commit | 23a3e7a41a05ce3e4c8dcc2bc75ce366d8fd8fbb (patch) | |
tree | 32cd9dd6231e5fff40d477a23543747c62b65a38 /src | |
parent | a653a3a2823e9bcecc80ec639cd5d2743f3edd04 (diff) | |
download | termlife-23a3e7a41a05ce3e4c8dcc2bc75ce366d8fd8fbb.tar termlife-23a3e7a41a05ce3e4c8dcc2bc75ce366d8fd8fbb.tar.gz termlife-23a3e7a41a05ce3e4c8dcc2bc75ce366d8fd8fbb.tar.bz2 termlife-23a3e7a41a05ce3e4c8dcc2bc75ce366d8fd8fbb.tar.lz termlife-23a3e7a41a05ce3e4c8dcc2bc75ce366d8fd8fbb.tar.xz termlife-23a3e7a41a05ce3e4c8dcc2bc75ce366d8fd8fbb.tar.zst termlife-23a3e7a41a05ce3e4c8dcc2bc75ce366d8fd8fbb.zip |
Add population display
Diffstat (limited to 'src')
-rw-r--r-- | src/world.h | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/world.h b/src/world.h index 61423c4..e70e20e 100644 --- a/src/world.h +++ b/src/world.h @@ -53,15 +53,25 @@ class World { return this->age_; } + std::size_t getPopulation() const { + return this->population_; + } + void summonLifeAt(std::size_t x, std::size_t y) { if ( this->area_(x, y) ) { - this->matrix_[y][x] = true; + if ( !this->matrix_[y][x] ) { + this->matrix_[y][x] = true; + this->population_ += 1; + } } } void extinguishLifeAt(std::size_t x, std::size_t y) { if ( this->area_(x, y) ) { - this->matrix_[y][x] = false; + if ( this->matrix_[y][x] ) { + this->matrix_[y][x] = false; + this->population_ -= 1; + } } } @@ -111,6 +121,7 @@ class World { const util::BoxTraverser area_; std::size_t age_{}; + std::size_t population_{}; std::array<std::array<bool, WIDTH>, HEIGHT> matrix_; }; |