baba-is-auto
C++17 Baba Is You simulator
Loading...
Searching...
No Matches
baba_is_auto::Map Class Reference

Map class. More...

#include <Map.hpp>

Public Member Functions

 Map ()=default
 Default constructor.
 
 Map (std::size_t width, std::size_t height)
 
void Reset ()
 Resets map data.
 
std::size_t GetWidth () const
 
std::size_t GetHeight () const
 
void Load (std::string_view filename)
 
void AddObject (std::size_t x, std::size_t y, ObjectType type)
 
void AddObject (std::size_t x, std::size_t y, ObjectType type, Direction direction)
 
void RemoveObject (std::size_t x, std::size_t y, ObjectType type)
 
bool RemoveObject (ObjectID id)
 
bool MoveObject (ObjectID id, std::size_t x, std::size_t y)
 
std::optional< PositionGetPosition (ObjectID id) const
 
ObjectInstanceGetInstance (ObjectID id)
 
const ObjectInstanceGetInstance (ObjectID id) const
 
bool SetDirection (ObjectID id, Direction direction)
 
std::optional< DirectionGetDirection (ObjectID id) const
 
ObjectAt (std::size_t x, std::size_t y)
 
const ObjectAt (std::size_t x, std::size_t y) const
 
std::vector< PositionGetPositions (ObjectType type) const
 

Friends

class Game
 

Detailed Description

Map class.

This class represents map. A map is a board of the game.

Constructor & Destructor Documentation

◆ Map() [1/2]

baba_is_auto::Map::Map ( )
default

Default constructor.

◆ Map() [2/2]

baba_is_auto::Map::Map ( std::size_t  width,
std::size_t  height 
)

Constructs map with given width and height.

Parameters
widthThe size of the width.
heightThe size of the height.

Member Function Documentation

◆ AddObject() [1/2]

void baba_is_auto::Map::AddObject ( std::size_t  x,
std::size_t  y,
ObjectType  type 
)

Adds an object to the map.

Parameters
xThe x position.
yThe y position.
typeAn object type to add to the map.

◆ AddObject() [2/2]

void baba_is_auto::Map::AddObject ( std::size_t  x,
std::size_t  y,
ObjectType  type,
Direction  direction 
)

Adds an object with an initial facing direction.

Parameters
xThe x position.
yThe y position.
typeAn object type to add to the map.
directionAn initial facing direction of the object.

◆ At() [1/2]

Object & baba_is_auto::Map::At ( std::size_t  x,
std::size_t  y 
)

Gets a writable object reference from the map.

Parameters
xThe x position.
yThe y position.
Returns
A writable object reference at the zero-based (x, y) position.

◆ At() [2/2]

const Object & baba_is_auto::Map::At ( std::size_t  x,
std::size_t  y 
) const

Gets an object from the map.

Parameters
xThe x position.
yThe y position.
Returns
An object at row and column.

◆ GetDirection()

std::optional< Direction > baba_is_auto::Map::GetDirection ( ObjectID  id) const

Gets an object's facing direction.

Parameters
idThe stable ID of the object.
Returns
The facing direction of the object, or std::nullopt if not found.

◆ GetHeight()

std::size_t baba_is_auto::Map::GetHeight ( ) const

Gets the height of the map.

Returns
The height of the map.

◆ GetInstance() [1/2]

ObjectInstance * baba_is_auto::Map::GetInstance ( ObjectID  id)

Gets an object by stable ID.

Parameters
idThe stable ID of the object.
Returns
A pointer to the object instance, or nullptr if not found.

◆ GetInstance() [2/2]

const ObjectInstance * baba_is_auto::Map::GetInstance ( ObjectID  id) const

Gets an object by stable ID.

Parameters
idThe stable ID of the object.
Returns
A pointer to the object instance, or nullptr if not found.

◆ GetPosition()

std::optional< Position > baba_is_auto::Map::GetPosition ( ObjectID  id) const

Gets an object's current position.

Parameters
idThe stable ID of the object.
Returns
The current position of the object.

◆ GetPositions()

std::vector< Position > baba_is_auto::Map::GetPositions ( ObjectType  type) const

Gets a list of icon positions.

Parameters
typeAn object type to get a list of positions.
Returns
A list of icon positions.

◆ GetWidth()

std::size_t baba_is_auto::Map::GetWidth ( ) const

Gets the width of the map.

Returns
The width of the map.

◆ Load()

void baba_is_auto::Map::Load ( std::string_view  filename)

Loads the data of the map.

Parameters
filenameThe file name to load.
Exceptions
std::runtime_errorIf the map data is invalid.

◆ MoveObject()

bool baba_is_auto::Map::MoveObject ( ObjectID  id,
std::size_t  x,
std::size_t  y 
)

Moves an object by stable ID, preserving its state.

Parameters
idThe stable ID of the object to move.
xThe new x position.
yThe new y position.
Returns
True if the object was moved successfully, false otherwise.

◆ RemoveObject() [1/2]

bool baba_is_auto::Map::RemoveObject ( ObjectID  id)

Removes an object by stable ID.

Parameters
idThe stable ID of the object to remove.
Returns
True if the object was removed successfully, false otherwise.

◆ RemoveObject() [2/2]

void baba_is_auto::Map::RemoveObject ( std::size_t  x,
std::size_t  y,
ObjectType  type 
)

Removes an object from the map.

Parameters
xThe x position.
yThe y position.
typeAn object type to remove from the map.

◆ Reset()

void baba_is_auto::Map::Reset ( )

Resets map data.

◆ SetDirection()

bool baba_is_auto::Map::SetDirection ( ObjectID  id,
Direction  direction 
)

Updates an object's facing direction.

Parameters
idThe stable ID of the object.
directionThe new facing direction of the object.
Returns
True if the direction was updated successfully, false otherwise.

Friends And Related Symbol Documentation

◆ Game

friend class Game
friend

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