summaryrefslogtreecommitdiff
path: root/dartbot.c
diff options
context:
space:
mode:
Diffstat (limited to 'dartbot.c')
-rw-r--r--dartbot.c50
1 files changed, 27 insertions, 23 deletions
diff --git a/dartbot.c b/dartbot.c
index 77681ae..1465128 100644
--- a/dartbot.c
+++ b/dartbot.c
@@ -99,7 +99,7 @@ void init_colours()
FOREACH_COLOUR(GEN_COLOUR_INIT_PAIR)
}
-WINDOW *w, *statw, *promptw;
+WINDOW *w, *titlew, *statw, *promptw;
struct ccoords {
double x, y;
@@ -376,24 +376,26 @@ void user_visit(struct leg *l)
struct visit *v = l->visits + l->n_visits++;
char status[100];
- int len = sprintf(status, "%d remaining", l->rem);
- char *target = CHECKOUTS[2][l->rem-1];
- if (target) {
- int trem = l->rem - segment_points(segment_from_name(target));
- len += sprintf(status + len, " (%s", target);
- if (trem) {
- target = CHECKOUTS[1][trem-1];
- len += sprintf(status + len, "-%s", target);
- trem = trem - segment_points(segment_from_name(target));
-
+ int len = sprintf(status, " %d remaining", l->rem);
+ if (l->rem <= 170) {
+ char *target = CHECKOUTS[2][l->rem-1];
+ if (target) {
+ int trem = l->rem - segment_points(segment_from_name(target));
+ len += sprintf(status + len, " (%s", target);
if (trem) {
- target = CHECKOUTS[0][trem-1];
+ target = CHECKOUTS[1][trem-1];
len += sprintf(status + len, "-%s", target);
+ trem = trem - segment_points(segment_from_name(target));
+
+ if (trem) {
+ target = CHECKOUTS[0][trem-1];
+ len += sprintf(status + len, "-%s", target);
+ }
}
+ len += sprintf(status + len, ")");
}
- len += sprintf(status + len, ")");
}
- char prompt[] = "enter points> ";
+ char prompt[] = " enter points> ";
curses_status(status);
curses_prompt(prompt);
@@ -459,7 +461,7 @@ void curses_draw(struct leg *l1, struct leg *l2)
char buf[100];
int buflen = 0;
- int wlines = LINES - 4;
+ int wlines = LINES - 3;
int n_visits = l1->n_visits > l2->n_visits ? l1->n_visits : l2->n_visits;
int start_visit = (wlines > n_visits) ? 0 : (n_visits - wlines);
int offset = 0;
@@ -514,19 +516,20 @@ void curses_match(int start_points, void (*f1)(struct leg *),
void (*f2)(struct leg *))
{
initscr();
- border(0, 0, 0, 0, 0, 0, 0, 0);
- move(0, 2);
- addstr("dartbot");
refresh();
start_color();
init_colours();
curs_set(0);
noecho();
- w = newwin(LINES-4, COLS-2, 1, 1);
- statw = newwin(1, COLS-2, LINES-3, 1);
- promptw = newwin(1, COLS-2, LINES-2, 1);
+ w = newwin(LINES-3, COLS, 1, 0);
+ titlew = newwin(1, COLS, 0, 0);
+ statw = newwin(1, COLS, LINES-2, 0);
+ promptw = newwin(1, COLS, LINES-1, 0);
+ wbkgd(titlew, COLOR_PAIR(C_STATUS));
wbkgd(statw, COLOR_PAIR(C_STATUS));
+ waddstr(titlew, " dartbot");
+ wrefresh(titlew);
struct leg *l1 = leg_init(start_points);
struct leg *l2 = leg_init(start_points);
@@ -544,15 +547,16 @@ void curses_match(int start_points, void (*f1)(struct leg *),
}
if (l1->rem <= 0)
- curses_status("Player 1 wins.");
+ curses_status(" Player 1 wins.");
else if (l2->rem <= 0)
- curses_status("Player 2 wins.");
+ curses_status(" Player 2 wins.");
leg_free(l1);
leg_free(l2);
wgetch(w);
delwin(promptw);
delwin(statw);
+ delwin(titlew);
delwin(w);
endwin();
}