Development idk

This commit is contained in:
Bill Rossi 2025-02-20 19:21:03 -05:00
parent 6a58fa2601
commit 4963835a13
4 changed files with 53 additions and 29 deletions

View File

@ -7,6 +7,7 @@ typedef enum DekiyakuAction {
DEKIYAKU_ACTION_NONE, DEKIYAKU_ACTION_NONE,
DEKIYAKU_ACTION_SAGE, DEKIYAKU_ACTION_SAGE,
DEKIYAKU_ACTION_SHOUBU, DEKIYAKU_ACTION_SHOUBU,
DEKIYAKU_ACTION_CANCEL,
} DekiyakuAction; } DekiyakuAction;
typedef enum DekiyakuMeldType { typedef enum DekiyakuMeldType {

View File

@ -9,13 +9,24 @@
Dialog dialogs[2]; Dialog dialogs[2];
void handle_click_cancel_yes(Game *g) { void handle_click_cancel_yes(Game *g) {
g->state = GAME_STATE_CHOOSING_FROM_HAND; g->player.dekiyaku_action = DEKIYAKU_ACTION_CANCEL;
g->state = GAME_STATE_CALCULATING_DEKIYAKU_SCORE;
} }
void handle_click_cancel_no(Game *g) { void handle_click_cancel_no(Game *g) {
g->state = GAME_STATE_CHOOSING_FROM_HAND; g->state = GAME_STATE_CHOOSING_FROM_HAND;
} }
void handle_click_shoubu(Game *g) {
g->player.dekiyaku_action = DEKIYAKU_ACTION_SHOUBU;
g->state = GAME_STATE_CALCULATING_DEKIYAKU_SCORE;
}
void handle_click_sage(Game *g) {
g->player.dekiyaku_action = DEKIYAKU_ACTION_SAGE;
g->state = GAME_STATE_CHOOSING_FROM_HAND;
}
void init_dialogs(Game *g) { void init_dialogs(Game *g) {
Dialog *cancel_dialog = &dialogs[0]; Dialog *cancel_dialog = &dialogs[0];
cancel_dialog->text = malloc(200); cancel_dialog->text = malloc(200);

65
game.c
View File

@ -87,6 +87,10 @@ void initialize_game(Game *g) {
g->right.points_string[0] = '\0'; g->right.points_string[0] = '\0';
g->left.points_string[0] = '\0'; g->left.points_string[0] = '\0';
g->player.dekiyaku_action = DEKIYAKU_ACTION_NONE;
g->right.dekiyaku_action = DEKIYAKU_ACTION_NONE;
g->left.dekiyaku_action = DEKIYAKU_ACTION_NONE;
g->player.hand.count = 0; g->player.hand.count = 0;
g->player.hand.position = (Vector2) { 300, 600 }; g->player.hand.position = (Vector2) { 300, 600 };
g->player.hand.display_type = HAND_DISPLAY_ROW; g->player.hand.display_type = HAND_DISPLAY_ROW;
@ -114,7 +118,7 @@ void initialize_game(Game *g) {
Image cards_image = LoadImage("img/cards.png"); Image cards_image = LoadImage("img/cards.png");
g->cards_texture = LoadTextureFromImage(cards_image); g->cards_texture = LoadTextureFromImage(cards_image);
UnloadImage(cards_image); UnloadImage(cards_image);
g->state = GAME_STATE_DEALING; g->state = GAME_STATE_INITIALIZING;
} }
Player *current_player(Game *g) { Player *current_player(Game *g) {
@ -126,13 +130,14 @@ Player *current_player(Game *g) {
case 2: case 2:
return &g->left; return &g->left;
} }
return NULL;
} }
bool is_player_turn(Game *g) { bool is_player_turn(Game *g) {
return current_player(g) == &g->player; return current_player(g) == &g->player;
} }
bool stale_calculation = true;
void handle_input(Game *g) { void handle_input(Game *g) {
if (!is_player_turn(g)) return; if (!is_player_turn(g)) return;
if (g->dialog) return dialog_handle_input(g->dialog); if (g->dialog) return dialog_handle_input(g->dialog);
@ -222,12 +227,14 @@ void run_frame_ai_playing(Game *g) {
} }
} }
void run_frame_dealing(Game *g) { void run_frame_initializing(Game *g) {
// TODO maybe we only need these once per game
kan_points_string(g, g->player.points, g->player.points_string); kan_points_string(g, g->player.points, g->player.points_string);
kan_points_string(g, g->right.points, g->right.points_string); kan_points_string(g, g->right.points, g->right.points_string);
kan_points_string(g, g->left.points, g->left.points_string); kan_points_string(g, g->left.points, g->left.points_string);
g->state = GAME_STATE_DEALING;
}
void run_frame_dealing(Game *g) {
if (g->player.hand.count < 4) { if (g->player.hand.count < 4) {
deal(&g->deck, &g->player.hand, 4, true); deal(&g->deck, &g->player.hand, 4, true);
} else if (g->left.hand.count < 4) { } else if (g->left.hand.count < 4) {
@ -271,21 +278,11 @@ void run_frame_start_of_turn(Game *g) {
} }
void run_frame_checking_for_cancel(Game *g) { void run_frame_checking_for_cancel(Game *g) {
if (g->dialog) return;
if (is_player_turn(g)) { g->dialog = cancel_dialog(); return; }
if (current_player(g)->dekiyaku_action == DEKIYAKU_ACTION_SAGE) { if (current_player(g)->dekiyaku_action == DEKIYAKU_ACTION_SAGE) {
if (is_player_turn(g)) { if (is_player_turn(g)) {
// check for player canceling g->dialog = cancel_dialog();
// if they do:
// g->state = GAME_STATE_CALCULATING_DEKIYAKU_SCORE;
// else
g->state = GAME_STATE_CHOOSING_FROM_HAND;
} else { } else {
// AI decides whether to cancel or not // TODO: the AI might want to cancel at some point
// if they do:
// g->state = GAME_STATE_CALCULATING_DEKIYAKU_SCORE;
// else
g->state = GAME_STATE_CHOOSING_FROM_HAND; g->state = GAME_STATE_CHOOSING_FROM_HAND;
} }
} else { } else {
@ -380,8 +377,13 @@ void run_frame_checking_for_new_dekiyaku(Game *g) {
int new_score = dekiyaku_score(&cp->dekiyaku); int new_score = dekiyaku_score(&cp->dekiyaku);
if (new_score != cp->dekiyaku_score) { if (new_score != cp->dekiyaku_score) {
cp->dekiyaku_score = new_score; cp->dekiyaku_score = new_score;
cp->dekiyaku_action = DEKIYAKU_ACTION_NONE; if (is_player_turn(g)) {
g->state = GAME_STATE_SELECTING_DEKIYAKU_ACTION; g->dialog = shoubu_dialog();
} else {
// TODO: better AI
cp->dekiyaku_action = DEKIYAKU_ACTION_SHOUBU;
g->state = GAME_STATE_CALCULATING_DEKIYAKU_SCORE;
}
} else { } else {
g->state = GAME_STATE_START_OF_TURN; g->state = GAME_STATE_START_OF_TURN;
} }
@ -392,8 +394,7 @@ void run_frame_selecting_dekiyaku_action(Game *g) {
if (g->player.dekiyaku_action != DEKIYAKU_ACTION_NONE) { if (g->player.dekiyaku_action != DEKIYAKU_ACTION_NONE) {
g->state = GAME_STATE_CALCULATING_DEKIYAKU_SCORE; g->state = GAME_STATE_CALCULATING_DEKIYAKU_SCORE;
} else { } else {
printf("Hey you can't choose a dekiyaku action yet, sorry\n"); g->dialog = shoubu_dialog();
g->player.dekiyaku_action = DEKIYAKU_ACTION_SAGE;
} }
} else { } else {
// TODO: better AI // TODO: better AI
@ -442,19 +443,31 @@ void run_frame_calculating_dekiyaku_score(Game *g) {
g->state = GAME_STATE_INITIALIZING; g->state = GAME_STATE_INITIALIZING;
} }
void run_frame(Game *g) { void move_cards(Game *g) {
handle_input(g);
float delta = GetFrameTime(); float delta = GetFrameTime();
bool done_moving = true;
for (int i = 0; i < 48; i++) { for (int i = 0; i < 48; i++) {
move_position(&g->cards[i].move, delta); move_position(&g->cards[i].move, delta);
if (!card_done_moving(&g->cards[i])) done_moving = false;
} }
if (!done_moving) return; }
bool done_moving(Game *g) {
for (int i = 0; i < 48; i++) {
if (!card_done_moving(&g->cards[i])) return false;
}
return true;
}
void run_frame(Game *g) {
handle_input(g);
if (g->dialog) return;
move_cards(g);
if (!done_moving(g)) return;
switch (g->state) { switch (g->state) {
case GAME_STATE_INITIALIZING: case GAME_STATE_INITIALIZING:
run_frame_initializing(g);
return; return;
case GAME_STATE_DEALING: case GAME_STATE_DEALING:
run_frame_dealing(g); run_frame_dealing(g);

View File

@ -12,8 +12,7 @@ typedef enum PlayerSeat {
struct Player { struct Player {
PlayerSeat seat; PlayerSeat seat;
Hand hand; Hand hand, scored;
Hand scored;
Teyaku teyaku; Teyaku teyaku;
Dekiyaku dekiyaku; Dekiyaku dekiyaku;
DekiyakuAction dekiyaku_action; DekiyakuAction dekiyaku_action;