#ifndef _HF_GAME_
#define _HF_GAME_

#include <stdbool.h>

typedef struct Game Game;

#include "card.h"
#include "field_multiplier.h"
#include "teyaku.h"
#include "dekiyaku.h"
#include "points.h"
#include "player.h"
#include "dialog.h"
#include "options.h"

typedef enum GameState {
  GAME_STATE_INITIALIZING,
  GAME_STATE_DEALING,
  GAME_STATE_CALCULATING_FIELD_MULTIPLIER,
  GAME_STATE_CALCULATING_TEYAKU,
  GAME_STATE_START_OF_TURN,
  GAME_STATE_CHECKING_FOR_CANCEL,
  GAME_STATE_CHOOSING_FROM_HAND,
  GAME_STATE_CHOOSING_TARGET,
  GAME_STATE_SHOWING_CARD_FROM_DECK,
  GAME_STATE_PLAYING_FROM_DECK,
  GAME_STATE_CHOOSING_TARGET_FROM_DECK,
  GAME_STATE_CHECKING_FOR_NEW_DEKIYAKU,
  GAME_STATE_SELECTING_DEKIYAKU_ACTION,
  GAME_STATE_CALCULATING_SCORES,
  GAME_STATE_CALCULATING_DEKIYAKU_SCORE,
  GAME_STATE_END_OF_ROUND,
  GAME_STATE_END_OF_GAME,
  GAME_STATE_NEW_GAME,
  GAME_STATE_TITLE_SCREEN,
  GAME_STATE_OPTIONS,
} GameState;

struct Game {
  GameState state;
  bool should_close;
  Card cards[48];
  Texture2D cards_texture_red, cards_texture_black;
  Hand deck, field;
  FieldMultiplier *field_multiplier;
  Card *current_play_from_hand, *current_play_target;
  Player player, right, left;
  int temp_points;
  int turn_number;
  Dialog *dialog;
  Player *dealer;
  int current_round;
  int kan_value;
  int number_of_rounds;
  bool black_card_backs;
  float deal_speed;
  Options *options;
};

void initialize_game(Game *g);
void run_until_closing(Game *g);
void transfer_points(Game *g, int *to, int *from, int amount);
void transfer_kan(Game *g, int *to, int *from, int amount);

#endif