diff --git a/dialog.c b/dialog.c index 43e1206..6db2251 100644 --- a/dialog.c +++ b/dialog.c @@ -103,12 +103,30 @@ void init_dialogs(Game *g) { 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; + + Dialog *dekiyaku_end_of_round_dialog = &dialogs[4]; + dekiyaku_end_of_round_dialog->text_count = 3; + dekiyaku_end_of_round_dialog->text[0] = malloc(200); + dekiyaku_end_of_round_dialog->text[1] = malloc(200); + dekiyaku_end_of_round_dialog->text[2] = malloc(200); + strcpy(dekiyaku_end_of_round_dialog->text[0], "Player score"); + strcpy(dekiyaku_end_of_round_dialog->text[1], "Right score"); + strcpy(dekiyaku_end_of_round_dialog->text[2], "Left score"); + dekiyaku_end_of_round_dialog->text_color = BLACK; + dekiyaku_end_of_round_dialog->options_count = 1; + dekiyaku_end_of_round_dialog->game = g; + + dekiyaku_end_of_round_dialog->options[0].text = malloc(50); + strcpy(dekiyaku_end_of_round_dialog->options[0].text, "Okay"); + dekiyaku_end_of_round_dialog->options[0].color = GREEN; + dekiyaku_end_of_round_dialog->options[0].handle = &handle_click_ok_end_of_round; } 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]; } +void dekiyaku_end_of_round_dialog(Game *g) { g->dialog = &dialogs[4]; } Rectangle dialog_option_outer_rectangle(Dialog *d, int i) { return (Rectangle) { diff --git a/dialog.h b/dialog.h index 2ee34a3..6468947 100644 --- a/dialog.h +++ b/dialog.h @@ -31,6 +31,7 @@ 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 dekiyaku_end_of_round_dialog(Game *g); void dialog_draw(Dialog *d); void dialog_handle_input(Dialog *d); diff --git a/game.c b/game.c index 62a92bb..bffc62d 100644 --- a/game.c +++ b/game.c @@ -78,6 +78,9 @@ void initialize_game(Game *g) { g->player.points_string[0] = '\0'; g->right.points_string[0] = '\0'; g->left.points_string[0] = '\0'; + g->player.name = "Player"; + g->right.name = "Right"; + g->left.name = "Left"; g->player.hand.count = 0; g->right.hand.count = 0; @@ -315,8 +318,8 @@ void run_frame_initializing(Game *g) { add_to_hand(&g->deck, c); } - shuffle_hand(&g->deck); - // order_deck(&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); @@ -598,9 +601,44 @@ void run_frame_calculating_scores(Game *g) { } } +void calculate_dekiyaku_score(Game *g, Player *p) { + Dekiyaku d; + calculate_dekiyaku(&p->scored, &d); + if (p->dekiyaku_action == DEKIYAKU_ACTION_SHOUBU) { + sprintf(g->dialog->text[0], "%s wins with dekiyaku!", p->name); + dekiyaku_to_string(&d, g->dialog->text[1]); + sprintf(g->dialog->text[2], "%s wins %d kan", p->name, dekiyaku_score(&d)); + transfer_kan(g, &p->points, &g->player.points, dekiyaku_score(&d)); + transfer_kan(g, &p->points, &g->right.points, dekiyaku_score(&d)); + transfer_kan(g, &p->points, &g->left.points, dekiyaku_score(&d)); + } else { + sprintf(g->dialog->text[0], "%s cancels with dekiyaku!", p->name); + dekiyaku_to_string(&d, g->dialog->text[1]); + if (dekiyaku_score(&d) % 2) { + sprintf(g->dialog->text[2], "%s wins %d.5 kan", p->name, dekiyaku_score(&d) / 2); + transfer_points(g, &p->points, &g->player.points, (dekiyaku_score(&d) * g->kan_value) / 2); + transfer_points(g, &p->points, &g->right.points, (dekiyaku_score(&d) * g->kan_value) / 2); + transfer_points(g, &p->points, &g->left.points, (dekiyaku_score(&d) * g->kan_value) / 2); + } else { + sprintf(g->dialog->text[2], "%s wins %d kan", p->name, dekiyaku_score(&d) / 2); + transfer_kan(g, &p->points, &g->player.points, dekiyaku_score(&d) / 2); + transfer_kan(g, &p->points, &g->right.points, dekiyaku_score(&d) / 2); + transfer_kan(g, &p->points, &g->left.points, dekiyaku_score(&d) / 2); + } + } +} + void run_frame_calculating_dekiyaku_score(Game *g) { - printf("Somebody won with dekiyaku. Cool.\n"); fflush(stdout); - g->state = GAME_STATE_INITIALIZING; + dekiyaku_end_of_round_dialog(g); + if (g->player.dekiyaku_action == DEKIYAKU_ACTION_CANCEL || g->player.dekiyaku_action == DEKIYAKU_ACTION_SHOUBU) { + calculate_dekiyaku_score(g, &g->player); + } else if (g->right.dekiyaku_action == DEKIYAKU_ACTION_CANCEL || g->right.dekiyaku_action == DEKIYAKU_ACTION_SHOUBU) { + calculate_dekiyaku_score(g, &g->right); + } else if (g->left.dekiyaku_action == DEKIYAKU_ACTION_CANCEL || g->left.dekiyaku_action == DEKIYAKU_ACTION_SHOUBU) { + calculate_dekiyaku_score(g, &g->left); + } else { + // Hands are exhausted + } } void run_frame_end_of_round(Game *g) { @@ -738,7 +776,7 @@ void draw_frame(Game *g) { if (is_player_turn(g)) { switch (g->state) { case GAME_STATE_CHOOSING_FROM_HAND: - DrawText("Choose a card to play", 60, 485, 20, BLACK); + DrawText("Choose a card to play from your hand", 60, 485, 20, BLACK); break; case GAME_STATE_CHOOSING_TARGET: DrawText("Choose a target on the field", 60, 485, 20, BLACK); diff --git a/player.h b/player.h index 9b1a815..d7f6465 100644 --- a/player.h +++ b/player.h @@ -12,6 +12,7 @@ typedef enum PlayerSeat { struct Player { PlayerSeat seat; + char *name; Hand hand, scored; Teyaku teyaku; Dekiyaku dekiyaku;