Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class GameState:
- def __init__(self):
- self.state = {
- 'player': {'name': 'Player1', 'health': 100, 'inventory': []},
- 'level': {'current': 1, 'max': 10},
- 'enemies': [{'name': 'Goblin', 'health': 30}, {'name': 'Troll', 'health': 50}],
- }
- def get_player_info(self):
- return self.state['player']
- def set_player_health(self, health):
- self.state['player']['health'] = health
- def get_enemy_info(self, index):
- return self.state['enemies'][index]
- def add_item_to_inventory(self, item):
- self.state['player']['inventory'].append(item)
- # Example usage
- game_state = GameState()
- print(game_state.get_player_info())
- game_state.set_player_health(80)
- game_state.add_item_to_inventory('Sword')
Advertisement
Add Comment
Please, Sign In to add comment