nsnake
Classic snake game for the terminal
Loading...
Searching...
No Matches
Board Class Reference

A level where the snake runs and eats fruits. More...

#include <Board.hpp>

Public Types

enum  Style { SOLID , TELEPORT }
 If the player will teleport when reaching the Board's limits or not. More...
 

Public Member Functions

 Board (int width, int height, Style style)
 Creates a new Board.
 
bool isWall (int x, int y)
 Tells if there's a wall at #x #y.
 
bool isBorder (int x, int y)
 
int getW ()
 
int getH ()
 
void draw (Window *win)
 
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 when starting.
 
void teleport (Player *player)
 Makes the Player teleport if it's on a border.
 
void clear ()
 Makes the whole level empty.
 
void setBoard (std::vector< std::vector< bool > > &newBoard)
 Sets the whole level content.
 
int getStartX ()
 
int getStartY ()
 
void setStartX (int x)
 
void setStartY (int y)
 
void setMetadata (std::string name, std::string value)
 Sets a meta information from this level.
 
std::string getMetadata (std::string name)
 Gets a meta information from this level.
 
bool hasMetadata (std::string name)
 Tells if this level has a specific information attached.
 
void scrollLeft ()
 
void scrollRight ()
 
void scrollUp ()
 
void scrollDown ()
 

Public Attributes

Style style
 Tells if the player will teleport when reaching the Board's limits or not.
 

Static Public Attributes

static int small_width = 40
 
static int small_height = 10
 
static int medium_width = 55
 
static int medium_height = 14
 
static int large_width = 78
 
static int large_height = 21
 

Detailed Description

A level where the snake runs and eats fruits.

Note
I couldn't name this class "Level" because it could get confusing with the concept of game speed, which is also based on the word "Level".

This class represents a single level the snake can play on.

It is essentially a 2D matrix of tiles, where each can be either "Walls" or "Empty.

It also contains some extra info, like the position where the player should spawn, and (if this level was created by someone) the author, date and stuff.

Definition at line 32 of file Board.hpp.

Member Enumeration Documentation

◆ Style

If the player will teleport when reaching the Board's limits or not.

Definition at line 46 of file Board.hpp.

Constructor & Destructor Documentation

◆ Board()

Board::Board ( int width,
int height,
Style style )

Creates a new Board.

Parameters
widthWhole level width
heightWhole level height
styleIf the player will teleport when reaching the limits

Definition at line 15 of file Board.cpp.

◆ ~Board()

Board::~Board ( )
virtual

Definition at line 24 of file Board.cpp.

Member Function Documentation

◆ clear()

void Board::clear ( )

Makes the whole level empty.

Definition at line 132 of file Board.cpp.

◆ draw()

void Board::draw ( Window * win)

Definition at line 55 of file Board.cpp.

◆ getH()

int Board::getH ( )

Definition at line 51 of file Board.cpp.

◆ getMetadata()

std::string Board::getMetadata ( std::string name)

Gets a meta information from this level.

Returns
Requested info or empty string if not exists.

Definition at line 169 of file Board.cpp.

◆ getStartX()

int Board::getStartX ( )

Definition at line 147 of file Board.cpp.

◆ getStartY()

int Board::getStartY ( )

Definition at line 151 of file Board.cpp.

◆ getW()

int Board::getW ( )

Definition at line 47 of file Board.cpp.

◆ hasMetadata()

bool Board::hasMetadata ( std::string name)

Tells if this level has a specific information attached.

Definition at line 176 of file Board.cpp.

◆ isBorder()

bool Board::isBorder ( int x,
int y )

Definition at line 28 of file Board.cpp.

◆ isWall()

bool Board::isWall ( int x,
int y )

Tells if there's a wall at #x #y.

Definition at line 36 of file Board.cpp.

◆ randomlyFillExceptBy()

void Board::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 when starting.

Definition at line 83 of file Board.cpp.

◆ scrollDown()

void Board::scrollDown ( )

Definition at line 228 of file Board.cpp.

◆ scrollLeft()

void Board::scrollLeft ( )

Definition at line 180 of file Board.cpp.

◆ scrollRight()

void Board::scrollRight ( )

Definition at line 196 of file Board.cpp.

◆ scrollUp()

void Board::scrollUp ( )

Definition at line 212 of file Board.cpp.

◆ setBoard()

void Board::setBoard ( std::vector< std::vector< bool > > & newBoard)

Sets the whole level content.

Parameters
newBoard2D matrix of booleans, telling if there's a "Wall" on that tile or not.

Definition at line 139 of file Board.cpp.

◆ setMetadata()

void Board::setMetadata ( std::string name,
std::string value )

Sets a meta information from this level.

Definition at line 165 of file Board.cpp.

◆ setStartX()

void Board::setStartX ( int x)

Definition at line 156 of file Board.cpp.

◆ setStartY()

void Board::setStartY ( int y)

Definition at line 160 of file Board.cpp.

◆ teleport()

void Board::teleport ( Player * player)

Makes the Player teleport if it's on a border.

Definition at line 98 of file Board.cpp.

Member Data Documentation

◆ large_height

int Board::large_height = 21
static

Definition at line 42 of file Board.hpp.

◆ large_width

int Board::large_width = 78
static

Definition at line 41 of file Board.hpp.

◆ medium_height

int Board::medium_height = 14
static

Definition at line 39 of file Board.hpp.

◆ medium_width

int Board::medium_width = 55
static

Definition at line 38 of file Board.hpp.

◆ small_height

int Board::small_height = 10
static

Definition at line 36 of file Board.hpp.

◆ small_width

int Board::small_width = 40
static

Definition at line 35 of file Board.hpp.

◆ style

Style Board::style

Tells if the player will teleport when reaching the Board's limits or not.

Note
The Board adapts automatically if you change this on-the-fly.

Definition at line 90 of file Board.hpp.


The documentation for this class was generated from the following files: