aboutsummaryrefslogtreecommitdiff
path: root/src/tower.c
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2020-06-28 08:34:16 +0200
committerCharles <sircharlesaze@gmail.com>2020-06-28 08:34:16 +0200
commitfeae9f442000cf218c249e6e163e8b5137771857 (patch)
tree4244ae75d5c39e8442d65c9357d66bf91924f6b3 /src/tower.c
parentb9c8bbac74bb828eeae033a54c1f25d1711cf66a (diff)
downloadhanoi-feae9f442000cf218c249e6e163e8b5137771857.tar.gz
hanoi-feae9f442000cf218c249e6e163e8b5137771857.tar.bz2
hanoi-feae9f442000cf218c249e6e163e8b5137771857.zip
Added player controls
Diffstat (limited to 'src/tower.c')
-rw-r--r--src/tower.c47
1 files changed, 31 insertions, 16 deletions
diff --git a/src/tower.c b/src/tower.c
index a92a201..b31eaf7 100644
--- a/src/tower.c
+++ b/src/tower.c
@@ -1,23 +1,28 @@
#include "tower.h"
-static uint8_t st_tower_pop(t_tower tower)
+static uint8_t st_tower_pop(t_tower *tower)
{
- if (tower.len == 0)
+ if (tower->len == 0)
abort();
- uint8_t top = tower.data[tower.len - 1];
- tower.len--;
+ uint8_t top = tower->data[tower->len - 1];
+ tower->len--;
return top;
}
-static void st_tower_push(t_tower tower, uint8_t top)
+static void st_tower_push(t_tower *tower, uint8_t top)
{
- if (tower.len == MAX_HEIGHT)
+ if (tower->len == MAX_HEIGHT)
abort();
- tower.data[tower.len] = top;
- tower.len++;
+ tower->data[tower->len] = top;
+ tower->len++;
}
-void towers_init(t_tower towers[3], size_t disk_num)
+uint8_t tower_peek(t_tower *tower)
+{
+ return (tower->data[tower->len - 1]);
+}
+
+void towers_init(t_tower towers[3], size_t disk_num)
{
memset(towers[0].data, 0, sizeof(t_tower));
memset(towers[1].data, 0, sizeof(t_tower));
@@ -29,28 +34,38 @@ void towers_init(t_tower towers[3], size_t disk_num)
towers[2].len = 0;
}
-void towers_move(t_tower towers[3], size_t from, size_t to)
+void towers_move(t_tower towers[3], size_t from, size_t to)
{
if (from > 2 || to > 2)
abort();
- st_tower_push(towers[to], st_tower_pop(towers[from]));
+ st_tower_push(&towers[to], st_tower_pop(&towers[from]));
}
-void tower_put(t_tower *tower, WINDOW *win, int highlight_level)
+void tower_put(t_tower *tower, WINDOW *win, enum e_highlight highlight_level)
{
int height, width;
getmaxyx(win, height, width);
- if (highlight_level == 1)
- wattron(win, A_BOLD);
+ wclear(win);
+ if (highlight_level & HIGHLIGHT_FROM)
+ mvwaddstr(win, 1, 1, "SELECTED");
+ if (highlight_level & HIGHLIGHT_CURRENT)
+ wattron(win, A_REVERSE);
mvwvline(win, 1, width / 2, '|', height - 2);
for (size_t i = 0; i < tower->len; i++)
{
int disk_width = tower->data[i] * 2 + 1;
+ if (disk_width > width - 2)
+ {
+ disk_width = width - 5;
+ wattron(win, A_BOLD);
+ mvwprintw(win, height - i - 2, 0, "%2d", tower->data[i]);
+ wattroff(win, A_BOLD);
+ }
mvwhline(win, height - i - 2, width / 2 - disk_width / 2, '#', disk_width);
}
- if (highlight_level == 1)
- wattroff(win, A_BOLD);
+ if (highlight_level & HIGHLIGHT_CURRENT)
+ wattroff(win, A_REVERSE);
wrefresh(win);
}