manual??? and refactoring

This commit is contained in:
2025-10-17 21:08:03 +02:00
parent a2d4290076
commit 103f85d07e
15 changed files with 211 additions and 52 deletions

View File

@@ -12,7 +12,7 @@
#include "rooster.h"
int same_coordinate(coordinate a, coordinate b) {
int same_coordinate(const coordinate a, const coordinate b) {
return a.x == b.x && a.y == b.y;
}
@@ -35,12 +35,12 @@ void show_grid_on_offset(const rooster *gp, const int starting_x, const int star
refresh();
}
void show_grid(const rooster *rp) {
show_grid_on_offset(rp, 0, 0);
void show_grid(const rooster *gp) {
show_grid_on_offset(gp, 0, 0);
}
void update_grid(rooster *rp, char c, int x, int y) {
if (rooster_plaats(rp, x, y, c) == 1) {
void update_grid(rooster *gp, const char c, const int x, const int y) {
if (rooster_plaats(gp, x, y, c) == 1) {
mvaddch(y, x, c);
}
}
@@ -51,9 +51,9 @@ void update_grid(rooster *rp, char c, int x, int y) {
* Side Effect:
* Clears the console and prints the victory message.
*/
static void display_victory(void) {
static void display_victory(const coordinate location) {
erase();
mvprintw(2,5, "YOU WON!!!!!");
mvprintw(location.y, location.x, "YOU WON!!!!!");
refresh();
}
@@ -63,9 +63,9 @@ static void display_victory(void) {
* Side Effect:
* Clears the console and prints the GAME OVER message.
*/
static void display_loss(void) {
static void display_loss(const coordinate location) {
erase();
mvprintw(2,5, "GAME OVER");
mvprintw(location.y, location.x, "GAME OVER");
refresh();
}
@@ -75,9 +75,9 @@ static void display_loss(void) {
* Side Effect:
* Clears the console and prints the quit message.
*/
static void display_quit(void) {
static void display_quit(const coordinate location) {
erase();
mvprintw(2,5, "You quit the game");
mvprintw(location.y, location.x, "You quit the game");
refresh();
}
@@ -87,42 +87,46 @@ static void display_quit(void) {
* Side Effect:
* Clears the console and prints the hacker man message.
*/
static void display_hackerman(void) {
static void display_hackerman(const coordinate location) {
erase();
mvprintw(2,5, "The hacker man strikes again...");
mvprintw(location.y, location.x, "The hacker man strikes again...");
refresh();
}
void graceful_exit(void) {
mvprintw(25, 5, "Press 'q' to exit.");
void graceful_exit(const coordinate message_location) {
mvprintw(message_location.y, message_location.x, "Press ENTER or SPACE to exit.");
while (1) {
switch (getch()) {
case 'q':
case 'Q':
case KEY_ENTER:
case '\n':
case ' ':
return;
}
}
}
void game_exit_screen(rooster *gp) {
toestand current_state = rooster_vraag_toestand(gp);
void game_exit_screen(const rooster *gp, coordinate location) {
const toestand current_state = rooster_vraag_toestand(gp);
switch (current_state) {
case STATE_GEWONNEN:
display_victory();
display_victory(location);
break;
case STATE_VERLOREN:
display_loss();
display_loss(location);
break;
case STATE_QUIT:
display_quit();
display_quit(location);
break;
default:
display_hackerman();
display_hackerman(location);
}
graceful_exit();
location.y += 2;
graceful_exit(location);
}
static void init_ncurses() {
ESCDELAY = 0;
setlocale(LC_ALL, "");
initscr();
cbreak(); // So you can cancel the game with ctrl + c.