diff --git a/card.h b/card.h index 3c8beb0..d5198b9 100644 --- a/card.h +++ b/card.h @@ -12,6 +12,12 @@ typedef struct Hand Hand; #define CARD_HEIGHT 120 #define CARD_BORDER 5 +#define CRANE_INDEX 0 +#define CURTAIN_INDEX 8 +#define MOON_INDEX 28 +#define RAINY_MAN_INDEX 40 +#define PHOENIX_INDEX 44 + typedef enum CardType { CHAFF, RIBBON, diff --git a/field_multiplier.c b/field_multiplier.c new file mode 100644 index 0000000..fca83f8 --- /dev/null +++ b/field_multiplier.c @@ -0,0 +1,17 @@ +#include + +#include "field_multiplier.h" +#include "card.h" + +const FieldMultiplier *calculate_field_multiplier(Hand *h) { + bool large = false; + for (int i = 0; i < h->count; i++) { + Card *c = h->cards[i]; + if (c->index == CRANE_INDEX || c->index == CURTAIN_INDEX || c->index == MOON_INDEX) + large = true; + else if (c->index == RAINY_MAN_INDEX || c->index == PHOENIX_INDEX) + return &grand_field; + } + + return large ? &large_field : &small_field; +} diff --git a/field_multiplier.h b/field_multiplier.h new file mode 100644 index 0000000..8b3e1f3 --- /dev/null +++ b/field_multiplier.h @@ -0,0 +1,19 @@ +#ifndef _HF_FIELD_MULTIPLIER_ +#define _HF_FIELD_MULTIPLIER_ + +typedef struct FieldMultiplier FieldMultiplier; + +#include "card.h" + +struct FieldMultiplier { + char *name; + int value; +}; + +static const FieldMultiplier small_field = { "Small Field", 1 }; +static const FieldMultiplier large_field = { "Large Field", 2 }; +static const FieldMultiplier grand_field = { "Grand Field", 4 }; + +const FieldMultiplier *calculate_field_multiplier(Hand *h); + +#endif diff --git a/game.c b/game.c index f0be7a3..02418ac 100644 --- a/game.c +++ b/game.c @@ -5,15 +5,19 @@ #include "card.h" #include "teyaku.h" #include "dekiyaku.h" +#include "field_multiplier.h" Vector2 mouse_pos; char teyaku_calculation[400]; -char dekiyaku_calculation[400]; void initialize_game(Game *g) { g->deck.count = 0; 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; for (int i = 0; i < 48; i++) { CardType t = CHAFF; RibbonType rt = RIBBON_NONE; @@ -60,14 +64,15 @@ void initialize_game(Game *g) { shuffle_hand(&g->deck); g->player_hand.count = 0; - g->player_hand.position = (Vector2) { 20, 450 }; + g->player_hand.position = (Vector2) { 20, 475 }; g->right_hand.count = 0; g->right_hand.position = (Vector2) { 20, 100 }; g->left_hand.count = 0; - g->left_hand.position = (Vector2) { 20, 250 }; + g->left_hand.position = (Vector2) { 20, 225 }; + g->field.count = 0; + g->field.position = (Vector2) { 20, 350 }; strcpy(teyaku_calculation, ""); - strcpy(dekiyaku_calculation, ""); Image cards_image = LoadImage("img/cards.png"); g->cards_texture = LoadTextureFromImage(cards_image); @@ -107,9 +112,6 @@ void run_calculation(Game *g) { strcpy(teyaku_calculation, ""); } - Dekiyaku d; - calculate_dekiyaku(h, &d); - dekiyaku_to_string(&d, dekiyaku_calculation); stale_calculation = false; } } @@ -121,17 +123,31 @@ void run_frame_dealing(Game *g) { deal(&g->deck, &g->right_hand, 4, false); } else if (g->left_hand.count < 4) { deal(&g->deck, &g->left_hand, 4, false); + } else if (g->field.count < 3) { + deal(&g->deck, &g->field, 3, true); } else if (g->player_hand.count < 7) { deal(&g->deck, &g->player_hand, 3, true); } else if (g->right_hand.count < 7) { deal(&g->deck, &g->right_hand, 3, false); } else if (g->left_hand.count < 7) { deal(&g->deck, &g->left_hand, 3, false); + } else if (g->field.count < 6) { + deal(&g->deck, &g->field, 3, true); } else { - g->state = GAME_STATE_INITIALIZING; + g->state = GAME_STATE_CALCULATING_FIELD_MULTIPLIER; } } +void run_frame_calculating_field_multiplier(Game *g) { + g->field_multiplier = calculate_field_multiplier(&g->field); + g->state = GAME_STATE_CALCULATING_TEYAKU; +} + +void run_frame_calculating_teyaku(Game *g) { + calculate_teyaku(g->player_hand, &g->player_teyaku); + g->state = GAME_STATE_INITIALIZING; +} + void run_frame(Game *g) { float delta = GetFrameTime(); bool done_moving = true; @@ -149,6 +165,12 @@ void run_frame(Game *g) { case GAME_STATE_DEALING: run_frame_dealing(g); break; + case GAME_STATE_CALCULATING_FIELD_MULTIPLIER: + run_frame_calculating_field_multiplier(g); + break; + case GAME_STATE_CALCULATING_TEYAKU: + run_frame_calculating_teyaku(g); + break; } run_calculation(g); } @@ -160,8 +182,12 @@ void draw_frame(Game *g) { draw_card(&g->cards[i], &g->cards_texture); } - DrawText(teyaku_calculation, 10, 550, 25, BLACK); - DrawText(dekiyaku_calculation, 10, 500, 25, BLACK); + if (g->field_multiplier) DrawText(g->field_multiplier->name, 600, 385, 40, BLACK); + if (g->player_teyaku.calculated) { + char s[200]; + teyaku_to_string(&g->player_teyaku, s); + DrawText(s, 5, 25, 30, BLACK); + } EndDrawing(); } diff --git a/game.h b/game.h index c04ceb3..c406708 100644 --- a/game.h +++ b/game.h @@ -6,10 +6,14 @@ typedef struct Game Game; #include "card.h" +#include "field_multiplier.h" +#include "teyaku.h" typedef enum GameState { GAME_STATE_INITIALIZING, - GAME_STATE_DEALING + GAME_STATE_DEALING, + GAME_STATE_CALCULATING_FIELD_MULTIPLIER, + GAME_STATE_CALCULATING_TEYAKU, } GameState; struct Game { @@ -17,7 +21,9 @@ struct Game { bool should_close; Card cards[48]; Texture2D cards_texture; - Hand player_hand, left_hand, right_hand, deck; + Hand player_hand, left_hand, right_hand, deck, field; + FieldMultiplier *field_multiplier; + Teyaku player_teyaku, left_teyaku, right_teyaku; }; void initialize_game(Game *g); diff --git a/teyaku.c b/teyaku.c index 8984b66..6a3373a 100644 --- a/teyaku.c +++ b/teyaku.c @@ -86,6 +86,7 @@ char *chaff_teyaku_english(ChaffTeyaku ct) { void calculate_teyaku(const Hand h, Teyaku *t) { t->chaff = calculate_chaff_teyaku(h); t->set = calculate_set_teyaku(h); + t->calculated = true; } void teyaku_to_string(Teyaku *t, char *str) { diff --git a/teyaku.h b/teyaku.h index 6e99abc..51d210e 100644 --- a/teyaku.h +++ b/teyaku.h @@ -1,6 +1,8 @@ #ifndef _HF_TEYAKU_ #define _HF_TEYAKU_ +#include + #include "card.h" typedef enum SetTeyaku { @@ -29,6 +31,7 @@ typedef enum ChaffTeyaku { typedef struct Teyaku { ChaffTeyaku chaff; SetTeyaku set; + bool calculated; } Teyaku; void calculate_teyaku(const Hand h, Teyaku *t);