diff --git a/src/arguments.h b/src/arguments.h index bc46ae5..163e23f 100644 --- a/src/arguments.h +++ b/src/arguments.h @@ -24,9 +24,9 @@ */ feature proc_args(int argc, char **argv, - std::unique_ptr &curse, - std::unique_ptr &in, - std::unique_ptr &out, - std::unique_ptr &log); + std::unique_ptr &curse, + std::unique_ptr &in, + std::unique_ptr &out, + std::unique_ptr &log); #endif diff --git a/src/arguments.h.orig b/src/arguments.h.orig deleted file mode 100644 index 7b72410..0000000 --- a/src/arguments.h.orig +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef __ARGUMENTS_H__ -#define __ARGUMENTS_H__ -#include "log.h" -#include "cursor.h" -#include "display.h" -#include "input.h" - -#include "constants.h" - -feature proc_args(int argc, char ** argv, cursor &curse, input &in, logger& log); - -#endif diff --git a/src/characters.cc.orig b/src/characters.cc.orig deleted file mode 100644 index 358531f..0000000 --- a/src/characters.cc.orig +++ /dev/null @@ -1,176 +0,0 @@ -#include "characters.h" - -#include - -character::character(const enum race &nrace): - race{nrace}, HP{STARTING_HP[race]}, - ATK{STARTING_ATK[race]}, DEF{STARTING_DEF[race]} {} - -character::~character() {} - -enum race character::get_race() const { - return race; -} - -position character::get_position() const { - return pos; -} - -int character::get_HP() const { - return HP; -} - -int character::get_ATK() const { - return ATK; -} - -int character::get_DEF() const { - return DEF; -} - -int character::get_gold() const { - return gold; -} - -float character::get_hitrate() const { - return base_hitrate; -} - -bool character::is_hostile() const { - return hostile; -} - -void character::set_position(const position &npos) { - pos = npos; -} - -void character::set_HP(const int nHP) { - HP = nHP; -} - -void character::set_ATK(const int nATK) { - ATK = nATK; -} - -void character::set_DEF(const int nDEF) { - DEF = nDEF; -} - -void character::set_gold(const int ngold) { - gold = ngold; -} - -void character::set_hitrate(const float nhitrate) { - base_hitrate = nhitrate; -} - -void character::set_hostile(const bool is_hostile) { - hostile = is_hostile; -} - -void character::apply_buff(const stat_name statn, const int amount) { - // TODO: add checks for bounds - switch (statn) { - case stat_name::HP: - HP += amount; - break; - - case stat_name::ATK: - ATK += amount; - break; - - case stat_name::DEF: - DEF += amount; - break; - - case stat_name::hostile: { - if (amount > 0) - hostile = true; - else - hostile = false; - - break; - } - } -} - -character_list::character_list(): - layer{layer_num::characters} {} - -void character_list::print() const { - // TODO: implement it using ncurses -} - -void character_list::print(display &display) const { - for (auto &ch : characters) - display.print_position(ch->get_position(), - CHARACTER_REP[ch->get_race()]); -} - -std::vector>::const_iterator character_list::begin() -const { - return characters.begin(); -} - -std::vector>::const_iterator character_list::end() -const { - return characters.end(); -} - -direction_list character::moveable(const position_list &available_positions) -const { - direction_list result; - - for (int i = 0; i < DIRECTION_CNT; ++i) - if (find(available_positions, pos + MOVE[i]) - != available_positions.size()) - result.push_back((direction)i); - - return result; -} - -result character::apply(direction &dir, const potion_list &potions) { - // TODO: implement this after implementing potions - return result::fine; -} - -position_list remove_from_list(const position_list &sorted_positions, - position_list excluded) { - std::sort(excluded.begin(), excluded.end()); - - position_list result{sorted_positions.size() - excluded.size()}; - - auto exc = excluded.begin(); - - for (auto src : sorted_positions) { - if (exc != excluded.end() && src == *exc) - ++exc; - else - result.push_back(src); - } - - return result; -} - -// IMPORTANT: remember to check if player is on the stairs -result character::move(const direction dir, - const position_list &available_positions) { - if (find(available_positions, pos + MOVE[dir]) - != available_positions.size()) { - pos += MOVE[dir]; - return result::moved; - } - - return result::fine; -} - -result character::move_or_attack(const direction dir, - const position_list &available_positions, - const character_list &chlist) { - auto res = this->move(dir,available_positions); - - if(res != result::fine) - return res; - - return this->attack(dir,chlist); -} diff --git a/src/console_input.cc b/src/console_input.cc index 568b61b..69cafc6 100644 --- a/src/console_input.cc +++ b/src/console_input.cc @@ -12,10 +12,10 @@ game_command console_input::get_command() { if (cmd == "q") return game_command_terminate; - else if (cmd == "f") - return the_world; - else if (cmd == "r") - return game_restart; + else if (cmd == "f") + return the_world; + else if (cmd == "r") + return game_restart; else if (cmd == "u") return (game_command)((tmp = get_direction(cmd)) == game_command_panic diff --git a/src/constants.h b/src/constants.h index c13bcef..e21836c 100644 --- a/src/constants.h +++ b/src/constants.h @@ -24,7 +24,7 @@ enum game_command {game_command_terminate = 0, attack_northeast, attack_northwest, attack_southeast, attack_southwest, up_stairs, down_stairs, - the_world, game_restart, + the_world, game_restart, game_command_pass, game_command_panic }; diff --git a/src/constants.h.orig b/src/constants.h.orig deleted file mode 100644 index 0c22ffd..0000000 --- a/src/constants.h.orig +++ /dev/null @@ -1,71 +0,0 @@ -// TODO: Consider moving the contents of this header to their relevant -// headers - -#ifndef __CONSTANTS_H__ -#define __CONSTANTS_H__ -#include -#include "position.h" - -// IMPORTANT: added END to the end of all valued enums so that you can -// iterate over them - -enum error {none}; - -// TODO: update result to include subject -enum result {fine, died, go_down, hit, moved}; - -enum game_status{terminated, main_menu, in_game, options}; - -enum stat_name {HP, ATK, DEF, hostile}; - -const int LAYER_CNT = 4; // TODO: update as you go -enum layer_num {map = 0, objects, characters, shop}; - -const int RACE_CNT = 2; // TODO: update as you go - -enum race {unknown = 0, rshade /* TODO: fill out the other races (including enemies) */}; - -// TODO: fill out the other races (including enemies) -const int MAX_HP[RACE_CNT] = {0, 125}; -const int STARTING_HP[RACE_CNT] = {0, 125}; -const int STARTING_ATK[RACE_CNT] = {0, 25}; -const int STARTING_DEF[RACE_CNT] = {0, 25}; -const char CHARACTER_REP[RACE_CNT] = {'@', 'S'}; - -const int DIRECTION_CNT = 8; -// IMPORTANT: east is positive for x and SOUTH is positive for y -// initializes all directions to an int -enum direction {east = 0, west, north, south, northeast, - northwest, southeast, southest - }; - -const position MOVE[DIRECTION_CNT] = { - {1, 0}, {-1, 0}, {0, -1}, {0, 1}, - {1, -1}, {-1, -1}, {1, 1}, {-1, 1} -}; - -const int MAP_HEIGHT = 25; -const int MAP_WIDTH = 79; -const int DISPLAY_HEIGHT = 30; -const int DISPLAY_WIDTH = 79; - -// TODO: list all extra features -// using constants to keep track of features -// method: features: FEATURE_XXX | FEATURE_YYY -// That is: use bit manipulation -// check if feature is enabled: -// features & FEATURE_XXX -typedef unsigned int feature; // can extend to unsigned long (long) if needed -const feature FEATURE_NCURSES = 1 << 0; -const feature FEATURE_RAND_MAP = 1 << 1; -const feature FEATURE_ENEMIES_CHASE = 1 << 2; -const feature FEATURE_INVENTORY = 1 << 3; -const feature FEATURE_THROW = 1 << 4; -const feature FEATURE_REVISIT = 1 << 5; -const feature FEATURE_LOG = 1 << 6; -const feature FEATURE_SAVE = 1 << 7; - -typedef std::vector position_list; -typedef std::vector direction_list; - -#endif diff --git a/src/curses_input.cc b/src/curses_input.cc index 3f82d7e..3e22da8 100644 --- a/src/curses_input.cc +++ b/src/curses_input.cc @@ -37,12 +37,15 @@ game_command curses_input::get_command() { case '>': return game_command::down_stairs; - case 'q': - return game_command_terminate; - case 'f': - return game_command::the_world; - case 'r': - return game_restart; + + case 'q': + return game_command_terminate; + + case 'f': + return game_command::the_world; + + case 'r': + return game_restart; default: return game_command_pass; diff --git a/src/cursor.cc b/src/cursor.cc index 4362293..d50f31a 100644 --- a/src/cursor.cc +++ b/src/cursor.cc @@ -17,14 +17,16 @@ void cursor::show() const { refresh(); } -void cursor::print_char(const position &pos, const char ch, const int attrs) const { - attrset(attrs); - mvaddch(pos.y,pos.x,ch); +void cursor::print_char(const position &pos, const char ch, + const int attrs) const { + attrset(attrs); + mvaddch(pos.y, pos.x, ch); } -void cursor::print_str(const position &pos, const std::string str, const int attrs) const { - attrset(attrs); - mvaddstr(pos.y, pos.x, str.c_str()); +void cursor::print_str(const position &pos, const std::string str, + const int attrs) const { + attrset(attrs); + mvaddstr(pos.y, pos.x, str.c_str()); } bool check_terminal_size() { diff --git a/src/cursor.h b/src/cursor.h index f90bd0f..35b185d 100644 --- a/src/cursor.h +++ b/src/cursor.h @@ -47,7 +47,8 @@ public: void print_char(const position &pos, const char ch, const int attrs) const; - void print_str(const position &head, const std::string str, const int attrs) const; + void print_str(const position &head, const std::string str, + const int attrs) const; }; // IMPORTANT: this will fail when terminal size changes diff --git a/src/display.h.orig b/src/display.h.orig deleted file mode 100644 index 2f5fce3..0000000 --- a/src/display.h.orig +++ /dev/null @@ -1,35 +0,0 @@ -/* - * CS 246 Final Project - * File: display.h - * Purpose: handles map functionality - */ - -#ifndef __DISPLAY_H__ -#define __DISPLAY_H__ -#include -#include -#include -#include "position.h" -#include "constants.h" -#include "cursor.h" - -class display final { -private: - std::vector contents; - cursor &curse; -public: - display(); - display(cursor&new_curse,int argc, char **argv); - - void clear(); - // use this instead of overloading for clarity - void print(std::ostream &out) const; - void print_line(const std::string &line, const int linenum); - - void render() const ; - - // will override any character that was there - void print_position(const position &pos, const char ch); -}; - -#endif diff --git a/src/file_input.cc b/src/file_input.cc index f4e4670..745df64 100644 --- a/src/file_input.cc +++ b/src/file_input.cc @@ -12,10 +12,10 @@ game_command file_input::get_command() { if (cmd == "q") return game_command_terminate; - else if (cmd == "f") - return the_world; - else if (cmd == "r") - return game_restart; + else if (cmd == "f") + return the_world; + else if (cmd == "r") + return game_restart; else if (cmd == "u") return (game_command)((tmp = get_direction(cmd)) == game_command_panic diff --git a/src/game.h b/src/game.h index a486547..36d155e 100644 --- a/src/game.h +++ b/src/game.h @@ -12,17 +12,17 @@ class game final { private: - std::unique_ptr ∈ - std::unique_ptr &out; - std::unique_ptr &log; + std::unique_ptr ∈ + std::unique_ptr &out; + std::unique_ptr &log; feature features; std::unique_ptr rng; std::unique_ptr player; public: game(const feature enabled_features, - std::unique_ptr &new_in, - std::unique_ptr &new_out, - std::unique_ptr &new_log); + std::unique_ptr &new_in, + std::unique_ptr &new_out, + std::unique_ptr &new_log); game_status run(); private: int getcmd() const; diff --git a/src/game.h.orig b/src/game.h.orig deleted file mode 100644 index a227c34..0000000 --- a/src/game.h.orig +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef __GAME_H__ -#define __GAME_H__ -#include -#include -#include "constants.h" -#include "display.h" -#include "cursor.h" -#include "rng.h" -#include "characters.h" -#include "map.h" -#include "log.h" - -class game final { -private: - display &out; - cursor &curse; - feature features; - std::unique_ptr rng; - std::unique_ptr player; - std::vector levels; -public: - game(cursor&new_curse,display &new_display, int argc, char **argv); - game_status run(); -private: - int getcmd() const; -}; - -#endif diff --git a/src/main.cc b/src/main.cc index b9af1e6..e6eb13e 100644 --- a/src/main.cc +++ b/src/main.cc @@ -7,16 +7,16 @@ // The way things are designed to work: // to be filled... -int main(int argc, char **argv) { - std::unique_ptr curse; - std::unique_ptr in; - std::unique_ptr out; - std::unique_ptr log; +int main(int argc, char **argv) { + std::unique_ptr curse; + std::unique_ptr in; + std::unique_ptr out; + std::unique_ptr log; - feature enabled_features = proc_args(argc, argv, curse, in, out, log); + feature enabled_features = proc_args(argc, argv, curse, in, out, log); - if(enabled_features & FEATURE_PANIC) - std::cerr<<"Wrong arguments you dumbass :)"< - -typedef struct position { - int x; - int y; - - position(); - position(int nx, int ny); - - position operator+(const position &other) const; - position &operator=(const position &other); - position &operator+=(const position &other); - bool operator==(const position &other) const; - bool operator!=(const position &other) const; - bool operator<(const position &other) const; -} position; - -std::size_t find(const std::vector &sorted_list, - const position &target); - -#endif