RpgGame
Console Based RPG game in C#
Loading...
Searching...
No Matches
RpgGame.Core.Level Class Reference

Represents a single game level containing terrain tiles, item placements, and movement validation logic. More...

Collaboration diagram for RpgGame.Core.Level:

Public Member Functions

 Level (int width, int height)
 Initializes a new instance of the Level class.
 
Tile GetTile (int x, int y)
 Retrieves the tile at the specified coordinates.
 
void SetTile (int x, int y, Tile tile)
 Sets the tile at the specified coordinates.
 
void TryMoveCharacter (Character.Character character, Position nPos)
 Attempts to move a character to a new position if the move is valid. Also handles item interactions for players.
 
bool IsMoveValid (Character.Character character, Position nPos)
 Determines whether a character can move to the specified position.
 
bool IsInBounds (Position pos)
 Checks whether the specified position lies within the level boundaries.
 
void AddItem (Position pos, IItem item)
 Adds an item to the specified position in the level.
 
IReadOnlyList< IItemGetItemsAt (Position pos)
 Retrieves all items located at a given position.
 
IItemGetTopItem (Position pos)
 Retrieves the top item at a position without removing it.
 
IItemTakeTopItem (Position pos)
 Removes and returns the top item at a given position.
 
int TotalItemsAt (Position pos)
 Returns the total number of items at a given position.
 
bool HasItems (Position pos)
 Determines whether any items exist at a given position.
 

Properties

int Width [get]
 Width of the level in tiles.
 
int Height [get]
 Height of the level in tiles.
 

Detailed Description

Represents a single game level containing terrain tiles, item placements, and movement validation logic.

The Level class acts as the central authority for world state. It manages:

  • Tile grid storage
  • Item placement on the ground
  • Movement validation for characters

The class enforces boundary rules and ensures characters cannot move into non-walkable or occupied tiles.

Constructor & Destructor Documentation

◆ Level()

RpgGame.Core.Level.Level ( int  width,
int  height 
)
inline

Initializes a new instance of the Level class.

Parameters
widthWidth of the level grid.
heightHeight of the level grid.

Member Function Documentation

◆ AddItem()

void RpgGame.Core.Level.AddItem ( Position  pos,
IItem  item 
)
inline

Adds an item to the specified position in the level.

Parameters
posThe position where the item should be placed.
itemThe item to add.
Here is the caller graph for this function:

◆ GetItemsAt()

IReadOnlyList< IItem > RpgGame.Core.Level.GetItemsAt ( Position  pos)
inline

Retrieves all items located at a given position.

Parameters
posThe position to query.
Returns
A read-only list of items at the specified position. Returns an empty list if no items are present.

◆ GetTile()

Tile RpgGame.Core.Level.GetTile ( int  x,
int  y 
)
inline

Retrieves the tile at the specified coordinates.

Parameters
xHorizontal coordinate.
yVertical coordinate.
Returns
The tile located at the given position.
Here is the caller graph for this function:

◆ GetTopItem()

IItem? RpgGame.Core.Level.GetTopItem ( Position  pos)
inline

Retrieves the top item at a position without removing it.

Parameters
posThe position to query.
Returns
The first item in the stack if present; otherwise null.
Here is the caller graph for this function:

◆ HasItems()

bool RpgGame.Core.Level.HasItems ( Position  pos)
inline

Determines whether any items exist at a given position.

Parameters
posThe position to check.
Returns
True if items exist; otherwise false.

◆ IsInBounds()

bool RpgGame.Core.Level.IsInBounds ( Position  pos)
inline

Checks whether the specified position lies within the level boundaries.

Parameters
posThe position to check.
Returns
True if the position is within bounds; otherwise false.
Here is the caller graph for this function:

◆ IsMoveValid()

bool RpgGame.Core.Level.IsMoveValid ( Character::Character  character,
Position  nPos 
)
inline

Determines whether a character can move to the specified position.

Parameters
characterThe character attempting to move.
nPosThe target position.
Returns
True if the move is within bounds, walkable, and unoccupied; otherwise false.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetTile()

void RpgGame.Core.Level.SetTile ( int  x,
int  y,
Tile  tile 
)
inline

Sets the tile at the specified coordinates.

Parameters
xHorizontal coordinate.
yVertical coordinate.
tileThe tile to assign.
Exceptions
ArgumentNullExceptionThrown if the tile parameter is null.
Here is the caller graph for this function:

◆ TakeTopItem()

IItem? RpgGame.Core.Level.TakeTopItem ( Position  pos)
inline

Removes and returns the top item at a given position.

Parameters
posThe position from which to take the item.
Returns
The removed item if present; otherwise null.
Here is the caller graph for this function:

◆ TotalItemsAt()

int RpgGame.Core.Level.TotalItemsAt ( Position  pos)
inline

Returns the total number of items at a given position.

Parameters
posThe position to query.
Returns
The number of items at that position.

◆ TryMoveCharacter()

void RpgGame.Core.Level.TryMoveCharacter ( Character::Character  character,
Position  nPos 
)
inline

Attempts to move a character to a new position if the move is valid. Also handles item interactions for players.

Parameters
characterThe character attempting to move.
nPosThe target position.
Here is the call graph for this function:
Here is the caller graph for this function:

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