diff options
| author | Charles <sircharlesaze@gmail.com> | 2020-06-27 16:23:31 +0200 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2020-06-27 16:23:31 +0200 |
| commit | b9c8bbac74bb828eeae033a54c1f25d1711cf66a (patch) | |
| tree | 4483b62c30c9f9be46a9c1f699c4c6076f69a8e7 /src/main.c | |
| parent | e2c1a8b40787516b9f8f3697a73ac406eae05e6f (diff) | |
| download | hanoi-b9c8bbac74bb828eeae033a54c1f25d1711cf66a.tar.gz hanoi-b9c8bbac74bb828eeae033a54c1f25d1711cf66a.tar.bz2 hanoi-b9c8bbac74bb828eeae033a54c1f25d1711cf66a.zip | |
Added tower display
Diffstat (limited to 'src/main.c')
| -rw-r--r-- | src/main.c | 70 |
1 files changed, 68 insertions, 2 deletions
@@ -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; } |
