diff --git a/game.c b/game.c index 919e957..a12dc98 100644 --- a/game.c +++ b/game.c @@ -14,23 +14,19 @@ Vector2 mouse_pos; char teyaku_calculation[400]; void initialize_game(Game *g) { + Image cards_image = LoadImage("img/cards.png"); + g->cards_texture = LoadTextureFromImage(cards_image); + UnloadImage(cards_image); + g->deck.count = 0; g->deck.position = (Vector2) { 800, 400 }; g->deck.display_type = HAND_DISPLAY_DECK; g->should_close = false; g->state = GAME_STATE_INITIALIZING; g->field_multiplier = NULL; - g->player.teyaku.calculated = false; - g->left.teyaku.calculated = false; - g->right.teyaku.calculated = false; - g->player.dekiyaku_score = 0; - g->left.dekiyaku_score = 0; - g->right.dekiyaku_score = 0; g->kan_value = 12; - g->current_play_from_hand = NULL; - g->current_play_target = NULL; - g->turn_number = -1; g->dialog = NULL; + init_dialogs(g); for (int i = 0; i < 48; i++) { @@ -74,8 +70,6 @@ void initialize_game(Game *g) { g->cards[i].move.destination = (Vector2) { 800, 400 }; g->cards[i].order = i; g->cards[i].selected = false; - g->deck.cards[i] = &g->cards[i]; - g->deck.count++; } shuffle_hand(&g->deck); @@ -87,37 +81,27 @@ 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.teyaku.calculated = false; + g->right.teyaku.calculated = false; + g->left.teyaku.calculated = false; - g->player.hand.count = 0; g->player.hand.position = (Vector2) { 300, 600 }; g->player.hand.display_type = HAND_DISPLAY_ROW; - g->right.hand.count = 0; g->right.hand.position = (Vector2) { 750, 125 }; g->right.hand.display_type = HAND_DISPLAY_ROW; - g->left.hand.count = 0; g->left.hand.position = (Vector2) { 50, 125 }; g->left.hand.display_type = HAND_DISPLAY_ROW; - g->field.count = 0; g->field.position = (Vector2) { 400, 300 }; g->field.display_type = HAND_DISPLAY_FIELD; - g->player.scored.count = 0; g->player.scored.position = (Vector2) { 300, 750 }; g->player.scored.display_type = HAND_DISPLAY_SCORED; - g->right.scored.count = 0; g->right.scored.position = (Vector2) { 750, 25 }; g->right.scored.display_type = HAND_DISPLAY_SCORED; - g->left.scored.count = 0; g->left.scored.position = (Vector2) { 50, 25 }; g->left.scored.display_type = HAND_DISPLAY_SCORED; strcpy(teyaku_calculation, ""); - Image cards_image = LoadImage("img/cards.png"); - g->cards_texture = LoadTextureFromImage(cards_image); - UnloadImage(cards_image); g->state = GAME_STATE_INITIALIZING; } @@ -228,6 +212,35 @@ void run_frame_ai_playing(Game *g) { } void run_frame_initializing(Game *g) { + // TODO: choose the dealer in a more effective manner + g->turn_number = -1; + + g->player.hand.count = 0; + g->right.hand.count = 0; + g->left.hand.count = 0; + g->field.count = 0; + g->player.scored.count = 0; + g->right.scored.count = 0; + g->left.scored.count = 0; + g->player.dekiyaku_score = 0; + g->left.dekiyaku_score = 0; + g->right.dekiyaku_score = 0; + + g->player.dekiyaku_action = DEKIYAKU_ACTION_NONE; + g->right.dekiyaku_action = DEKIYAKU_ACTION_NONE; + g->left.dekiyaku_action = DEKIYAKU_ACTION_NONE; + + g->current_play_from_hand = NULL; + g->current_play_target = NULL; + + for (int i = 0; i < 48; i++) { + Card *c = &g->cards[i]; + c->visible = false; + add_to_hand(&g->deck, c); + } + + shuffle_hand(&g->deck); + 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); @@ -439,7 +452,7 @@ void run_frame_calculating_scores(Game *g) { } void run_frame_calculating_dekiyaku_score(Game *g) { - printf("Somebody won with dekiyaku. Cool.\n"); + printf("Somebody won with dekiyaku. Cool.\n"); fflush(stdout); g->state = GAME_STATE_INITIALIZING; } @@ -516,6 +529,7 @@ void draw_frame(Game *g) { } if (g->field_multiplier) DrawText(g->field_multiplier->name, 60, 385, 40, BLACK); + if (g->player.teyaku.calculated) { char s[200]; teyaku_to_string(&g->player.teyaku, s);