From 08c5c086690e2cc5ebe4eb1ab2193314c82c370b Mon Sep 17 00:00:00 2001 From: Bill Rossi Date: Thu, 6 Feb 2025 19:44:48 -0500 Subject: [PATCH] What the heck --- game.c | 76 ++++++++++++++++++++++++++++++++-------------------------- game.h | 2 ++ play.c | 26 ++++++++++++++++++++ play.h | 10 ++++++++ 4 files changed, 80 insertions(+), 34 deletions(-) create mode 100644 play.c create mode 100644 play.h diff --git a/game.c b/game.c index 3f5f408..f59f320 100644 --- a/game.c +++ b/game.c @@ -53,7 +53,7 @@ void initialize_game(Game *g) { case 41: t = ANIMAL; break; } - g->cards[i] = (Card) { i, t, rt, month, { 800, 100 }, false, false }; + g->cards[i] = (Card) { i, t, rt, month, { 800, 100 }, false }; g->cards[i].move.end_time = 0.; g->cards[i].move.position = &g->cards[i].position; g->cards[i].move.destination = (Vector2) { 800, 400 }; @@ -86,37 +86,22 @@ void initialize_game(Game *g) { bool stale_calculation = true; void handle_input(Game *g) { - if (IsMouseButtonPressed(0)) { - mouse_pos = GetMousePosition(); - for (int i = 0; i < 48; i++) { - if (point_within_card(&g->cards[i], mouse_pos)) { - g->cards[i].selected = !g->cards[i].selected; - stale_calculation = true; - break; + switch (g->state) { + case GAME_STATE_PLAYER_CHOOSING_FROM_HAND: + if (IsMouseButtonPressed(0)) { + 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]; + break; + } } } - } -} - -void run_calculation(Game *g) { - int num_selected = 0; - if (stale_calculation) { - Hand h; - h.count = 0; - for (int i = 0; i < 48; i++) { - num_selected += g->cards[i].selected; - if (g->cards[i].selected) h.cards[h.count++] = &g->cards[i]; - } - - if (num_selected == 7) { - Teyaku t; - calculate_teyaku(h, &t); - teyaku_to_string(&t, teyaku_calculation); - } else { - strcpy(teyaku_calculation, ""); - } - - stale_calculation = false; + break; + case GAME_STATE_PLAYER_CHOOSING_TARGET: + break; + default: + break; } } @@ -149,10 +134,18 @@ void run_frame_calculating_field_multiplier(Game *g) { void run_frame_calculating_teyaku(Game *g) { calculate_teyaku(g->player_hand, &g->player_teyaku); - g->state = GAME_STATE_INITIALIZING; + // g->selected_card = NULL; + g->state = GAME_STATE_PLAYER_CHOOSING_FROM_HAND; +} + +void run_frame_player_choosing_from_hand(Game *g) { +} +void run_frame_player_choosing_target(Game *g) { } void run_frame(Game *g) { + handle_input(g); + float delta = GetFrameTime(); bool done_moving = true; for (int i = 0; i < 48; i++) { @@ -161,8 +154,6 @@ void run_frame(Game *g) { } if (!done_moving) return; - handle_input(g); - switch (g->state) { case GAME_STATE_INITIALIZING: return; @@ -175,8 +166,13 @@ void run_frame(Game *g) { case GAME_STATE_CALCULATING_TEYAKU: run_frame_calculating_teyaku(g); break; + case GAME_STATE_PLAYER_CHOOSING_FROM_HAND: + run_frame_player_choosing_from_hand(g); + break; + case GAME_STATE_PLAYER_CHOOSING_TARGET: + run_frame_player_choosing_target(g); + break; } - run_calculation(g); } void draw_frame(Game *g) { @@ -192,6 +188,18 @@ void draw_frame(Game *g) { teyaku_to_string(&g->player_teyaku, s); DrawText(s, 5, 25, 30, BLACK); } + + switch (g->state) { + case GAME_STATE_PLAYER_CHOOSING_FROM_HAND: + DrawText("Choose a card to play", 60, 485, 40, BLACK); + break; + case GAME_STATE_PLAYER_CHOOSING_TARGET: + DrawText("Choose a target on the field", 60, 485, 40, BLACK); + break; + default: + break; + } + EndDrawing(); } diff --git a/game.h b/game.h index c406708..bbaf9e5 100644 --- a/game.h +++ b/game.h @@ -14,6 +14,8 @@ typedef enum GameState { GAME_STATE_DEALING, GAME_STATE_CALCULATING_FIELD_MULTIPLIER, GAME_STATE_CALCULATING_TEYAKU, + GAME_STATE_PLAYER_CHOOSING_FROM_HAND, + GAME_STATE_PLAYER_CHOOSING_TARGET, } GameState; struct Game { diff --git a/play.c b/play.c new file mode 100644 index 0000000..4d777eb --- /dev/null +++ b/play.c @@ -0,0 +1,26 @@ +#include +#include +#include "play.h" + +bool valid_play(Hand *field, Card *played, Card *target) { + if (target == NULL) { + bool matching_month_in_field = false; + for (int i = 0; i < field->count; i++) { + if (field->cards[i]->month == target->month) { + matching_month_in_field = true; + break; + } + } + return !matching_month_in_field; + } else { + bool target_in_field = false; + for (int i = 0; i < field->count; i++) { + if (field->cards[i]->index == target->index) { + target_in_field = true; + break; + } + } + if (!target_in_field) return false; + return played->month == target->month; + } +} diff --git a/play.h b/play.h new file mode 100644 index 0000000..81cfdf1 --- /dev/null +++ b/play.h @@ -0,0 +1,10 @@ +#ifndef _HF_PLAY_ +#define _HF_PLAY_ + +#include + +#include "card.h" + +bool valid_play(Hand *field, Card *played, Card *target); + +#endif