mtx.Cell

class Cell(field, x, y)[source]

Bases: object

Class to manage a cell that is part of a playing field at a specific position.

Each cell can hold game objects that are kept in a list and methods are provided to add new game objects, delete existing ones, access neighboring cells, and query whether a new game object can be placed on the cell.

Parameters:
  • field (mtx.Field) – The parent of the cell.
  • x (int) – The x coordinate of the cell within the field.
  • y (int) – The y coordinate of the cell within the field.
Add(obj)[source]

Adds a new object to the cell.

Parameters:obj (mtx.BaseObject) – The object to be added to the cell.
GetFirstObject()[source]
Returns:The top most object on the cell or None if none exists.
Return type:mtx.BaseObject or None
GetNeighbour(location, distance=1)[source]

Returns the neighboring cell described by location and distance. location must be one of mtx.UP, mtx.RIGHT, mtx.DOWN, mtx.LEFT

Parameters:
  • location (int) – The location relative to this cell.
  • distance (int) – The distance from this cell. The default is 1.
Returns:

The neighboring cell.

Return type:

mtx.Cell

Raises:

AttributeError – If location is not valid.

GetObjectBelow(obj)[source]
Parameters:obj (mtx.BaseObject) – The object from which the next underlying object is to be returned.
Returns:The first object below the given one or None if none exists.
Return type:mtx.BaseObject or None
GetObjectCount(symbol)[source]
Parameters:symbol (str) – The symbol of an object.
Returns:The number of objects with the given symbol.
Return type:int
GetPosition()[source]
Returns:The position of the cell.
Return type:tuple
IsAccessible(moving, gameSettings)[source]

Returns, if an object can be placed on the cell. The result depends on the objects the cell containing and the settings of the game.

Parameters:
  • moving (bool) – True, if the cell will be entered by a move (not a jump), False otherise. If move is True and there is a moving object on the cell which can also be moved, access is granted.
  • gameSettings (mtx.Settings) – The settings of the game.
Returns:

True, if cell is accessible, False otherwise.

Return type:

bool

Remove(obj)[source]

Removes an object from the cell.

Parameters:obj (mtx.BaseObject) – The object to be removed from the cell.
Raises:LookupError – If the object is not in the objects list.