Eile Mit Weile
Loading...
Searching...
No Matches
Space Class Reference

Abstract Base Class. Represents a space on the board. More...

#include <Space.hpp>

Inheritance diagram for Space:
UniqueSerializable Serializable BenchSpace FinishArea HomeField LadderSpace NormalSpace

Public Member Functions

 Space (unsigned space_idx, std::vector< Figure * > figures=std::vector< Figure * >(0))
 
 ~Space ()
 
virtual unsigned GetTypeOfSpace () const
 
virtual unsigned AddFigure (Figure *figure)
 
virtual FigureRemoveFigure (Figure *figure)
 
virtual std::vector< Figure * > GetFigures ()
 
unsigned GetSpaceIdx () const
 
virtual bool IsBlocked () const
 
void WriteIntoJson (rapidjson::Value &json, rapidjson::Document::AllocatorType &allocator) const override
 
- Public Member Functions inherited from UniqueSerializable
std::string GetId () const
 
void WriteIntoJson (rapidjson::Value &json, rapidjson::MemoryPoolAllocator< rapidjson::CrtAllocator > &allocator) const override
 
- Public Member Functions inherited from Serializable
virtual rapidjson::DocumentToJson () const
 

Protected Member Functions

 Space (std::string id, unsigned space_idx, std::vector< Figure * > figures)
 
- Protected Member Functions inherited from UniqueSerializable
 UniqueSerializable ()
 
 UniqueSerializable (std::string id)
 

Protected Attributes

std::vector< Figure * > _figures
 
unsigned _space_idx
 
- Protected Attributes inherited from UniqueSerializable
std::string id
 

Detailed Description

Abstract Base Class. Represents a space on the board.

A space is identified by its index. The index is used to determine which space a Figure is to be moved to. The convention for space indices is found in Board.

Special spaces are derived from this class. They are identifiable by an integer returned by GetTypeOfSpace().
However, for some spaces, their _space_idx is fixed and thus we don't need to use GetTypeOfSpace() to identify them. For normal spaces there's also no need for identification as they do not have any special behaviour.
For the sake of completeness GetTypeOfSpace() is implemented for all Space derivatives regardless.
Here's a list of the integer values returned by GetTypeOfSpace() for each space type:

Constructor & Destructor Documentation

◆ Space() [1/2]

Space::Space ( unsigned  space_idx,
std::vector< Figure * >  figures = std::vector< Figure * >(0) 
)
explicit

Constructor: creates a Space with a space index (_space_idx)

◆ ~Space()

Space::~Space ( )

Destructor: deletes all Figures on the Space

◆ Space() [2/2]

Space::Space ( std::string  id,
unsigned  space_idx,
std::vector< Figure * >  figures 
)
explicitprotected

Deserialization constructor used by FromJson (only defined in derivatives)

Member Function Documentation

◆ AddFigure()

unsigned Space::AddFigure ( Figure figure)
virtual

Adds a Figure to the space. Returns the amount of figures on the space.

Reimplemented in BenchSpace, and HomeField.

◆ GetFigures()

std::vector< Figure * > Space::GetFigures ( )
virtual

Getter for _figures

◆ GetSpaceIdx()

unsigned Space::GetSpaceIdx ( ) const

Getter for _space_idx

◆ GetTypeOfSpace()

unsigned Space::GetTypeOfSpace ( ) const
virtual

Returns the type of the space. Derivatives (e.g. BenchSpace) override this function.

Reimplemented in BenchSpace, FinishArea, HomeField, LadderSpace, and NormalSpace.

◆ IsBlocked()

bool Space::IsBlocked ( ) const
virtual

Indicates whether the space is blocked by two figures of the same player. For all space types except BenchSpace this is always false.

Reimplemented in BenchSpace.

◆ RemoveFigure()

Figure * Space::RemoveFigure ( Figure figure)
virtual

Removes a Figure from the space and returns its pointer.

Reimplemented in BenchSpace.

◆ WriteIntoJson()

void Space::WriteIntoJson ( rapidjson::Value json,
rapidjson::Document::AllocatorType &  allocator 
) const
overridevirtual

Serializes a Space object into a json object. Used by server.

Implements Serializable.

Member Data Documentation

◆ _figures

std::vector<Figure* > Space::_figures
protected

The Figures on the space. Used as a push/pop list.

◆ _space_idx

unsigned Space::_space_idx
protected

Denotes the index of the space. See Board for which index represents which space.


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