-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAbstract_factory.py
143 lines (99 loc) · 3.86 KB
/
Abstract_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
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import random
class AbstractLevel:
@classmethod
def get_map(Class):
return Class.Map()
@classmethod
def get_objects(Class):
return Class.Objects()
class EasyLevel(AbstractLevel):
class EasyMap:
def __init__(self):
self._map = [[0 for j in range(5)] for i in range(5)]
for i in range(5):
for j in range(5):
if i == 0 or j == 0 or i == 4 or j == 4:
self._map[j][i] = -1
else:
self._map[j][i] = random.randint(0, 2)
def get_map(self):
return self._map
class EasyObjects:
def __init__(self):
self.objects = [('next_lvl', (2, 2))]
def get_objects(self, map_obj):
for obj_name in ['rat']:
coord = (random.randint(1, 3), random.randint(1, 3))
intersect = True
while intersect:
intersect = False
for obj in self.objects:
if coord == obj[1]:
intersect = True
coord = (random.randint(1, 3), random.randint(1, 3))
self.objects.append((obj_name, coord))
return self.objects
Map = EasyMap
Objects = EasyObjects
class MediumLevel(AbstractLevel):
class MediumMap:
def __init__(self):
self._map = [[0 for j in range(8)] for i in range(8)]
for i in range(8):
for j in range(8):
if i == 0 or j == 0 or i == 7 or j == 7:
self._map[j][i] = -1
else:
self._map[j][i] = random.randint(0, 2)
def get_map(self):
return self._map
class MediumObjects:
def __init__(self):
self.objects = [('next_lvl', (4, 4))]
def get_objects(self, map_obj):
for obj_name in ['rat', 'snake']:
coord = (random.randint(1, 6), random.randint(1, 6))
intersect = True
while intersect:
intersect = False
for obj in self.objects:
if coord == obj[1]:
intersect = True
coord = (random.randint(1, 6), random.randint(1, 6))
self.objects.append((obj_name, coord))
return self.objects
Map = MediumMap
Objects = MediumObjects
class HardLevel(AbstractLevel):
class HardMap:
def __init__(self):
self._map = [[0 for j in range(10)] for i in range(10)]
for i in range(10):
for j in range(10):
if i == 0 or j == 0 or i == 9 or j == 9:
self._map[j][i] = -1
else:
self._map[j][i] = random.randint(-1, 8)
def get_map(self):
return self._map
class HardObjects:
def __init__(self):
self.objects = [('next_lvl', (5, 5))]
def get_objects(self, map_obj):
for obj_name in ['rat', 'snake']:
coord = (random.randint(1, 8), random.randint(1, 8))
intersect = True
while intersect:
intersect = False
if map_obj[coord[0]][coord[1]] == -1:
intersect = True
coord = (random.randint(1, 8), random.randint(1, 8))
continue
for obj in self.objects:
if coord == obj[1]:
intersect = True
coord = (random.randint(1, 8), random.randint(1, 8))
self.objects.append((obj_name, coord))
return self.objects
Map = HardMap
Objects = HardObjects