game.core.commands.command

core/commands/command.py

Implements the notorius game programming command pattern.

Defines the abstract Command interface and concrete game commands. (Fly, Map, QuestLog, Refresh, Exit). Includes a registry of commands and utilities for matching user input and executing commands.

Functions

get_command(input_text)

Get a Command object matching the input_text.

register_command(cls)

Decorator to register a Command class in the COMMAND registry.

Classes

Command()

Abstract base class for game commands.

ExitCommand()

FlyCommand()

Command to fly to a chosen airport.

MapCommand()

Command to view the map.

QuestLogCommand()

Command to view the quest log.

RefreshCommand()

Command to refresh the game status.

class game.core.commands.command.Command

Bases: ABC

Abstract base class for game commands.

_abc_impl = <_abc._abc_data object>
aliases: tuple[str, ...] = ()
abstract execute(game, args: str = '') CommandResult

Execute the game command.

Parameters:
  • game (Game) – The game instance.

  • args (str) – Optional arguments (e.g. 1,2,3..)

Returns:

Result including messages and result status (ok | error).

Return type:

CommandResult

matches(text: str) bool

Check if text matches the command name or any aliases.

name: str
class game.core.commands.command.ExitCommand

Bases: Command

_abc_impl = <_abc._abc_data object>
aliases: tuple[str, ...] = ('q', 'quit')
execute(game, args='') CommandResult

Execute the game command.

Parameters:
  • game (Game) – The game instance.

  • args (str) – Optional arguments (e.g. 1,2,3..)

Returns:

Result including messages and result status (ok | error).

Return type:

CommandResult

name: str = 'exit'
class game.core.commands.command.FlyCommand

Bases: Command

Command to fly to a chosen airport.

_abc_impl = <_abc._abc_data object>
execute(game, args='') CommandResult

Execute flying to the chosen airport.

matches(text: str) bool

Match digits as valid input.

name: str = 'fly'
class game.core.commands.command.MapCommand

Bases: Command

Command to view the map.

_abc_impl = <_abc._abc_data object>
aliases: tuple[str, ...] = ('m',)
execute(game, args='') CommandResult

Render the map including airports, target and player.

name: str = 'map'
class game.core.commands.command.QuestLogCommand

Bases: Command

Command to view the quest log.

_abc_impl = <_abc._abc_data object>
aliases: tuple[str, ...] = ('quest', 'questlog')
execute(game, args='') CommandResult

Display the quest log including active and completed quests.

name: str = 'quests'
class game.core.commands.command.RefreshCommand

Bases: Command

Command to refresh the game status.

_abc_impl = <_abc._abc_data object>
aliases: tuple[str, ...] = ('r', 'i')
execute(game, args='') CommandResult

Refresh the game status.

name: str = 'refresh'
game.core.commands.command.get_command(input_text: str) Command | None

Get a Command object matching the input_text.

Parameters:

input_text (str) – User input text.

Returns:

Matched Command instance or None.

Return type:

Optional[Command]

game.core.commands.command.register_command(cls: type[Command])

Decorator to register a Command class in the COMMAND registry.