work in progress

This commit is contained in:
2024-07-13 18:22:15 -04:00
parent 8da12f5360
commit 39d3447593
8 changed files with 105 additions and 3 deletions

View File

@ -140,6 +140,8 @@ feature proc_args(int argc, char **argv,
return FEATURE_PANIC_SEED; return FEATURE_PANIC_SEED;
rng = std::make_unique<RNG>(tmp); rng = std::make_unique<RNG>(tmp);
} else {
rng = std::make_unique<RNG>();
} }
return result; return result;

View File

@ -3,4 +3,6 @@
class CC3K; class CC3K;
// every time it runs, clear first
#endif #endif

View File

@ -9,7 +9,7 @@ const int INF = 0x3F3F3F3F;
enum error {none}; enum error {none};
// TODO: update result to include subject // TODO: update result to include subject
enum result {fine, died, go_down, go_up, hit, moved, miss}; enum result {fine, died, go_down, go_up, hit, moved, miss, terminate};
enum game_status {terminated, main_menu, in_game, options, enum game_status {terminated, main_menu, in_game, options,
dead, won, escaped, restart dead, won, escaped, restart
@ -63,7 +63,7 @@ const int DIRECTION_CNT = 8;
// IMPORTANT: east is positive for x and SOUTH is positive for y // IMPORTANT: east is positive for x and SOUTH is positive for y
// initializes all directions to an int // initializes all directions to an int
enum direction { north = 0, south, east, west, northeast, enum direction { north = 0, south, east, west, northeast,
northwest, southeast, southest northwest, southeast, southwest
}; };
const position MOVE[DIRECTION_CNT] = { const position MOVE[DIRECTION_CNT] = {

View File

@ -40,10 +40,89 @@ void game::new_level() {
rng, enabled_features)); rng, enabled_features));
} }
result game::player_moves(game_command cmd) {
switch (cmd) {
case game_command_terminate:
return result::terminate;
case move_east: {
if (enabled_features & FEATURE_NCURSES)
return player_move_or_attack(east);
return player->move(east, levels[curr_level]->get_available_around(
player->get_position()));
}
case move_west: {
if (enabled_features & FEATURE_NCURSES)
return player_move_or_attack(west);
return player->move(west, levels[curr_level]->get_available_around(
player->get_position()));
}
case move_north: {
if (enabled_features & FEATURE_NCURSES)
return player_move_or_attack(north);
return player->move(north, levels[curr_level]->get_available_around(
player->get_position()));
}
case move_south: {
if (enabled_features & FEATURE_NCURSES)
return player_move_or_attack(south);
return player->move(south, levels[curr_level]->get_available_around(
player->get_position()));
}
case move_northeast: {
if (enabled_features & FEATURE_NCURSES)
return player_move_or_attack(northeast);
return player->move(northeast,
levels[curr_level]->get_available_around(
player->get_position()));
}
case move_northwest: {
if (enabled_features & FEATURE_NCURSES)
return player_move_or_attack(northwest);
return player->move(northwest,
levels[curr_level]->get_available_around(
player->get_position()));
}
case move_southeast: {
if (enabled_features & FEATURE_NCURSES)
return player_move_or_attack(southeast);
return player->move(southeast,
levels[curr_level]->get_available_around(
player->get_position()));
}
case move_southwest: {
if (enabled_features & FEATURE_NCURSES)
return player_move_or_attack(southwest);
return player->move(southwest,
levels[curr_level]->get_available_around(
player->get_position()));
}
}
}
game_status game::run() { game_status game::run() {
player->start_turn();
auto res = player_moves(in->get_command()); auto res = player_moves(in->get_command());
switch (res) { switch (res) {
case result::terminate:
return terminated;
case result::died: case result::died:
return game_status::dead; return game_status::dead;
@ -70,7 +149,10 @@ game_status game::run() {
break; break;
} }
move_enemies();
if (player->get_HP() <= 0)
return game_status::dead;
return game_status::in_game; return game_status::in_game;
} }

View File

@ -44,6 +44,8 @@ private:
result player_moves(game_command cmd); result player_moves(game_command cmd);
void new_level(); void new_level();
void move_enemies(); void move_enemies();
result player_move_or_attack(const direction &dir);
}; };
#endif #endif

View File

@ -18,7 +18,7 @@ private:
static const int MAX_ROOM_WIDTH = 20; static const int MAX_ROOM_WIDTH = 20;
static const int MAX_ROOM_HEIGHT = 5; static const int MAX_ROOM_HEIGHT = 5;
// setup safezones // setup safezones
static const int ACTUAL_MAP_WIDTH = MAP_WIDTH - 5; static const int ACTUAL_MAP_WIDTH = MAP_WIDTH - 6;
static const int ACTUAL_MAP_HEIGHT = MAP_HEIGHT - 5; static const int ACTUAL_MAP_HEIGHT = MAP_HEIGHT - 5;
static const int MAP_PADDING = 3; static const int MAP_PADDING = 3;
static const int MIN_ROOM_SPACING = 3; static const int MIN_ROOM_SPACING = 3;

View File

@ -74,3 +74,13 @@ void remove_from_list(std::vector<position>
return; return;
} }
} }
#include "math.h"
float distance(const position &a, const position &b) {
return sqrt(distance_sqr(a, b));
}
int distance_sqr(const position &a, const position &b) {
return pow(a.x - b.x, 2) + pow(a.y - b.y, 2);
}

View File

@ -26,4 +26,8 @@ std::vector<position> remove_from_list(const std::vector<position>
std::vector<position> excluded); std::vector<position> excluded);
void remove_from_list(std::vector<position> &sorted_positions, void remove_from_list(std::vector<position> &sorted_positions,
position &excluded); position &excluded);
float distance(const position &a, const position &b);
int distance_sqr(const position &a, const position &b);
#endif #endif