Game of Ur 0.3.3
This is a computer adaptation of Game of Ur, written in C++ mainly using SDL and OpenGL.
Loading...
Searching...
No Matches
House Class Reference

The representation of a single house on the Game of Ur Board, in other words a tile. More...

#include <house.hpp>

Public Types

enum  Type : uint8_t { REGULAR , ROSETTE }
 The type of a house.
 
enum  Region : uint8_t { BATTLEFIELD , BLACK =RoleID::BLACK , WHITE =RoleID::WHITE }
 The region this house belongs to.
 

Public Member Functions

 House (glm::i8vec2 nextCell, Type houseType, Region region)
 Constructs a new House.
 
void move (std::shared_ptr< Piece > gamePiece)
 Validates and applies a move, replacing the reference to the currently occupying piece with a new one.
 
std::weak_ptr< PiecegetOccupantReference ()
 Gets a reference to the piece already occupying this house, if any.
 
PieceIdentity getOccupant () const
 Gets the identity of the piece occupying this house.
 
bool isOccupied () const
 Tests whether this house is already occupied by a game piece.
 
bool isRosette () const
 Tests whether this house is a rosette house.
 
Region getRegion () const
 Gets the region this house belongs to.
 
Type getType () const
 Gets which type of house this house is.
 
glm::i8vec2 getNextCellDirection () const
 Gets an integral vector pointing to the location of the next House, relative to this one.
 
bool canMove (const Piece &gamePiece) const
 Tests whether a given piece can move into this house.
 

Private Attributes

glm::i8vec2 mNextCell
 Direction to the location of the next House, relative to this one.
 
Type mType
 The type of House this one is.
 
Region mRegion
 The region in which this House lies.
 
std::weak_ptr< PiecemOccupant {}
 The piece occupying this house, if any.
 

Detailed Description

The representation of a single house on the Game of Ur Board, in other words a tile.

Also stores a reference to the game piece presently occupying this house.

Constructor & Destructor Documentation

◆ House()

House::House ( glm::i8vec2 nextCell,
Type houseType,
Region region )
inline

Constructs a new House.

Parameters
nextCellThe direction to the next House relative to this one.
houseTypeThe type of house this is.
regionThe region in which this house is present.

Member Function Documentation

◆ canMove()

bool House::canMove ( const Piece & gamePiece) const

Tests whether a given piece can move into this house.

The conditions determining this are as follows:

  • This house must be a region accessible by the piece's owner (i.e., their own region or the battlefield)
  • This house must be unoccupied.
  • If this house is occupied, then it must be a non-rosette house occupied by a piece belonging to an opponent.

In all other cases, the house can't be occupied by this piece.

Parameters
gamePieceThe piece trying to occupy this house.
Return values
trueThis piece may move into this house.
falseThis piece can't move into this house.
Todo
We shouldn't need Piece here, just PieceIdentity should do.

◆ getNextCellDirection()

glm::i8vec2 House::getNextCellDirection ( ) const
inline

Gets an integral vector pointing to the location of the next House, relative to this one.

Returns
glm::i8vec2 A vector pointing in the direction of the next house from this one.

◆ getOccupant()

PieceIdentity House::getOccupant ( ) const

Gets the identity of the piece occupying this house.

Returns
PieceIdentity The ID of the piece occupying this house.

◆ getOccupantReference()

std::weak_ptr< Piece > House::getOccupantReference ( )
inline

Gets a reference to the piece already occupying this house, if any.

Returns
std::weak_ptr<Piece> A reference to the piece occupying this house.

◆ getRegion()

Region House::getRegion ( ) const
inline

Gets the region this house belongs to.

Returns
Region The region this house belongs to.

◆ getType()

Type House::getType ( ) const
inline

Gets which type of house this house is.

Returns
Type This house's type.

◆ isOccupied()

bool House::isOccupied ( ) const
inline

Tests whether this house is already occupied by a game piece.

Return values
trueThere is a game piece on this house.
falseThere is no game piece on this house.

◆ isRosette()

bool House::isRosette ( ) const
inline

Tests whether this house is a rosette house.

Return values
trueThis house is a rosette house.
falseThis house is not a rosette house.

◆ move()

void House::move ( std::shared_ptr< Piece > gamePiece)

Validates and applies a move, replacing the reference to the currently occupying piece with a new one.

Passing an empty pointer causes this house to lose its reference to its current occupant.

Warning
This method assumes that any higher level game logic checks were already performed before it was called.
Parameters
gamePieceThe piece to now occupy this, or a nullptr if the piece here is to be moved.

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