aboutsummaryrefslogtreecommitdiff
path: root/life.cc
diff options
context:
space:
mode:
authorAdrian Kummerlaender2016-12-09 23:28:46 +0100
committerAdrian Kummerlaender2016-12-09 23:28:46 +0100
commitb72dcd74717366f145b029d89ae11a085a5f5997 (patch)
treec90959183927ee1e9adc3dc08c631e2ae17f79ef /life.cc
downloadtermlife-b72dcd74717366f145b029d89ae11a085a5f5997.tar
termlife-b72dcd74717366f145b029d89ae11a085a5f5997.tar.gz
termlife-b72dcd74717366f145b029d89ae11a085a5f5997.tar.bz2
termlife-b72dcd74717366f145b029d89ae11a085a5f5997.tar.lz
termlife-b72dcd74717366f145b029d89ae11a085a5f5997.tar.xz
termlife-b72dcd74717366f145b029d89ae11a085a5f5997.tar.zst
termlife-b72dcd74717366f145b029d89ae11a085a5f5997.zip
Initial working version
...of a plain Game Of Life displayed using `Termbox`.
Diffstat (limited to 'life.cc')
-rw-r--r--life.cc46
1 files changed, 46 insertions, 0 deletions
diff --git a/life.cc b/life.cc
new file mode 100644
index 0000000..7f0ace7
--- /dev/null
+++ b/life.cc
@@ -0,0 +1,46 @@
+#include <termbox.h>
+
+#include "world.h"
+
+int main(int, char*[]) {
+ tb_init();
+
+ tb_select_input_mode(TB_INPUT_ESC | TB_INPUT_MOUSE);
+
+ life::World<20,20> world;
+
+ while ( true ) {
+ struct tb_event ev;
+ int t = tb_poll_event(&ev);
+
+ if ( t == -1 ) {
+ tb_shutdown();
+ return -1;
+ }
+
+ switch (t) {
+ case TB_EVENT_KEY:
+ switch ( ev.key ) {
+ case TB_KEY_ESC:
+ tb_shutdown();
+ return 0;
+ case TB_KEY_SPACE:
+ world.tick();
+ break;
+ }
+ break;
+ case TB_EVENT_MOUSE:
+ if (ev.key == TB_KEY_MOUSE_LEFT) {
+ world.summonLifeAt(ev.x, ev.y);
+ }
+
+ break;
+ case TB_EVENT_RESIZE:
+ break;
+ }
+
+ world.draw();
+ }
+
+ return 0;
+}