xFazz

example game state

Dec 26th, 2024
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. class GameState:
  2. def __init__(self):
  3. self.state = {
  4. 'player': {'name': 'Player1', 'health': 100, 'inventory': []},
  5. 'level': {'current': 1, 'max': 10},
  6. 'enemies': [{'name': 'Goblin', 'health': 30}, {'name': 'Troll', 'health': 50}],
  7. }
  8.  
  9. def get_player_info(self):
  10. return self.state['player']
  11.  
  12. def set_player_health(self, health):
  13. self.state['player']['health'] = health
  14.  
  15. def get_enemy_info(self, index):
  16. return self.state['enemies'][index]
  17.  
  18. def add_item_to_inventory(self, item):
  19. self.state['player']['inventory'].append(item)
  20.  
  21. # Example usage
  22. game_state = GameState()
  23. print(game_state.get_player_info())
  24. game_state.set_player_health(80)
  25. game_state.add_item_to_inventory('Sword')
  26.  
Advertisement
Add Comment
Please, Sign In to add comment