Gamecontrol SDK
The Gamecontrol is the center of the game. You can think of it like a referee. The Gamecontrol controls the game loop and decides which player won. In order to achieve this, the module provides a Game
class.
The Game
class provides events depending on the game state as well as a method to change it.
Class structure
Create a game
To create a new game write a class which inherits from Game
.
class MyGame(Game):
Now the methods:
on_pregame()
-> start Stateon_start()
-> run Stateon_end()
-> end Stateon_exit()
-> programm exiton_score()
-> score
can be overridden with custom code. They will be executed on their coresponding event. To access the score of a player the players
variable can be used.
class MyGame(Game):
async def on_score(seat: int):
for seat, score in self.players.score.items():
print(f"Player {seat} has {score} Points")
Most states of the game loop are changed automatically depending on the different controllers and other devices. The exception is the switch from run to end. This must be changed by you.
class MyGame(Game):
async def on_score(seat: int):
for seat, score in self.players.score.items():
print(f"Player {seat} has {score} Points")
# find winner
if score >= self.max_score:
print(f"Player {seat} wins!!!")
await self.set_game_state(GameState.END)
To start the game you have to execute MyGame.run()
.
if __name__ == "__main__"
game = MyGame()
game.run('path/to/config.toml')
Note
Don't forget creating a config file according to the specifications