aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdrian Kummerlaender2016-12-19 22:03:27 +0100
committerAdrian Kummerlaender2016-12-19 22:03:27 +0100
commit23a3e7a41a05ce3e4c8dcc2bc75ce366d8fd8fbb (patch)
tree32cd9dd6231e5fff40d477a23543747c62b65a38 /src
parenta653a3a2823e9bcecc80ec639cd5d2743f3edd04 (diff)
downloadtermlife-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.h15
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_;
};