-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
58 lines (53 loc) · 1.76 KB
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
from pydantic import BaseModel, Field
from typing import Dict, List, Optional, Union
class Enemy(BaseModel):
name: str
hp: int
max_hp: int
attack: int
font_awesome_icon: str
class Item(BaseModel):
id: str
name: str
type: str # 'weapon', 'armor', 'consumable'
effect: Dict[str, int]
is_equipped: bool = False
description: str
class Equipment(BaseModel):
weapon: Optional[Item] = None
armor: Optional[Item] = None
class GameState(BaseModel):
cell_types: List[List[dict]] = []
map_width: int
map_height: int
player: dict = {}
player_pos: tuple = (0, 0)
player_pos_prev: tuple = (0, 0)
player_hp: int
player_max_hp: int
player_attack: int
player_defense: int
player_xp: int = 0
inventory: List[Item] = []
equipment: Equipment = Field(default_factory=Equipment)
explored: List[List[bool]] = Field(default_factory=list) # Changed this line
in_combat: bool = False
current_enemy: Optional[Enemy] = None
game_over: bool = False
temporary_effects: Dict[str, Dict[str, Union[int, int]]] = {}
game_title: str = "Unknown Game"
@classmethod
def from_config(cls, config):
instance = cls(
map_width=config['map_size']['width'],
map_height=config['map_size']['height'],
player_hp=config['player']['base_hp'],
player_max_hp=config['player']['max_hp'],
player_attack=config['player']['base_attack'],
player_defense=config['player']['base_defense'],
player_xp=0,
)
# Initialize explored array with proper dimensions
instance.explored = [[False for _ in range(instance.map_width)]
for _ in range(instance.map_height)]
return instance