summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.cache/clangd/index/main.c.B35546292B5EA1F4.idxbin3382 -> 3652 bytes
-rw-r--r--.cache/clangd/index/ring.h.D0AA315870801682.idxbin576 -> 872 bytes
-rw-r--r--.gitignore1
-rw-r--r--src/main.c36
-rw-r--r--src/ring.c22
-rw-r--r--src/ring.h1
-rw-r--r--src/tower.c5
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
index a5094ec..02a1be3 100644
--- a/.cache/clangd/index/main.c.B35546292B5EA1F4.idx
+++ b/.cache/clangd/index/main.c.B35546292B5EA1F4.idx
Binary files differ
diff --git a/.cache/clangd/index/ring.h.D0AA315870801682.idx b/.cache/clangd/index/ring.h.D0AA315870801682.idx
index acdc302..304b0bb 100644
--- a/.cache/clangd/index/ring.h.D0AA315870801682.idx
+++ b/.cache/clangd/index/ring.h.D0AA315870801682.idx
Binary files differ
diff --git a/.gitignore b/.gitignore
index 16d3c4d..490cac5 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,2 @@
.cache
+.cache/*
diff --git a/src/main.c b/src/main.c
index 54d375f..4039aa3 100644
--- a/src/main.c
+++ b/src/main.c
@@ -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;
-
}
}
}
diff --git a/src/ring.c b/src/ring.c
index 633648b..e73d477 100644
--- a/src/ring.c
+++ b/src/ring.c
@@ -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;
+}
diff --git a/src/ring.h b/src/ring.h
index 0b23bf1..0e146ff 100644
--- a/src/ring.h
+++ b/src/ring.h
@@ -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;
}