32game_state_t current_state;
60int loading_game(
int game_state_id, player_pos_setter_t setter);
63 game_in_progress =
false;
65 current_state = MAIN_MENU;
75 switch (current_state) {
82 current_state = MAP_MODE;
117 case MENU_START_GAME:
120 game_in_progress =
true;
122 current_state = GENERATE_MAP;
126 current_state = MAP_MODE;
128 case MENU_SAVE_GAME: {
131 if (save_name == NULL) {
132 save_name =
"Unnamed Save";
140 current_state = MAP_MODE;
143 case MENU_LOAD_GAME: {
146 switch (load_status) {
148 log_msg(INFO,
"Game",
"Game loaded successfully");
150 game_in_progress =
true;
152 current_state = MAP_MODE;
155 log_msg(ERROR,
"Game",
"Failed to reset player character - generating new map");
157 current_state = GENERATE_MAP;
160 log_msg(ERROR,
"Game",
"Failed to load game state - generating new map");
162 current_state = GENERATE_MAP;
165 log_msg(ERROR,
"Game",
"Failed to load player character - generating new map");
167 current_state = GENERATE_MAP;
170 log_msg(ERROR,
"Game",
"Unknown error loading game state");
172 current_state = GENERATE_MAP;
177 case MENU_CHANGE_LANGUAGE:
178 current_state = MAIN_MENU;
181 current_state = EXIT;
191 current_state = EXIT;
196 current_state = GENERATE_MAP;
199 current_state = COMBAT_MODE;
202 current_state = INVENTORY_MODE;
206 current_state = MAIN_MENU;
210 current_state = STATS_MODE;
213 log_msg(ERROR,
"game",
"Unknown return value from map_mode_update");
222 case CONTINUE_COMBAT:
226 current_state = LOOT_MODE;
230 current_state = EXIT;
233 current_state = EXIT;
240 case CONTINUE_INVENTORY:
244 current_state = MAP_MODE;
251 case CONTINUE_INVENTORY:
254 current_state = MAP_MODE;
267 current_state = MAP_MODE;
272int loading_game(
const int game_state_id,
const player_pos_setter_t setter) {
274 if (
get_game_state_by_id(&db_connection, game_state_id, map, revealed_map, WIDTH, HEIGHT, setter) != 1)
return 2;
276 if (player == NULL)
return 3;
void reset_player_stats(character_t *player)
Resets the player stats to their base values.
Exposes functions for working working with the character.
void save_character(const db_connection_t *db_connection, const character_t character, const sqlite3_int64 game_state_id)
This function saves the character to the database.
void get_character_from_db(const db_connection_t *db_connection, character_t *character, const int game_state_id)
This function retrieves a character from the database.
Exposes functions for working with the character and database.
combat_result_t start_combat(character_t *player, character_t *monster)
Starts the loop for combat between the player and the monster.
Declares combat mode state machine, including menus and combat operations.
Defines common macros, types, and global variables for color schemes and utilities.
void db_close(db_connection_t *db_connection)
This function is for the closing of the database.
Exposes functions for working with the database.
void loot_mode_state()
Handles the loot mode state of the game.
void game_loop()
The main game loop of the application.
int loading_game(int game_state_id, player_pos_setter_t setter)
Load the a game from the database.
void run_game()
Starts the game loop.
void inventory_mode_state()
Handles the inventory mode state of the game.
void stats_mode_state()
Handles the stats mode state of the game.
void main_menu_state()
Handles the main menu state of the game.
void combat_mode_state()
The state machine for the combat mode.
void map_mode_state()
Handles the map mode state of the game.
Declares core game states, global database connection, and main game control functions.
int reset_goblin()
Resets the goblin character data by deallocating the current goblin instance and creating a new one.
int reset_player()
Resets the player character to its initial state, clearing all abilities, items, and stats.
int init_player(char *name)
Initializes the player character with default abilities and items.
Declares functions and globals for initializing, resetting, and freeing game data such as player,...
sqlite_int64 save_game_state(const db_connection_t *db_connection, const int *map, const int *revealed_map, const int width, const int height, const vector2d_t player, const char *save_name)
Save the game state.
int get_latest_save_id(const db_connection_t *db_connection)
int get_game_state_by_id(const db_connection_t *db_connection, const int game_state_id, int *map, int *revealed_map, const int width, const int height, const player_pos_setter_t setter)
Load the game state for a specific id from the database.
Declares functions to create, save, load, and manage game state data in the SQLite database.
inventory_result_t start_inventory(character_t *player, character_t *monster)
Starts the inventory mode.
Exposes functions for working with the inventory mode.
Exposes functions for the IO-Handler.
void log_msg(const log_level_t level, const char *module, const char *format,...)
Logs a formatted message with a specified log level and module.
Header file for logging functionality of the game.
menu_result_t show_main_menu(const bool game_in_progress)
Display and handle the main menu.
Exposes functions for the main menu.
Exposes common types and constants for the games map.
void generate_map()
Generate the map and populate it with keys, enemies, and the exit.
Exposes functions for generating the game map.
map_mode_result_t map_mode_update(character_t *player)
Updates the player position based on the player's input and redraws the maze.
vector2d_t get_player_pos()
Get the current player position.
void set_player_start_pos(const int player_x, const int player_y)
Sets the starting position of the player.
Defines and manages functions for map exploration, player movement, and map interactions in map mode.
void clear_screen(void)
Clear the screen.
Exposes functions for outputting to the console.
stats_result_t stats_mode(character_t *player)
Enter the stat mode for a given character.
Exposes functions and enums for the stats_mode.
This struct is used for the database connection in SQLite.