diff --git a/src/cursor.cc b/src/cursor.cc index fcf9bdf..c3d04f8 100644 --- a/src/cursor.cc +++ b/src/cursor.cc @@ -2,53 +2,53 @@ #include "constants.h" cursor::cursor() { - initscr(); + initscr(); - if (has_colors()) { - start_color(); - init_pair(COLOR_RED, COLOR_RED, COLOR_BLACK); - init_pair(COLOR_GREEN, COLOR_GREEN, COLOR_BLACK); - init_pair(COLOR_YELLOW, COLOR_YELLOW, COLOR_BLACK); - init_pair(COLOR_BLUE, COLOR_BLUE, COLOR_BLACK); - init_pair(COLOR_MAGENTA, COLOR_MAGENTA, COLOR_BLACK); - init_pair(COLOR_CYAN, COLOR_CYAN, COLOR_BLACK); - init_pair(COLOR_WHITE, COLOR_WHITE, COLOR_BLACK); - init_pair(COLOR_BLACK_ON_WHITE, COLOR_BLACK, COLOR_WHITE); - } + if (has_colors()) { + start_color(); + init_pair(COLOR_RED, COLOR_RED, COLOR_BLACK); + init_pair(COLOR_GREEN, COLOR_GREEN, COLOR_BLACK); + init_pair(COLOR_YELLOW, COLOR_YELLOW, COLOR_BLACK); + init_pair(COLOR_BLUE, COLOR_BLUE, COLOR_BLACK); + init_pair(COLOR_MAGENTA, COLOR_MAGENTA, COLOR_BLACK); + init_pair(COLOR_CYAN, COLOR_CYAN, COLOR_BLACK); + init_pair(COLOR_WHITE, COLOR_WHITE, COLOR_BLACK); + init_pair(COLOR_BLACK_ON_WHITE, COLOR_BLACK, COLOR_WHITE); + } } cursor::~cursor() { - endwin(); + endwin(); } int cursor::getcmd() const { - return getch(); + return getch(); } void cursor::show() const { - refresh(); + refresh(); } void cursor::clear() const { - ::clear(); + ::clear(); } void cursor::print_char(const position &pos, const char ch, const int attrs) const { - attrset(attrs); - mvaddch(pos.y, pos.x, ch); + 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()); + attrset(attrs); + mvaddstr(pos.y, pos.x, str.c_str()); } bool check_terminal_size() { - int max_x; - int max_y; - getmaxyx(stdscr, max_y, max_x); + int max_x; + int max_y; + getmaxyx(stdscr, max_y, max_x); - return max_x >= DISPLAY_WIDTH && max_y >= DISPLAY_HEIGHT; + return max_x >= DISPLAY_WIDTH && max_y >= DISPLAY_HEIGHT; } diff --git a/src/cursor.h b/src/cursor.h index 52fde78..c0e064a 100644 --- a/src/cursor.h +++ b/src/cursor.h @@ -37,20 +37,20 @@ class cursor final { private: public: - cursor(); + cursor(); - ~cursor(); + ~cursor(); - int getcmd() const; + int getcmd() const; - void show() const; + void show() const; - void clear() const ; + void clear() const ; - void print_char(const position &pos, const char ch, const int attrs) const; + 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/position.cc b/src/position.cc index 75eb9e6..baf3aa5 100644 --- a/src/position.cc +++ b/src/position.cc @@ -5,43 +5,43 @@ position::position(): x{0}, y{0} {} position::position(int nx, int ny): x{nx}, y{ny} {} position position::operator+(const position &other) const { - position result{x + other.x, y + other.y}; - return result; + position result{x + other.x, y + other.y}; + return result; } position &position::operator=(const position &other) { - x = other.x; - y = other.y; - return *this; + x = other.x; + y = other.y; + return *this; } position &position::operator+=(const position &other) { - return *this = *this + other; + return *this = *this + other; } bool position::operator==(const position &other) const { - return x == other.x && y == other.y; + return x == other.x && y == other.y; } bool position::operator!=(const position &other) const { - return x != other.x || y != other.y; + return x != other.x || y != other.y; } bool position::operator<(const position &other) const { - return y < other.y || x < other.x; + return y < other.y || x < other.x; } #include size_t find(const std::vector &sorted_list, const position &target) { - // TODO: implement binary searching + // TODO: implement binary searching - for (size_t i = 0; i < sorted_list.size(); ++i) - if (sorted_list[i] == target) - return i; + for (size_t i = 0; i < sorted_list.size(); ++i) + if (sorted_list[i] == target) + return i; - return sorted_list.size(); + return sorted_list.size(); } #include diff --git a/src/rng.h b/src/rng.h index 575311e..0abd2c2 100644 --- a/src/rng.h +++ b/src/rng.h @@ -11,20 +11,20 @@ // IMPORTANT: pass all RNG objects as references class RNG final { private: - const unsigned int init_seed; - int curr_rand_num; + const unsigned int init_seed; + int curr_rand_num; public: - RNG(); // use time(0) as the seed - RNG(const unsigned int seed); // use a seed + RNG(); // use time(0) as the seed + RNG(const unsigned int seed); // use a seed - int rand_num(); // returns a random number between 0 and RAND_MAX + int rand_num(); // returns a random number between 0 and RAND_MAX - // IMPORTANT: all upper bounds are not included, all lower bounds are - int rand_between(const int lower_bound, const int upper_bound); - // returns a random number between 0 and upper_bound - int rand_under(const int upper_bound); - unsigned int get_init_seed() const; - int get_curr_rand_num() const; + // IMPORTANT: all upper bounds are not included, all lower bounds are + int rand_between(const int lower_bound, const int upper_bound); + // returns a random number between 0 and upper_bound + int rand_under(const int upper_bound); + unsigned int get_init_seed() const; + int get_curr_rand_num() const; bool trial(const fraction &psuccess);