mtx.Game

class Game[source]

Bases: mtx.Game.GameInterface

AddAct(act)[source]
GetAccessibleNeighbourCell(obj, moving, direction, distance=1)[source]
GetLevel()[source]
Returns:The object of the currently loaded level.
Return type:mtx.Level
GetSettings()[source]
Returns:The settings object of this game.
Return type:mtx.Settings
HasPlayer(number)[source]
IsCellAccessible(cell, moving)[source]
JumpObject(obj, direction, distance)[source]

Jump with an object in the given direction and distance.

Parameters:
  • obj (mtx.BaseObject) – Object which is to perform a jump.
  • direction (int) – Direction in which to jump.
  • distance (int) – Distance how far to jump.
Returns:

True, if the object could jump, False otherwise.

JumpPlayer(number, direction, distance)[source]

Jump with a player in the given direction and distance.

Parameters:
  • number (int) – The number of the player.
  • direction (int) – Direction in which to jump.
  • distance (int) – Distance how far to jump.
Returns:

True, if the player could jump, False otherwise.

MoveObject(obj, direction, moveDepth=1)[source]

Moves an object in the given direction.

Parameters:
  • obj (mtx.BaseObject) – The object to be moved.
  • direction (int) – Direction in which the objekt is to be moved.
  • moveDepth (int) – The maximum number of adjacent moving objects that can be moved at a time.
Returns:

True, if the object could be moved, False otherwise.

MovePlayer(number, direction, moveDepth=1)[source]

Moves a player with given number in the given direction.

Parameters:
  • number (int) – The number of the player.
  • direction (int) – Direction in which the player is to be moved.
  • moveDepth (int) – The maximum number of adjacent moving objects that can be moved at a time.
Returns:

True, if the player could be moved, False otherwise.

NextLevel()[source]
SetConsole(console)[source]

Sets the game console that is responsible for managing this game.

The method is used internally and should not be called externally.

Parameters:console (mtx.GameConsole) – A game console object.


class GameInterface[source]

Bases: object

classmethod GetAuthor()[source]

Returns the author of the game. This is shown in the game console during the game selection. By default, ‘Unknown’ is returned.

Returns:The author of the game.
Return type:str
static GetDescription()[source]

Returns the description of the game. This is shown in the game console during the game selection. By default, an empty string is returned.

Returns:The description of the game.
Return type:str
static GetMaxPlayers()[source]

Returns the maximum number of players that can play at the same time on this game. By default, 1 is returned.

Returns:The maximum number of players.
Return type:int
classmethod GetName()[source]

Returns the unique name of the game. The default name is the name of the class. The method must only be overwritten if the name to be used differs from the class name.

Returns:The unique name of the game.
Return type:str
GetNextLevel(number)[source]

This method is called from the game console to get the next level.

! You must override this method and have to return a level object.

Parameters:number (int) – The number of the level to be loaded (starting at 1).
Returns:A mtx.Level object to load as the next level or None if there is no next level.
Raises:NotImplementedError – If there is no implementation for this method.

Examples

A level can be created by using a level definition, which is a dictionary that defines all the information for the level. The level structure itself is defined by an ascii matrix where each ascii sign represents one or more game objects.

def GetNextLevel(self, number):
    levelDef = {'name':  'Level 1',
                'plan': ['#####',
                         '#1bt#',
                         '#####']}

    return mtx.Level.Create(levelDef)

If you want to create a level based on an algorithm, than you have to create a mtx.Level object. Use the:class:Add<mtx.Level.Add> method, to add game objects to the level.

def GetNextLevel(self, number):
    level = mtx.Level(5, 3, 'Level 1')

    level.Add(0, 0, '#')
    ...

    return level
OnCollect(collectable, source)[source]

Event method, which is called when a collectable object is to be collected. To veto, the method should return False.

Parameters:
Returns:

True if the collectable object can be collected and removed by the collector, False otherwise.

OnIdle(deltaTime)[source]

Event method that is called periodically. The frequency of the calls depends on the implementation of the game console, but 20 milliseconds are recommended.

It can be used to perform time-based actions such as the movement of the opponents.

It can not be guaranteed that the frequency of the calls will be met exactly. To be independent of the frequency, the elapsed time since the last call is passed as a parameter.

Parameters:deltaTime (float) – Time that has elapsed since the last call.
OnInit(settings)[source]

This method is called when the game is loaded in the game console. Variables can be initialized and settings can be set.

Parameters:settings (mtx.Settings) – The settings object for this game in which all game relevant settings can be set.
OnLevelStart(level, reset)[source]

Event method, which is called upon each start or reset of a level.

It can be used to get the number of different objects in the level (e.g. the number of items that need to be collected) or to get a particular object (e.g. the player).

Parameters:
  • level (mtx.Level) – The level object to get access to the objects.
  • reset (bool) – True, if the start was caused by a reset, False otherwise.
OnPlayerJumpRequest(number, direction)[source]
OnPlayerMoveRequest(number, direction)[source]
OnRemove(removable, source)[source]

Event method, which is called when a removable object is to be removed. To veto, the method should return False.

Parameters:
Returns:

True if the removable object can be removed, False otherwise.

OnShutdown()[source]

This method is called when the game is finished and can be used to clean up things.

OnTriggerEnter(trigger, source)[source]

Event method, which is called when an object enters a cell with an event object.

Parameters:
OnTriggerLeave(trigger, source)[source]

Event method, which is called when an object leaves a cell with an event object.

Parameters:
OnUndo()[source]