diff options
author | Jakob Kaivo <jkk@ung.org> | 2019-12-05 13:04:49 -0500 |
---|---|---|
committer | Jakob Kaivo <jkk@ung.org> | 2019-12-05 13:04:49 -0500 |
commit | 0132202c2c3a501567680f5289198af0ec8e3af3 (patch) | |
tree | 3aac83117db5fac20996f3a8af7eb4e1ead4648c | |
parent | 2287af016aabde82d8df386d4ea62128177db05b (diff) |
ask whether or not you want to play again after winning
-rw-r--r-- | bs.c | 23 |
1 files changed, 18 insertions, 5 deletions
@@ -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; } |