diff options
author | Adrian Kummerlaender | 2016-12-09 23:28:46 +0100 |
---|---|---|
committer | Adrian Kummerlaender | 2016-12-09 23:28:46 +0100 |
commit | b72dcd74717366f145b029d89ae11a085a5f5997 (patch) | |
tree | c90959183927ee1e9adc3dc08c631e2ae17f79ef /life.cc | |
download | termlife-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.cc | 46 |
1 files changed, 46 insertions, 0 deletions
@@ -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; +} |