Unreal Snake Game 1.0.0
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
SnakeGame::Grid Class Reference

Public Member Functions

 Grid (const Dim &dim, const IPositionRandomizerPtr &randomizer=MakeShared< PositionRandomizer >())
 
Dim dim () const
 
void update (const TPositionPtr *links, CellType cellType)
 
void update (const Position &position, CellType cellType)
 
bool hitTest (const Position &position, CellType cellType) const
 
UE_NODISCARD bool randomEmptyPosition (Position &position) const
 
void printDebug ()
 

Static Public Member Functions

static Position center (uint32 width, uint32 height)
 

Private Member Functions

void initWalls ()
 
void updateInternal (const Position &position, CellType cellType)
 
void freeCellsByType (CellType cellType)
 
FORCEINLINE uint32 posToIndex (uint32 x, uint32 y) const
 
FORCEINLINE uint32 posToIndex (const Position &position) const
 

Private Attributes

const Dim c_dim
 
TArray< CellType > m_cells
 
TMap< CellType, TArray< uint32 > > m_indByType
 
TSharedPtr< IPositionRandomizerm_positionRandomizer
 

Member Function Documentation

◆ center()

static Position SnakeGame::Grid::center ( uint32  width,
uint32  height 
)
inlinestatic

Returns center position in grid (walls included)

Parameters
width
height
Returns
Position center of grid

◆ dim()

Dim SnakeGame::Grid::dim ( ) const
inline

Returns grid dimensions including walls (width + 2; height + 2)

Returns
Dim grid dimensions

◆ hitTest()

bool Grid::hitTest ( const Position position,
CellType  cellType 
) const

Checks cell type in the given position

Parameters
positionposition on the grid
cellTypetype of the cell
Returns
bool if hit test was successfull

◆ randomEmptyPosition()

bool Grid::randomEmptyPosition ( Position position) const

Returns empty position by ref

Parameters
[out]positionon the grid
Returns
bool true if empty position exists (if position doesn't exist then snake body fills whole grid)

◆ update() [1/2]

void Grid::update ( const Position position,
CellType  cellType 
)

Update cell with a given cell type

Parameters
positionposition on the grid to be updated
cellTypetype of the cell

◆ update() [2/2]

void Grid::update ( const TPositionPtr *  links,
CellType  cellType 
)

Update cells with a given cell type

Parameters
linkspointer to the position link
cellTypetype of the cell

Member Data Documentation

◆ m_indByType

TMap<CellType, TArray<uint32> > SnakeGame::Grid::m_indByType
private
Initial value:
= {
{CellType::Snake, {}},
{CellType::Wall, {}},
{CellType::Food, {}},
}

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