Calculate field multipler and teyaku
This commit is contained in:
parent
371feff5fe
commit
417544321c
6
card.h
6
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,
|
||||
|
17
field_multiplier.c
Normal file
17
field_multiplier.c
Normal file
@ -0,0 +1,17 @@
|
||||
#include <stdbool.h>
|
||||
|
||||
#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;
|
||||
}
|
19
field_multiplier.h
Normal file
19
field_multiplier.h
Normal file
@ -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
|
46
game.c
46
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();
|
||||
}
|
||||
|
||||
|
10
game.h
10
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);
|
||||
|
1
teyaku.c
1
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) {
|
||||
|
3
teyaku.h
3
teyaku.h
@ -1,6 +1,8 @@
|
||||
#ifndef _HF_TEYAKU_
|
||||
#define _HF_TEYAKU_
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#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);
|
||||
|
Loading…
Reference in New Issue
Block a user