From ec9d0e500719d694a9d67d991bfad6ad9a52316b Mon Sep 17 00:00:00 2001 From: Bill Rossi Date: Sat, 8 Feb 2025 08:15:43 -0500 Subject: [PATCH] Make plays!! --- card.c | 9 +++++++++ game.c | 36 +++++++++++++++++++++++++++++++++++- game.h | 5 ++++- 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/card.c b/card.c index 5a7fbf2..1dc2e02 100644 --- a/card.c +++ b/card.c @@ -44,6 +44,15 @@ void shuffle_hand(Hand *h) { } } +void remove_from_hand(Hand *h, Card *c) { + bool card_found = false; + for (int i = 0; i < h->count - 1; i++) { + if (h->cards[i] == c) card_found = true; + h->cards[i] = h->cards[i + 1]; + } + h->count--; +} + void add_to_hand(Hand *h, Card *c) { h->cards[h->count] = c; diff --git a/game.c b/game.c index 1737c17..517c218 100644 --- a/game.c +++ b/game.c @@ -76,6 +76,15 @@ void initialize_game(Game *g) { 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_ROW; + g->right_scored.count = 0; + g->right_scored.position = (Vector2) { 50, 25 }; + g->right_scored.display_type = HAND_DISPLAY_ROW; + g->left_scored.count = 0; + g->left_scored.position = (Vector2) { 750, 25 }; + g->left_scored.display_type = HAND_DISPLAY_ROW; strcpy(teyaku_calculation, ""); @@ -132,7 +141,10 @@ void handle_input(Game *g) { if (point_within_card(g->field.cards[i], mouse_pos)) { if (selected_card == NULL) printf("No card selected, whoops"); if (valid_play(&g->field, selected_card, g->field.cards[i])) { + g->current_play_from_hand = selected_card; + g->current_play_target = g->field.cards[i]; printf("Valid\n"); + break; } else { printf("Invalid\n"); } @@ -141,6 +153,8 @@ void handle_input(Game *g) { if (CheckCollisionPointRec(mouse_pos, next_card_position(&g->field))) { if (valid_play(&g->field, selected_card, NULL)) { + g->current_play_from_hand = selected_card; + g->current_play_target = NULL; printf("Valid\n"); } else { printf("Invalid\n"); @@ -192,9 +206,10 @@ void run_frame_player_choosing_from_hand(Game *g) { for (int i = 0; i < g->player_hand.count; i++) { if (g->player_hand.cards[i]->selected) { g->state = GAME_STATE_PLAYER_CHOOSING_TARGET; - break; + return; } } + } void run_frame_player_choosing_target(Game *g) { @@ -208,6 +223,25 @@ void run_frame_player_choosing_target(Game *g) { if (no_cards_selected) { g->state = GAME_STATE_PLAYER_CHOOSING_FROM_HAND; + return; + } + + if (g->current_play_from_hand) { + if (g->current_play_target) { + g->current_play_from_hand->selected = false; + remove_from_hand(&g->player_hand, g->current_play_from_hand); + add_to_hand(&g->player_scored, g->current_play_from_hand); + remove_from_hand(&g->field, g->current_play_target); + add_to_hand(&g->player_scored, g->current_play_target); + g->current_play_from_hand = NULL; + g->current_play_target = NULL; + } else { + g->current_play_from_hand->selected = false; + remove_from_hand(&g->player_hand, g->current_play_from_hand); + add_to_hand(&g->field, g->current_play_from_hand); + g->current_play_from_hand = NULL; + } + g->state = GAME_STATE_INITIALIZING; } } diff --git a/game.h b/game.h index bbaf9e5..bc309cd 100644 --- a/game.h +++ b/game.h @@ -23,9 +23,12 @@ struct Game { bool should_close; Card cards[48]; Texture2D cards_texture; - Hand player_hand, left_hand, right_hand, deck, field; + Hand player_hand, left_hand, right_hand; + Hand deck, field; + Hand player_scored, left_scored, right_scored; FieldMultiplier *field_multiplier; Teyaku player_teyaku, left_teyaku, right_teyaku; + Card *current_play_from_hand, *current_play_target; }; void initialize_game(Game *g);