Sokoban
Public Member Functions | Private Member Functions | Private Attributes | List of all members
TwoPlayerMap Class Reference

Class which represents map for two players. More...

#include <Map.h>

Inheritance diagram for TwoPlayerMap:
Map

Public Member Functions

 TwoPlayerMap (std::ifstream &map_stream)
 Constructor. More...
 
bool complete () override
 Checks if map is completed (all barrels are on targets). More...
 
void restart () override
 Restarts level. More...
 
bool solve () override
 This method does nothing. More...
 
bool play_solution_next () override
 This method does nothing. More...
 
element get_field_type (int x, int y) override
 Gets type of cell. More...
 
bool is_dead_position () override
 This method does nothing. More...
 
void right_move () override
 
void left_move () override
 
void up_move () override
 
void down_move () override
 
void right_move_second () override
 
void left_move_second () override
 
void up_move_second () override
 
void down_move_second () override
 
- Public Member Functions inherited from Map
virtual ~Map ()
 Virtual destructor. More...
 
int get_width () const
 Gets with of map (horizontal number of cells). More...
 
int get_height () const
 Gets with of map (vertical number of cells). More...
 

Private Member Functions

int move_sokoban (int v_x, int v_y, bool first_sokoban=true)
 General method for sokoban movement. More...
 

Private Attributes

TwoPlayerGameState state
 
TwoPlayerGameState start_state
 

Additional Inherited Members

- Static Public Attributes inherited from Map
static const char NUMBER_OF_FIELDS = 10
 
static const int MAX_STEPS = 1000
 
static const char EOM = 'x'
 
static const element GROUND = 0
 
static const element TARGET = 1
 
static const element BARREL = 2
 
static const element BARREL_TARGET = 3
 
static const element SOKOBAN = 4
 
static const element SOKOBAN_TARGET = 5
 
static const element WALL = 6
 
static const element GRASS = 7
 
static const element SOKOBAN_2 = 8
 
static const element SOKOBAN_2_TARGET = 9
 
- Protected Member Functions inherited from Map
 Map (std::ifstream &map_stream)
 Constructor. More...
 
bool is_valid_position (int x, int y)
 Checks if position (x,y) is in map grid. More...
 
- Protected Attributes inherited from Map
std::vector< std::vector< char > > game_grid
 
int number_of_barrels
 
int width
 
int height
 
TwoPlayerGameState init_state
 Game state which is used by the constructor for general map including a position of sokoban and position of barrels. More...
 

Detailed Description

Class which represents map for two players.

Some of the general methods which are inherrited does nothing.

Constructor & Destructor Documentation

◆ TwoPlayerMap()

TwoPlayerMap::TwoPlayerMap ( std::ifstream &  map_stream)

Constructor.

Creates the two player map from the input file. It uses the constructor from ancestor to reach it.

See also
Map::Map()
Parameters
map_streamInput stream which the map is made from.

Member Function Documentation

◆ complete()

bool TwoPlayerMap::complete ( )
inlineoverridevirtual

Checks if map is completed (all barrels are on targets).

Returns
Bool value which determines if map is completed.

Implements Map.

◆ down_move()

void TwoPlayerMap::down_move ( )
inlineoverridevirtual

Moves the first sokoban down if it is possible.

Implements Map.

◆ down_move_second()

void TwoPlayerMap::down_move_second ( )
inlineoverridevirtual

Moves the second sokoban down if it is possible.

Implements Map.

◆ get_field_type()

element TwoPlayerMap::get_field_type ( int  x,
int  y 
)
inlineoverridevirtual

Gets type of cell.

Parameters
xThe coordinate x of cell.
yThe coordinate y of cell.
Returns
Byte number which represents field type according to the constants.

Implements Map.

◆ is_dead_position()

bool TwoPlayerMap::is_dead_position ( )
inlineoverridevirtual

This method does nothing.

It is implemented only in the single player map.

Todo:
Returns
Just false.

Implements Map.

◆ left_move()

void TwoPlayerMap::left_move ( )
inlineoverridevirtual

Moves the first sokoban to the left if it is possible.

Implements Map.

◆ left_move_second()

void TwoPlayerMap::left_move_second ( )
inlineoverridevirtual

Moves the second sokoban to the left if it is possible

Implements Map.

◆ move_sokoban()

int TwoPlayerMap::move_sokoban ( int  v_x,
int  v_y,
bool  first_sokoban = true 
)
private

General method for sokoban movement.

The direction is defined by vector.

Parameters
v_xThe part x of vector which represents move direction of Sokoban. It may be -1,0 or 1.
v_yThe part x of vector which represents move direction of Sokoban. It may be -1,0 or 1.
first_sokobanDetermines if it is the movement of the first sokoban.
Returns
0 if Sokoban was moved, -1 if Sokoban cannot be moved, -2 if input vector cannot represent Sokoban movement

◆ play_solution_next()

bool TwoPlayerMap::play_solution_next ( )
inlineoverridevirtual

This method does nothing.

It is implemented only in one player map.

Todo:
Returns
Just false.

Implements Map.

◆ restart()

void TwoPlayerMap::restart ( )
inlineoverridevirtual

Restarts level.

Implements Map.

◆ right_move()

void TwoPlayerMap::right_move ( )
inlineoverridevirtual

Moves the first sokoban to the right if it is possible.

Implements Map.

◆ right_move_second()

void TwoPlayerMap::right_move_second ( )
inlineoverridevirtual

Moves the second sokoban to the right if it is possible

Implements Map.

◆ solve()

bool TwoPlayerMap::solve ( )
inlineoverridevirtual

This method does nothing.

It is implemented only in one player map.

Todo:
Returns
Just false.

Implements Map.

◆ up_move()

void TwoPlayerMap::up_move ( )
inlineoverridevirtual

Moves the first sokoban up if it is possible.

Implements Map.

◆ up_move_second()

void TwoPlayerMap::up_move_second ( )
inlineoverridevirtual

Moves the second sokoban up if it is possible.

Implements Map.

Member Data Documentation

◆ start_state

TwoPlayerGameState TwoPlayerMap::start_state
private

Default state of game - for restart

◆ state

TwoPlayerGameState TwoPlayerMap::state
private

State of game including a position of sokoban and position of barrels.


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