Allow the game to end

This commit is contained in:
Bill Rossi 2025-02-22 12:01:00 -05:00
parent e585551df0
commit 5d966ecfd0
4 changed files with 50 additions and 3 deletions

View File

@ -29,8 +29,12 @@ void handle_click_sage(Game *g) {
g->state = GAME_STATE_CHOOSING_FROM_HAND;
}
void handle_click_ok_end_of_round(Game *g) {
g->state = GAME_STATE_END_OF_ROUND;
}
void handle_click_ok_end_of_game(Game *g) {
g->state = GAME_STATE_INITIALIZING;
g->state = GAME_STATE_TITLE_SCREEN;
}
void init_dialogs(Game *g) {
@ -85,12 +89,26 @@ void init_dialogs(Game *g) {
no_dekiyaku_end_of_round_dialog->options[0].text = malloc(50);
strcpy(no_dekiyaku_end_of_round_dialog->options[0].text, "Okay");
no_dekiyaku_end_of_round_dialog->options[0].color = GREEN;
no_dekiyaku_end_of_round_dialog->options[0].handle = &handle_click_ok_end_of_game;
no_dekiyaku_end_of_round_dialog->options[0].handle = &handle_click_ok_end_of_round;
Dialog *end_of_game_dialog = &dialogs[3];
end_of_game_dialog->text_count = 3;
end_of_game_dialog->text[0] = malloc(200);
strcpy(end_of_game_dialog->text[0], "Game over something");
end_of_game_dialog->text_color = BLACK;
end_of_game_dialog->options_count = 1;
end_of_game_dialog->game = g;
end_of_game_dialog->options[0].text = malloc(50);
strcpy(end_of_game_dialog->options[0].text, "Okay");
end_of_game_dialog->options[0].color = GREEN;
end_of_game_dialog->options[0].handle = &handle_click_ok_end_of_game;
}
void cancel_dialog(Game *g) { g->dialog = &dialogs[0]; }
void shoubu_dialog(Game *g) { g->dialog = &dialogs[1]; }
void no_dekiyaku_end_of_round_dialog(Game *g) { g->dialog = &dialogs[2]; }
void end_of_game_dialog(Game *g) { g->dialog = &dialogs[3]; }
Rectangle dialog_option_outer_rectangle(Dialog *d, int i) {
return (Rectangle) {

View File

@ -30,6 +30,7 @@ void init_dialogs(Game *g);
void cancel_dialog(Game *g);
void shoubu_dialog(Game *g);
void no_dekiyaku_end_of_round_dialog(Game *g);
void end_of_game_dialog(Game *g);
void dialog_draw(Dialog *d);
void dialog_handle_input(Dialog *d);

25
game.c
View File

@ -128,6 +128,9 @@ void initialize_game(Game *g) {
break;
}
g->dealer = &g->player;
g->number_of_rounds = 3;
g->current_round = 0;
g->state = GAME_STATE_INITIALIZING;
}
@ -554,7 +557,8 @@ void run_frame_calculating_scores(Game *g) {
break;
case SPECIAL_CASE_DOUBLE_EIGHTS:
case SPECIAL_CASE_SIXTEEN_CHAFF:
sprintf(g->dialog->text[0], "Double eights or 16 chaff!");
if (special_case.type == SPECIAL_CASE_DOUBLE_EIGHTS) sprintf(g->dialog->text[0], "Double eights!");
else sprintf(g->dialog->text[0], "Sixteen chaff!");
sprintf(g->dialog->text[1], "Player %d gets %d kan\n", special_case.target, special_case.score);
switch (special_case.target) {
case SPECIAL_CASE_TARGET_PLAYER:
@ -599,6 +603,19 @@ void run_frame_calculating_dekiyaku_score(Game *g) {
g->state = GAME_STATE_INITIALIZING;
}
void run_frame_end_of_round(Game *g) {
g->current_round++;
if (g->current_round >= g->number_of_rounds) {
g->state = GAME_STATE_END_OF_GAME;
} else {
g->state = GAME_STATE_INITIALIZING;
}
}
void run_frame_end_of_game(Game *g) {
end_of_game_dialog(g);
}
void move_cards(Game *g) {
float delta = GetFrameTime();
for (int i = 0; i < 48; i++) {
@ -667,6 +684,12 @@ void run_frame(Game *g) {
case GAME_STATE_CALCULATING_DEKIYAKU_SCORE:
run_frame_calculating_dekiyaku_score(g);
break;
case GAME_STATE_END_OF_ROUND:
run_frame_end_of_round(g);
break;
case GAME_STATE_END_OF_GAME:
run_frame_end_of_game(g);
break;
}
}

5
game.h
View File

@ -29,6 +29,9 @@ typedef enum GameState {
GAME_STATE_SELECTING_DEKIYAKU_ACTION,
GAME_STATE_CALCULATING_SCORES,
GAME_STATE_CALCULATING_DEKIYAKU_SCORE,
GAME_STATE_END_OF_ROUND,
GAME_STATE_END_OF_GAME,
GAME_STATE_TITLE_SCREEN,
} GameState;
struct Game {
@ -45,6 +48,8 @@ struct Game {
int turn_number;
Dialog *dialog;
Player *dealer;
int number_of_rounds;
int current_round;
};
void initialize_game(Game *g);