From 23a3e7a41a05ce3e4c8dcc2bc75ce366d8fd8fbb Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Mon, 19 Dec 2016 22:03:27 +0100 Subject: Add population display --- src/world.h | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'src') 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, HEIGHT> matrix_; }; -- cgit v1.2.3