endscreen.c 909 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #include <curses.h>
  2. #include <stdlib.h>
  3. #include "endscreen.h"
  4. int* load_highscores() {
  5. FILE* file;
  6. if ((file = fopen(HIGHSCORE_FILE, "r")) == 0) {
  7. int* ret = malloc(sizeof(int));
  8. ret[0] = 0;
  9. return ret;
  10. }
  11. return NULL;
  12. }
  13. void display_endscreen(int currentScore) {
  14. if (2 * 40 > COLS || 20 > LINES) {
  15. endwin();
  16. fprintf(stderr, "Snek: Terminal is to small, must be 80x20 at least\n");
  17. exit(1);
  18. }
  19. WINDOW* win = subwin(stdscr, 20, 80, 0, 0);
  20. clear();
  21. wattrset(win, COLOR_PAIR(7));
  22. mvwprintw(win, 1, 1, "GAME OVER! YOUR SCORE: %d", currentScore);
  23. mvwprintw(win, 2, 1, "Press SPACEBAR to play again, q to quit");
  24. wrefresh(win);
  25. nodelay(stdscr, FALSE);
  26. while(1) {
  27. char c = getch();
  28. switch(c) {
  29. case ' ':
  30. nodelay(stdscr, TRUE);
  31. delwin(win);
  32. return;
  33. case 'q':
  34. endwin();
  35. exit(0);
  36. default:
  37. break;
  38. }
  39. }
  40. }