diff --git a/dekiyaku.h b/dekiyaku.h index 48bb7f6..3d4566e 100644 --- a/dekiyaku.h +++ b/dekiyaku.h @@ -7,6 +7,7 @@ typedef enum DekiyakuAction { DEKIYAKU_ACTION_NONE, DEKIYAKU_ACTION_SAGE, DEKIYAKU_ACTION_SHOUBU, + DEKIYAKU_ACTION_CANCEL, } DekiyakuAction; typedef enum DekiyakuMeldType { diff --git a/dialog.c b/dialog.c index 0753c42..506ea81 100644 --- a/dialog.c +++ b/dialog.c @@ -9,13 +9,24 @@ Dialog dialogs[2]; 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) { 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) { Dialog *cancel_dialog = &dialogs[0]; cancel_dialog->text = malloc(200); diff --git a/game.c b/game.c index 5587c3b..919e957 100644 --- a/game.c +++ b/game.c @@ -87,6 +87,10 @@ void initialize_game(Game *g) { g->right.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.position = (Vector2) { 300, 600 }; g->player.hand.display_type = HAND_DISPLAY_ROW; @@ -114,7 +118,7 @@ void initialize_game(Game *g) { Image cards_image = LoadImage("img/cards.png"); g->cards_texture = LoadTextureFromImage(cards_image); UnloadImage(cards_image); - g->state = GAME_STATE_DEALING; + g->state = GAME_STATE_INITIALIZING; } Player *current_player(Game *g) { @@ -126,13 +130,14 @@ Player *current_player(Game *g) { case 2: return &g->left; } + + return NULL; } bool is_player_turn(Game *g) { return current_player(g) == &g->player; } -bool stale_calculation = true; void handle_input(Game *g) { if (!is_player_turn(g)) return; 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) { - // TODO maybe we only need these once per game +void run_frame_initializing(Game *g) { 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->left.points, g->left.points_string); + g->state = GAME_STATE_DEALING; +} +void run_frame_dealing(Game *g) { if (g->player.hand.count < 4) { deal(&g->deck, &g->player.hand, 4, true); } 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) { - if (g->dialog) return; - if (is_player_turn(g)) { g->dialog = cancel_dialog(); return; } - if (current_player(g)->dekiyaku_action == DEKIYAKU_ACTION_SAGE) { if (is_player_turn(g)) { - // check for player canceling - // if they do: - // g->state = GAME_STATE_CALCULATING_DEKIYAKU_SCORE; - // else - g->state = GAME_STATE_CHOOSING_FROM_HAND; + g->dialog = cancel_dialog(); } else { - // AI decides whether to cancel or not - // if they do: - // g->state = GAME_STATE_CALCULATING_DEKIYAKU_SCORE; - // else + // TODO: the AI might want to cancel at some point g->state = GAME_STATE_CHOOSING_FROM_HAND; } } else { @@ -380,8 +377,13 @@ void run_frame_checking_for_new_dekiyaku(Game *g) { int new_score = dekiyaku_score(&cp->dekiyaku); if (new_score != cp->dekiyaku_score) { cp->dekiyaku_score = new_score; - cp->dekiyaku_action = DEKIYAKU_ACTION_NONE; - g->state = GAME_STATE_SELECTING_DEKIYAKU_ACTION; + if (is_player_turn(g)) { + g->dialog = shoubu_dialog(); + } else { + // TODO: better AI + cp->dekiyaku_action = DEKIYAKU_ACTION_SHOUBU; + g->state = GAME_STATE_CALCULATING_DEKIYAKU_SCORE; + } } else { 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) { g->state = GAME_STATE_CALCULATING_DEKIYAKU_SCORE; } else { - printf("Hey you can't choose a dekiyaku action yet, sorry\n"); - g->player.dekiyaku_action = DEKIYAKU_ACTION_SAGE; + g->dialog = shoubu_dialog(); } } else { // TODO: better AI @@ -442,19 +443,31 @@ void run_frame_calculating_dekiyaku_score(Game *g) { g->state = GAME_STATE_INITIALIZING; } -void run_frame(Game *g) { - handle_input(g); - +void move_cards(Game *g) { float delta = GetFrameTime(); - bool done_moving = true; for (int i = 0; i < 48; i++) { 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) { case GAME_STATE_INITIALIZING: + run_frame_initializing(g); return; case GAME_STATE_DEALING: run_frame_dealing(g); diff --git a/player.h b/player.h index 0d12fed..9b1a815 100644 --- a/player.h +++ b/player.h @@ -12,8 +12,7 @@ typedef enum PlayerSeat { struct Player { PlayerSeat seat; - Hand hand; - Hand scored; + Hand hand, scored; Teyaku teyaku; Dekiyaku dekiyaku; DekiyakuAction dekiyaku_action;