-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscenery.py
108 lines (83 loc) · 2.78 KB
/
scenery.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
from typing import List, Dict
class Scenery:
probability = 0
role = "scenery"
type = "scenery"
biome = "any"
def get_actions(self, user: str) -> List[Dict[str, str]]:
return []
def to_dict(self) -> Dict[str, any]:
return {
"role": self.role,
"type": self.type,
"biome": self.biome
}
class Forest(Scenery):
biome = "forest"
type = "forest"
def get_actions(self, user: str) -> List[Dict[str, str]]:
return [
{"name": "chop", "action": "/chop?amount=1"},
{"name": "chop 10", "action": "/chop?amount=10"},
{"name": "conquer", "action": f"/conquer?target={self.type}"},
]
class Pond(Scenery):
biome = "pond"
type = "pond"
def get_actions(self, user: str) -> List[Dict[str, str]]:
return [
{"name": "fish", "action": "/fish"},
{"name": "conquer", "action": f"/conquer?target={self.type}"},
]
class Cavern(Scenery):
biome = "cavern"
type = "cavern"
def get_actions(self, user: str) -> List[Dict[str, str]]:
return []
class Graveyard(Scenery):
biome = "graveyard"
type = "graveyard"
def get_actions(self, user: str) -> List[Dict[str, str]]:
return []
class Desert(Scenery):
biome = "desert"
type = "desert"
def get_actions(self, user: str) -> List[Dict[str, str]]:
return []
class Gnomes(Scenery):
biome = "gnomes"
type = "gnomes"
def get_actions(self, user: str) -> List[Dict[str, str]]:
return []
class Mountain(Scenery):
biome = "mountain"
type = "mountain"
def get_actions(self, user: str) -> List[Dict[str, str]]:
return [
{"name": "mine", "action": "/mine?amount=1"},
{"name": "mine 10", "action": "/mine?amount=10"},
{"name": "conquer", "action": f"/conquer?target={self.type}"},
]
class Rock(Scenery):
biome = "rock"
type = "rock"
def get_all_scenery_subclasses():
all_subclasses = set()
classes_to_check = list(Scenery.__subclasses__())
while classes_to_check:
subclass = classes_to_check.pop()
if subclass not in all_subclasses:
all_subclasses.add(subclass)
classes_to_check.extend(subclass.__subclasses__())
return all_subclasses
# The rest of the code remains the same
scenery_types = {}
for cls in get_all_scenery_subclasses():
if hasattr(cls, 'type'):
scenery_types[cls.type] = cls
else:
print(f"Warning: {cls.__name__} does not have a 'type' attribute.")
# Optionally, you can print out the collected scenery types for verification
print("Collected scenery types:")
for scenery_type, scenery_class in scenery_types.items():
print(f"{scenery_type}: {scenery_class.__name__}")