diff --git a/game.c b/game.c index f59f320..6c110f3 100644 --- a/game.c +++ b/game.c @@ -92,13 +92,33 @@ void handle_input(Game *g) { mouse_pos = GetMousePosition(); for (int i = 0; i < g->player_hand.count; i++) { if (point_within_card(g->player_hand.cards[i], mouse_pos)) { - // g->selected_card = g->player_hand.cards[i]; + for (int j = 0; j < 48; j++) { + g->cards[j].selected = false; + } + g->player_hand.cards[i]->selected = true; break; } } } break; case GAME_STATE_PLAYER_CHOOSING_TARGET: + if (IsMouseButtonPressed(0)) { + mouse_pos = GetMousePosition(); + bool clicked_hand_card = false; + for (int i = 0; i < g->player_hand.count; i++) { + if (point_within_card(g->player_hand.cards[i], mouse_pos)) { + clicked_hand_card = true; + if (g->player_hand.cards[i]->selected) { + g->player_hand.cards[i]->selected = false; + } else { + for (int j = 0; j < g->player_hand.count; j++) { + g->player_hand.cards[j]->selected = false; + } + g->player_hand.cards[i]->selected = true; + } + } + } + } break; default: break; @@ -134,13 +154,33 @@ void run_frame_calculating_field_multiplier(Game *g) { void run_frame_calculating_teyaku(Game *g) { calculate_teyaku(g->player_hand, &g->player_teyaku); - // g->selected_card = NULL; + for (int i = 0; i < 48; i++) { + g->cards[i].selected = false; + } g->state = GAME_STATE_PLAYER_CHOOSING_FROM_HAND; } 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; + } + } } + void run_frame_player_choosing_target(Game *g) { + bool no_cards_selected = true; + for (int i = 0; i < g->player_hand.count; i++) { + if (g->player_hand.cards[i]->selected) { + no_cards_selected = false; + break; + } + } + + if (no_cards_selected) { + g->state = GAME_STATE_PLAYER_CHOOSING_FROM_HAND; + } } void run_frame(Game *g) {