-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfactory.py
72 lines (62 loc) · 2.1 KB
/
factory.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
# factory.py
from item import *
from enemy import *
from location import *
from config import *
import random
"""Contains the factory classes for creating items, enemies, and locations in a game."""
class ItemFactory:
@staticmethod
def create_item(item_type: str, location: Location) -> Item:
if item_type == RANDOM_ITEM:
item_type = random.choice(location.item_types)
if item_type == HEALTH_POTION:
return HealthPotion()
elif item_type == CLOAK:
return Cloak()
elif item_type == GLOVES:
return Gloves()
elif item_type == DAGGER:
return Dagger()
elif item_type == LOVE_STONE:
return LoveStone()
elif item_type == WOODEN_SHIELD:
return WoodenShield()
elif item_type == BLOOD_POTION:
return BloodPotion()
elif item_type == THE_WATCHING_EAGLE:
return TheWatchingEagle()
elif item_type == SACRED_HEART:
return SacredHeart()
else:
raise ValueError(UNKNOWN_ITEM)
class EnemyFactory:
@staticmethod
def create_enemy(enemy_type: str, location: Location) -> Enemy:
if enemy_type == RANDOM_ENEMY:
enemy_type = random.choice(location.enemy_types)
if enemy_type == GOBLIN:
return Goblin()
elif enemy_type == ORC:
return Orc()
elif enemy_type == RED_EYED_OWL:
return RedEyedOwl()
elif enemy_type == BLOODY_WORM:
return BloodyWorm()
elif enemy_type == THE_GREAT_MONSTER:
return TheGreatMonster()
else:
raise ValueError(enemy_type + ' : ' + UNKNOWN_ENEMY)
class LocationFactory:
@staticmethod
def create_location(location_type: str) -> Location:
if location_type == VILLAGE:
return Village()
elif location_type == FOREST:
return Forest()
elif location_type == MOUNTAIN:
return Mountain()
elif location_type == CASTLE:
return Castle()
else:
raise ValueError(UNKNOWN_LOCATION)