nsnake
Classic snake game for the terminal
Public Types | Public Member Functions | Public Attributes | Static Public Attributes | List of all members
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 

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

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 ( 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.

Member Function Documentation

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.

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.

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.

Member Data Documentation

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: