summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2019-12-05 13:04:49 -0500
committerJakob Kaivo <jkk@ung.org>2019-12-05 13:04:49 -0500
commit0132202c2c3a501567680f5289198af0ec8e3af3 (patch)
tree3aac83117db5fac20996f3a8af7eb4e1ead4648c
parent2287af016aabde82d8df386d4ea62128177db05b (diff)
ask whether or not you want to play again after winning
-rw-r--r--bs.c23
1 files changed, 18 insertions, 5 deletions
diff --git a/bs.c b/bs.c
index a0f95e7..12c9d32 100644
--- a/bs.c
+++ b/bs.c
@@ -269,11 +269,24 @@ int main(int argc, char *argv[])
}
if (nsunk == nships) {
- break;
+ printw("\rYou win! Play again [Y/N]? ");
+ refresh();
+ while ((c = getch()) != 0) {
+ if (tolower(c) == 'n') {
+ endwin();
+ exit(0);
+ } else if (tolower(c) == 'y') {
+ for (size_t i = 0; i < nships; i++) {
+ ships[i].sunk = 0;
+ }
+ free(board1);
+ board1 = setup_board(size);
+ inbuf[0] = '\0';
+ input = inbuf;
+ updatescreen(board1, size, input);
+ break;
+ }
+ }
}
}
-
- endwin();
- printf("You won!\n");
- return 0;
}