aboutsummaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c70
1 files changed, 68 insertions, 2 deletions
diff --git a/src/main.c b/src/main.c
index 465b5ca..57b8179 100644
--- a/src/main.c
+++ b/src/main.c
@@ -3,10 +3,76 @@
int main()
{
initscr();
+ noecho();
+ cbreak();
- refresh();
- getch();
+ int width, height;
+ getmaxyx(stdscr, height, width);
+ (void)height;
+ int win_width = width / 3;
+
+ WINDOW *wins[3];
+ for (int i = 0; i < 3; i++)
+ {
+ refresh();
+ if ((wins[i] = newwin(0, win_width, 0, i * win_width)) == NULL)
+ abort();
+ box(wins[i], 0, 0);
+ /* wrefresh(wins[i]); */
+ }
+
+ t_tower towers[3];
+ towers_init(towers, 3);
+
+ int from_selection = 0;
+ int to_selection = 1;
+ bool mode_from = true;
+ bool running = true;
+ while (running)
+ {
+ for (int i = 0; i < 3; i++)
+ {
+ int highlight_level = 0;
+ if (i == from_selection)
+ highlight_level = 1;
+ tower_put(&towers[i], wins[i], highlight_level);
+ }
+
+ char c;
+ c = getch();
+
+ int selection = mode_from ? from_selection : to_selection;
+ switch (c)
+ {
+ case 'q':
+ running = false;
+ break;
+ case 'j':
+ selection--;
+ break;
+ case 'k':
+ selection++;
+ break;
+ case '\n':
+ if (mode_from)
+ from_selection = selection;
+ else
+ to_selection = selection;
+ if (!mode_from)
+ towers_move(towers, from_selection, to_selection);
+ mode_from = !mode_from;
+ break;
+ }
+ selection %= 3;
+ mvprintw(0, 0, "%d", selection);
+ refresh();
+ }
+
+ /* refresh(); */
+
+ for (int i = 0; i < 3; i++)
+ delwin(wins[3]);
endwin();
return 0;
}