From 6821e8706bb4293f2325bce10a03b99bdf966052 Mon Sep 17 00:00:00 2001 From: Louie S Date: Wed, 1 Nov 2023 16:42:05 -0400 Subject: Add move counter --- src/Makefile.in | 3 +++ src/main.c | 26 ++++++++++++++++++++++---- 2 files changed, 25 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/Makefile.in b/src/Makefile.in index ba0ac54..ac5f4fb 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -178,6 +178,7 @@ AWK = @AWK@ CC = @CC@ CCDEPMODE = @CCDEPMODE@ CFLAGS = @CFLAGS@ +CPP = @CPP@ CPPFLAGS = @CPPFLAGS@ CURSES_CFLAGS = @CURSES_CFLAGS@ CURSES_LIBS = @CURSES_LIBS@ @@ -187,7 +188,9 @@ DEPDIR = @DEPDIR@ ECHO_C = @ECHO_C@ ECHO_N = @ECHO_N@ ECHO_T = @ECHO_T@ +EGREP = @EGREP@ EXEEXT = @EXEEXT@ +GREP = @GREP@ INSTALL = @INSTALL@ INSTALL_DATA = @INSTALL_DATA@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ diff --git a/src/main.c b/src/main.c index 4e74d19..c4fd207 100644 --- a/src/main.c +++ b/src/main.c @@ -9,6 +9,7 @@ void draw_title(); void draw_body(); void draw_tower(int ring_index, int startx, int starty); +void draw_move_count(); void input_loop(); WINDOW *wmain; @@ -17,6 +18,7 @@ Ring rings[3]; Ring *held = NULL; Tower towers[3]; int hover = 0; // initially, hover over the leftmost tower +int move_count = 0; int main() { @@ -43,12 +45,13 @@ int main() curs_set(0); keypad(stdscr, TRUE); - // draw layout + // draw title draw_title(); - wbody = newwin(9, getmaxx(wmain), 8, 0); - draw_body(); - refresh(); + + // draw body + wbody = newwin(12, getmaxx(wmain), 8, 0); + draw_body(); wrefresh(wbody); input_loop(); @@ -68,6 +71,7 @@ void draw_body() { draw_tower(0, getmaxx(wbody)/4 - 4, 8); draw_tower(1, getmaxx(wbody)/2 - 4, 8); draw_tower(2, 3*getmaxx(wbody)/4 - 4, 8); + draw_move_count(); // FIXME placeholder implementation /* @@ -138,6 +142,18 @@ void draw_tower(int ring_index, int startx, int starty) { wattroff(wbody, A_BOLD); } +void draw_move_count() { + // tried to use log10, but this created weird problems + int local_move_count = move_count; + int count_length = 1; + while(local_move_count >= 10) { + local_move_count /= 10; + ++count_length; + } + mvwprintw(wbody, 10, getmaxx(wbody)/2 - (7 + count_length)/2, + "moves: %d", move_count); +} + void input_loop() { int input = 0; @@ -161,6 +177,7 @@ void input_loop() { case ' ': // spacebar if(held == NULL) { pickup_ring(); + if(held != NULL) ++move_count; draw_body(); wrefresh(wbody); } @@ -171,6 +188,7 @@ void input_loop() { } } break; + } } } -- cgit