diff --git a/card.c b/card.c index fc7e8cc..5aba3ee 100644 --- a/card.c +++ b/card.c @@ -44,6 +44,34 @@ void shuffle_hand(Hand *h) { } } +void order_deck(Hand *h) { + Card *swap; + + swap = h->cards[1]; + h->cards[1] = h->cards[47-0]; + h->cards[47-0] = swap; + + swap = h->cards[5]; + h->cards[5] = h->cards[47-1]; + h->cards[47-1] = swap; + + swap = h->cards[9]; + h->cards[9] = h->cards[47-2]; + h->cards[47-2] = swap; + + swap = h->cards[0]; + h->cards[0] = h->cards[47-12]; + h->cards[47-12] = swap; + + swap = h->cards[4]; + h->cards[4] = h->cards[47-13]; + h->cards[47-13] = swap; + + swap = h->cards[8]; + h->cards[8] = h->cards[47-14]; + h->cards[47-14] = swap; +} + void remove_from_hand(Hand *h, Card *c) { bool card_found = false; for (int i = 0; i < h->count - 1; i++) { diff --git a/dialog.c b/dialog.c index 506ea81..e729da2 100644 --- a/dialog.c +++ b/dialog.c @@ -24,6 +24,7 @@ void handle_click_shoubu(Game *g) { void handle_click_sage(Game *g) { g->player.dekiyaku_action = DEKIYAKU_ACTION_SAGE; + g->turn_number++; g->state = GAME_STATE_CHOOSING_FROM_HAND; } @@ -56,16 +57,16 @@ void init_dialogs(Game *g) { shoubu_dialog->options[0].text = malloc(50); strcpy(shoubu_dialog->options[0].text, "Sage"); shoubu_dialog->options[0].color = GREEN; - shoubu_dialog->options[0].handle = NULL; + shoubu_dialog->options[0].handle = &handle_click_sage; shoubu_dialog->options[1].text = malloc(50); strcpy(shoubu_dialog->options[1].text, "Shoubu"); shoubu_dialog->options[1].color = RED; - shoubu_dialog->options[1].handle = NULL; + shoubu_dialog->options[1].handle = &handle_click_shoubu; } -Dialog *cancel_dialog() { return &dialogs[0]; } -Dialog *shoubu_dialog() { return &dialogs[1]; } +void cancel_dialog(Game *g) { g->dialog = &dialogs[0]; } +void shoubu_dialog(Game *g) { g->dialog = &dialogs[1]; } Rectangle dialog_option_outer_rectangle(Dialog *d, int i) { return (Rectangle) { diff --git a/dialog.h b/dialog.h index d762313..e304fa5 100644 --- a/dialog.h +++ b/dialog.h @@ -26,8 +26,8 @@ struct Dialog { }; void init_dialogs(Game *g); -Dialog *cancel_dialog(); -Dialog *shoubu_dialog(); +void cancel_dialog(Game *g); +void shoubu_dialog(Game *g); void dialog_draw(Dialog *d); void dialog_handle_input(Dialog *d); diff --git a/game.c b/game.c index c9df404..5444d42 100644 --- a/game.c +++ b/game.c @@ -127,6 +127,7 @@ void initialize_game(Game *g) { g->dealer = &g->left; break; } + g->dealer = &g->player; g->state = GAME_STATE_INITIALIZING; } @@ -153,7 +154,9 @@ void handle_input(Game *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); + } switch (g->state) { case GAME_STATE_CHOOSING_FROM_HAND: @@ -307,7 +310,8 @@ void run_frame_initializing(Game *g) { add_to_hand(&g->deck, c); } - shuffle_hand(&g->deck); + // shuffle_hand(&g->deck); + order_deck(&g->deck); kan_points_string(g, g->player.points, g->player.points_string); kan_points_string(g, g->right.points, g->right.points_string); @@ -374,7 +378,7 @@ void run_frame_start_of_turn(Game *g) { void run_frame_checking_for_cancel(Game *g) { if (current_player(g)->dekiyaku_action == DEKIYAKU_ACTION_SAGE) { if (is_player_turn(g)) { - g->dialog = cancel_dialog(); + cancel_dialog(g); } else { // TODO: the AI might want to cancel at some point g->state = GAME_STATE_CHOOSING_FROM_HAND; @@ -463,7 +467,6 @@ void run_frame_playing_from_deck(Game *g) { Card *targets[4]; int target_count = 0; valid_targets(top_card, &g->field, &targets[0], &target_count); - Card *target = NULL; if (target_count == 1) { capture_card_from_field(g, top_card, targets[0], &g->deck, to_hand); @@ -485,7 +488,6 @@ void run_frame_choosing_target_from_deck(Game *g) { Card *targets[4]; int target_count = 0; valid_targets(top_card, &g->field, &targets[0], &target_count); - Card *target = NULL; if (is_player_turn(g)) { if (g->current_play_target) { @@ -506,7 +508,7 @@ void run_frame_checking_for_new_dekiyaku(Game *g) { if (new_score != cp->dekiyaku_score) { cp->dekiyaku_score = new_score; if (is_player_turn(g)) { - g->dialog = shoubu_dialog(); + shoubu_dialog(g); } else { // TODO: better AI cp->dekiyaku_action = DEKIYAKU_ACTION_SHOUBU; @@ -522,7 +524,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 { - g->dialog = shoubu_dialog(); + shoubu_dialog(g); } } else { // TODO: better AI