Micropolis
Position Class Reference

#include <position.h>

Public Member Functions

 Position ()
 
 Position (int x, int y)
 
 Position (const Position &pos)
 
 Position (const Position &pos, Direction2 dir)
 
 Position (const Position &pos, int dx, int dy)
 
Positionoperator= (const Position &pos)
 
bool move (Direction2 dir)
 
bool testBounds ()
 

Public Attributes

int posX
 Horizontal coordinate of the position.
 
int posY
 Vertical coordnate of the position.
 

Detailed Description

X/Y position.

Definition at line 154 of file position.h.

Constructor & Destructor Documentation

◆ Position() [1/5]

Position::Position ( )

Default constructor.

Definition at line 86 of file position.cpp.

References posX, and posY.

◆ Position() [2/5]

Position::Position ( int  x,
int  y 
)

Construct a position at a given x and y coordinate.

Parameters
xX coordinate of the new position.
yY coordinate of the new position.

Definition at line 98 of file position.cpp.

References posX, and posY.

◆ Position() [3/5]

Position::Position ( const Position pos)

Copy constructor.

Parameters
posPosition to copy.

Definition at line 109 of file position.cpp.

References posX, and posY.

◆ Position() [4/5]

Position::Position ( const Position pos,
Direction2  dir 
)

Copy constructor with a single tile movement.

Parameters
posPosition to copy.
dirDirection to move into.

Definition at line 121 of file position.cpp.

References move(), posX, and posY.

◆ Position() [5/5]

Position::Position ( const Position pos,
int  dx,
int  dy 
)

Copy constructor with arbitrary movement.

Parameters
posPosition to copy.
dxHorizontal offset.
dyVertical offset.

Definition at line 135 of file position.cpp.

References posX, and posY.

Member Function Documentation

◆ move()

bool Position::move ( Direction2  dir)

Move the position one step in the indicated direction.

Parameters
dirDirection to move into.
Returns
Position moved in the indicated direction.

Definition at line 161 of file position.cpp.

References DIR2_EAST, DIR2_INVALID, DIR2_NORTH, DIR2_NORTH_EAST, DIR2_NORTH_WEST, DIR2_SOUTH, DIR2_SOUTH_EAST, DIR2_SOUTH_WEST, DIR2_WEST, NOT_REACHED, posX, posY, WORLD_H, and WORLD_W.

Referenced by Micropolis::doBRiver(), Micropolis::doPowerScan(), Micropolis::doSRiver(), Position(), Micropolis::testForConductive(), Micropolis::treeSplash(), and Micropolis::tryDrive().

◆ operator=()

Position & Position::operator= ( const Position pos)

Assignment operator.

Parameters
posPosition to copy.

Definition at line 146 of file position.cpp.

References posX, and posY.

◆ testBounds()

bool Position::testBounds ( )
inline

Test whether the position is on-map.

Returns
Position is on-map.

Definition at line 177 of file position.h.

References posX, posY, WORLD_H, and WORLD_W.

Referenced by Micropolis::addToTrafficDensityMap(), and Micropolis::treeSplash().


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