1#include <Game/Board.hpp>
2#include <Game/Player.hpp>
3#include <Config/Globals.hpp>
4#include <Misc/Utils.hpp>
6int Board::small_width = 40;
7int Board::small_height = 10;
9int Board::medium_width = 55;
10int Board::medium_height = 14;
12int Board::large_width = 78;
13int Board::large_height = 21;
17 start_x(BOARD_DEFAULT_PLAYER_X),
18 start_y(BOARD_DEFAULT_PLAYER_Y)
28bool Board::isBorder(
int x,
int y)
30 if ((x == 0) || (x == (
int)this->board->
width() - 1) ||
31 (y == 0) || (y == (
int)this->board->height() - 1))
42 return (this->
style == Board::SOLID);
45 return (this->board->
at(x, y));
49 return this->board->
width();
53 return this->board->
height();
55void Board::draw(
Window* win)
57 int teleport_appearance =
'\'';
58 int solid_appearance = ((Globals::Screen::fancy_borders) ?
62 for (
size_t i = 0; i < (this->board->
width()); i++)
64 for (
size_t j = 0; j < (this->board->
height()); j++)
66 if (this->isBorder(i, j))
76 else if (this->
isWall(i, j))
85 for (
size_t i = 0; i < (this->board->
width()); i++) {
86 for (
size_t j = 0; j < (this->board->
height()); j++) {
90 this->board->set(i, j,
true);
95 for (
int i = -2; i != 7; i++)
96 this->board->set(x + i, y,
false);
102 int newx = player->
getX();
103 int newy = player->
getY();
107 int right = this->board->
width() - 2;
109 if (player->
getX() < left)
113 else if (player->
getX() > right)
119 int bottom = this->board->
height() - 2;
121 if (player->
getY() < top)
125 else if (player->
getY() > bottom)
130 player->moveTo(newx, newy);
135 for (
size_t i = 0; i < this->board->
width(); i++)
136 for (
size_t j = 0; j < this->board->
height(); j++)
137 this->board->set(i, j,
false);
142 for (
size_t i = 0; i < this->board->
width(); i++)
143 for (
size_t j = 0; j < this->board->
height(); j++)
144 this->board->set(i, j, newBoard[j][i]);
147int Board::getStartX()
149 return this->start_x;
151int Board::getStartY()
153 return this->start_y;
156void Board::setStartX(
int x)
160void Board::setStartY(
int y)
167 this->metadata[name] = value;
174 return this->metadata[name];
178 return (this->metadata.find(name) != this->metadata.end());
180void Board::scrollLeft()
183 for (
size_t j = 0; j < this->board->
height() - 1; j++)
186 bool tmp = this->board->
at(1, j);
189 for (
size_t i = 0; i < (this->board->
width() - 1); i++)
190 this->board->set(i, j, this->board->at(i + 1, j));
193 this->board->set(this->board->
width() - 2, j, tmp);
196void Board::scrollRight()
199 for (
size_t j = 0; j < this->board->
height() - 1; j++)
202 bool tmp = this->board->
at(this->board->
width() - 2, j);
205 for (
size_t i = (this->board->
width() - 1); i > 0; i--)
206 this->board->set(i, j, this->board->
at(i - 1, j));
209 this->board->set(1, j, tmp);
212void Board::scrollUp()
215 for (
size_t j = 0; j < this->board->
width() - 1; j++)
218 bool tmp = this->board->
at(j, 1);
221 for (
size_t i = 0; i < (this->board->
height() - 1); i++)
222 this->board->set(j, i, this->board->at(j, i + 1));
225 this->board->set(j, this->board->
height() - 2, tmp);
228void Board::scrollDown()
231 for (
size_t j = 0; j < this->board->
width() - 1; j++)
234 bool tmp = this->board->
at(j, this->board->
height() - 2);
237 for (
size_t i = this->board->
height() - 2; i > 0; i--)
238 this->board->set(j, i, this->board->
at(j, i - 1));
241 this->board->set(j, 1, tmp);
size_t height()
Height size of the array.
T at(int x, int y)
Returns element at x y.
size_t width()
Width size of the array.
void randomlyFillExceptBy(int x, int y)
Places random walls all over the Board except by #x and #y, allowing the Player to move a little bit ...
Style style
Tells if the player will teleport when reaching the Board's limits or not.
Style
If the player will teleport when reaching the Board's limits or not.
void setMetadata(std::string name, std::string value)
Sets a meta information from this level.
bool isWall(int x, int y)
Tells if there's a wall at #x #y.
std::string getMetadata(std::string name)
Gets a meta information from this level.
Board(int width, int height, Style style)
Creates a new Board.
void setBoard(std::vector< std::vector< bool > > &newBoard)
Sets the whole level content.
bool hasMetadata(std::string name)
Tells if this level has a specific information attached.
void teleport(Player *player)
Makes the Player teleport if it's on a border.
void clear()
Makes the whole level empty.
int getX()
Returns the head's x position.
int getY()
Returns the head's y position.
A segment of the terminal screen (2D char matrix).
void printChar(int c, int x, int y, ColorPair pair=0)
Shows #c at x y with color #pair.
bool booleanWithChance(float percent)
Random boolean with chance of #percent.