This is python state pattern implementation for games or other things
- Clone repository
https://github.com/GitRenhl/State-Machine.git
- Copy
state
folder to your project directory - Import and code:
- Done
import state as StateManagment
class Game:
def __init__(self):
self.states = ("state_1", "state_2")
state_dict = {
self.states[0]: StateManagment.ExampleState1,
self.states[1]: StateManagment.ExampleState2
}
self.game_state = StateManagment.StateMachine(self, state_dict)
self.game_state.change('state_1')
def update(self):
self.game_state.update()