DungeonCrawl
Loading...
Searching...
No Matches
stats_mode.c
Go to the documentation of this file.
1
5#include "stats_mode.h"
6
7#include "../combat/ability.h"
12int selected_index = 0;
13
14stats_result_t stats_mode(character_t* player) {
16 stats_result_t result = STATS_WINDOW;
17
18 // Draw stats window
19 render_stats_window(player);
20 const char* menu_options[4];
21
22 menu_options[0] = stats_mode_strings[STRENGTH_STR];
23 menu_options[1] = stats_mode_strings[INTELLIGENCE_STR];
24 menu_options[2] = stats_mode_strings[DEXTERITY_STR];
25 menu_options[3] = stats_mode_strings[CONSTITUTION_STR];
26
28 stats_mode_strings[STATS_MENU_TITLE],
29 menu_options,
30 4,
31 selected_index, "");
32 // Check for input
33 input_event_t input_event;
34 if (get_input_nonblocking(&input_event)) {
35 // Handle input using logical input types
36 switch (input_event.type) {
37 case INPUT_UP:
38 selected_index = (selected_index > 0) ? selected_index - 1 : MAX_STATS - 1;
39 break;
40 case INPUT_DOWN:
41 selected_index = (selected_index + 1) % MAX_STATS;
42 break;
43 case INPUT_CONFIRM:
44 if (player->skill_points > 0) {
45 switch (selected_index) {
46 case 0:
47 raise_skill(&player->base_stats, STRENGTH, player->skill_points);
48 break;
49 case 1:
50 raise_skill(&player->base_stats, INTELLIGENCE, player->skill_points);
51 break;
52 case 2:
53 raise_skill(&player->base_stats, DEXTERITY, player->skill_points);
54 break;
55 case 3:
56 raise_skill(&player->base_stats, CONSTITUTION, player->skill_points);
57 break;
58 default:;
59 }
60 player->skill_points--;
61 update_character_resources(&player->current_resources, &player->max_resources, &player->base_stats);
62 } else {
63 char word[MAX_STRING_LENGTH - 4];
64 snprintf(word, MAX_STRING_LENGTH - 4, "%s: 0", stats_mode_strings[AVAILABLE_SKILL_POINTS_STR]);
65 print_text_default(20, 17, word);
66 }
67 break;
68 case INPUT_CANCEL:
69 case INPUT_STATS:
70 result = STATS_EXIT;
71 break;
72 default:
73 break;
74 }
75 }
76
78 return result;
79}
Exposes functions for working with abilities.
void update_character_resources(resources_t *current_resources, resources_t *max_resources, stats_t *base_stats)
Updates the character's resources based on their stats.
Definition character.c:86
bool get_input_nonblocking(input_event_t *event)
Get the next input event (non-blocking)
Exposes functions for working with input.
void print_text_default(int y, int x, const char *text)
Print text at a specific position with default colors.
bool render_frame(void)
Render the current frame.
void clear_screen(void)
Clear the screen.
Exposes functions for outputting to the console.
void raise_skill(stats_t *stats, stat_type_t stat, int skillpoint)
Raises a specified skill by one point.
Definition stats.c:10
stats_result_t stats_mode(character_t *player)
Enter the stat mode for a given character.
Definition stats_mode.c:14
Exposes functions and enums for the stats_mode.
Exposes functions and enums for working with localization in the map mode.
void draw_stats_menu(const char *title, const char **options, int option_count, int selected_index, const char *footer)
Draw the stats menu.
void render_stats_window(const character_t *player)
Render the stats window.
Exposes functions for outputing to the screen in stats mode.
Structure for advanced input events with context data.
Definition input_types.h:43