diff options
author | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2022-04-07 07:24:16 -0700 |
---|---|---|
committer | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2022-04-07 07:26:53 -0700 |
commit | e37769bfcf7564ebc5e658c7f473230efb9a4bcd (patch) | |
tree | 18b3ea59b379d2467a73ef369cda11ca7847f9bb /dartbot.c | |
parent | d25968ab0568611017014e6eac65e65774c8bd4a (diff) | |
download | dartboat-e37769bfcf7564ebc5e658c7f473230efb9a4bcd.tar.gz dartboat-e37769bfcf7564ebc5e658c7f473230efb9a4bcd.tar.xz |
add ncurses interface; not interactive yet
Diffstat (limited to 'dartbot.c')
-rw-r--r-- | dartbot.c | 86 |
1 files changed, 80 insertions, 6 deletions
@@ -6,6 +6,7 @@ #include <stdlib.h> #include <string.h> #include <time.h> +#include <unistd.h> #define HORIZONTAL_STDEV 24 #define VERTICAL_STDEV 24 @@ -308,23 +309,96 @@ void test_match(int start_points) free(n); } printf("\n"); + + free(v.darts); } } -int main() +void draw(WINDOW *w, struct visit *visits, int n_visits) +{ + werase(w); + box(w, 0, 0); + wmove(w, 0, 2); + waddstr(w, "dartbot"); + + int rem = 501; + char buf[100]; + int buflen = 0; + + int offset = 2; + int start_visit = (LINES - 3 > n_visits) ? 0 : (n_visits - (LINES - 3)); + if (start_visit == 0 && LINES - 3 > n_visits) { + wmove(w, offset-start_visit, 2); + sprintf(buf, "(%2d) %3d", 0, rem); + waddstr(w, buf); + offset = 3; + } + + for (int i = 0; i < n_visits; ++i) { + struct visit v = visits[i]; + rem -= v.points; + + if (i < start_visit) + continue; + + wmove(w, offset+i-start_visit, 2); + + buflen += sprintf(buf, "(%2d) %3d", i+1, rem); + + for (int j = 0; j < v.n_darts; ++j) { + char *n = segment_name(v.darts[j]); + buflen += sprintf(buf + buflen, j == 0 ? " %4s" :" %4s", n); + free(n); + } + + buflen = 0; + waddstr(w, buf); + } + + wrefresh(w); +} + +void test_curses_match() { - /* initscr(); - addstr("test"); - refresh(); + curs_set(0); + noecho(); + + WINDOW *w = newwin(LINES, COLS, 0, 0); + + int rem = 501; + printf("(%2d) %3d\n", 0, rem); + struct visit *visits = calloc(1000, sizeof(*visits)); // FIXME + int n_visits = 0; - getch(); + draw(w, visits, n_visits); + wrefresh(w); + + while(rem > 0) { + struct visit v = test_visit(rem); + visits[n_visits] = v; + ++n_visits; + rem -= v.points; + + usleep(250000); + draw(w, visits, n_visits); + } + + for (int i = 0; i < n_visits; ++i) + free(visits[i].darts); + free(visits); + wgetch(w); + delwin(w); endwin(); - */ +} + +int main() +{ srand(time(NULL)); init_sectors(); init_centre_dists(); + test_curses_match(); test_match(501); return 0; |