did astyle on the source files

This commit is contained in:
2024-07-05 12:14:34 -04:00
parent 74de68cf0d
commit 7919c7dbfe
16 changed files with 46 additions and 423 deletions

View File

@ -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

View File

@ -1,176 +0,0 @@
#include "characters.h"
#include <algorithm>
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<std::unique_ptr<character>>::const_iterator character_list::begin()
const {
return characters.begin();
}
std::vector<std::unique_ptr<character>>::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);
}

View File

@ -1,71 +0,0 @@
// TODO: Consider moving the contents of this header to their relevant
// headers
#ifndef __CONSTANTS_H__
#define __CONSTANTS_H__
#include <vector>
#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> position_list;
typedef std::vector<direction> direction_list;
#endif

View File

@ -37,10 +37,13 @@ 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;

View File

@ -17,12 +17,14 @@ void cursor::show() const {
refresh();
}
void cursor::print_char(const position &pos, const char ch, const int attrs) const {
void cursor::print_char(const position &pos, const char ch,
const int attrs) const {
attrset(attrs);
mvaddch(pos.y,pos.x,ch);
mvaddch(pos.y, pos.x, ch);
}
void cursor::print_str(const position &pos, const std::string str, const int attrs) const {
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());
}

View File

@ -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

View File

@ -1,35 +0,0 @@
/*
* CS 246 Final Project
* File: display.h
* Purpose: handles map functionality
*/
#ifndef __DISPLAY_H__
#define __DISPLAY_H__
#include <iostream>
#include <string>
#include <vector>
#include "position.h"
#include "constants.h"
#include "cursor.h"
class display final {
private:
std::vector<std::string> 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

View File

@ -1,28 +0,0 @@
#ifndef __GAME_H__
#define __GAME_H__
#include <memory>
#include <vector>
#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> rng;
std::unique_ptr<character> player;
std::vector<level> levels;
public:
game(cursor&new_curse,display &new_display, int argc, char **argv);
game_status run();
private:
int getcmd() const;
};
#endif

View File

@ -15,8 +15,8 @@ int main(int argc, char **argv) {
feature enabled_features = proc_args(argc, argv, curse, in, out, log);
if(enabled_features & FEATURE_PANIC)
std::cerr<<"Wrong arguments you dumbass :)"<<std::endl;
if (enabled_features & FEATURE_PANIC)
std::cerr << "Wrong arguments you dumbass :)" << std::endl;
game game_proc(enabled_features, in, out, log);

View File

@ -1,32 +0,0 @@
#include "game.h"
#include "cursor.h"
#include "display.h"
#include "input.h"
#include "arguments.h"
// The way things are designed to work:
// 1. out initializes a new display (this is a virtual one)
// 2. out initializes output based on given args
// This is when curse is initialized (curse.init())
// 3. game_proc binds output to out and curses (if needed)
// Notes:
// 1. game sends all output to display and gets all input from input
// 2. display either renders to file (console) or curse
// 3.
int main(int argc, char **argv) {
logger log;
cursor curse;
input in(curse);
feature enabled_features = proc_args(argc,argv,curse,in,log);
display out(curse, enabled_features);
// binds display to the game
game game_proc(in, out, argc, argv);
while (game_proc.run() != game_status::terminated)
out.render();
return 0;
}

View File

@ -1,29 +0,0 @@
/*
* CS 246 Final Project
* File: map.h
* Purpose: handles map functionality
*/
#ifndef __POSITION_H__
#define __POSITION_H__
#include <vector>
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<position> &sorted_list,
const position &target);
#endif