diff options
-rw-r--r-- | .cache/clangd/index/main.c.B35546292B5EA1F4.idx | bin | 3382 -> 3652 bytes | |||
-rw-r--r-- | .cache/clangd/index/ring.h.D0AA315870801682.idx | bin | 576 -> 872 bytes | |||
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | src/main.c | 36 | ||||
-rw-r--r-- | src/ring.c | 22 | ||||
-rw-r--r-- | src/ring.h | 1 | ||||
-rw-r--r-- | src/tower.c | 5 |
7 files changed, 59 insertions, 6 deletions
diff --git a/.cache/clangd/index/main.c.B35546292B5EA1F4.idx b/.cache/clangd/index/main.c.B35546292B5EA1F4.idx Binary files differindex a5094ec..02a1be3 100644 --- a/.cache/clangd/index/main.c.B35546292B5EA1F4.idx +++ b/.cache/clangd/index/main.c.B35546292B5EA1F4.idx diff --git a/.cache/clangd/index/ring.h.D0AA315870801682.idx b/.cache/clangd/index/ring.h.D0AA315870801682.idx Binary files differindex acdc302..304b0bb 100644 --- a/.cache/clangd/index/ring.h.D0AA315870801682.idx +++ b/.cache/clangd/index/ring.h.D0AA315870801682.idx @@ -1 +1,2 @@ .cache +.cache/* @@ -84,6 +84,26 @@ void draw_body() { mvprintw(getcury(wmain)+1, 10, " ======= "); mvprintw(getcury(wmain)+1, 10, "---------"); */ + + // DEBUG + mvprintw(0, 0, "tower 1: %c %c %c", (towers[0].rings[0] ? 'X' : '_'), (towers[0].rings[1] ? 'X' : '_'), (towers[0].rings[2] ? 'X' : '_')); + mvprintw(1, 0, "tower 2: %c %c %c", (towers[1].rings[0] ? 'X' : '_'), (towers[1].rings[1] ? 'X' : '_'), (towers[1].rings[2] ? 'X' : '_')); + mvprintw(2, 0, "tower 3: %c %c %c", (towers[2].rings[0] ? 'X' : '_'), (towers[2].rings[1] ? 'X' : '_'), (towers[2].rings[2] ? 'X' : '_')); + mvprintw(3, 0, "ring 1:"); + mvprintw(4, 2, "location: %d", rings[0].location); + mvprintw(5, 2, "held: %d", rings[0].held); + mvprintw(6, 2, "size: %d", rings[0].size); + mvprintw(7, 2, "ascii: %s", rings[0].ascii); + mvprintw(8, 0, "ring 2:"); + mvprintw(9, 2, "location: %d", rings[1].location); + mvprintw(10, 2, "held: %d", rings[1].held); + mvprintw(11, 2, "size: %d", rings[1].size); + mvprintw(12, 2, "ascii: %s", rings[1].ascii); + mvprintw(13, 0, "ring 3:"); + mvprintw(14, 2, "location: %d", rings[2].location); + mvprintw(15, 2, "held: %d", rings[2].held); + mvprintw(16, 2, "size: %d", rings[2].size); + mvprintw(17, 2, "ascii: %s", rings[2].ascii); } void draw_tower(int ring_index, int startx, int starty) { @@ -136,12 +156,18 @@ void input_loop() { // pickup a ring case ' ': // spacebar - // TODO check if a ring is already held, in which case we need to do something else - pickup_ring(); - draw_body(); - wrefresh(wbody); + if(held == NULL) { + pickup_ring(); + draw_body(); + wrefresh(wbody); + } + else { + if(drop_ring()) { + draw_body(); + wrefresh(wbody); + } + } break; - } } } @@ -19,8 +19,28 @@ void pickup_ring() { } } - if(pickup > 0) { + if(pickup >= 0) { held = &rings[pickup]; held->held = true; + towers[hover].rings[pickup] = false; } } + +bool drop_ring() { + int i; + + // should not be called if we are not holding a ring + assert(held != NULL); + + //determine if we are allowed to drop the ring here + for(i = 2; i > held->size; --i) { + if(towers[held->location].rings[i]) { + return false; + } + } + + held->held = false; + towers[held->location].rings[i] = true; + held = NULL; + return true; +} @@ -14,5 +14,6 @@ extern Ring rings[3]; extern Ring *held; void pickup_ring(); +bool drop_ring(); #endif diff --git a/src/tower.c b/src/tower.c index 9220db2..6dcbc9a 100644 --- a/src/tower.c +++ b/src/tower.c @@ -1,3 +1,6 @@ +#include <stdlib.h> + +#include "ring.h" #include "tower.h" int hover_max = 2; @@ -5,9 +8,11 @@ int hover_max = 2; void hover_move_right() { ++hover; if(hover > hover_max) hover = hover_max; + if(held != NULL) held->location = hover; } void hover_move_left() { --hover; if(hover < 0) hover = 0; + if(held != NULL) held->location = hover; } |