-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathfield.py
More file actions
91 lines (67 loc) · 2.55 KB
/
field.py
File metadata and controls
91 lines (67 loc) · 2.55 KB
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
import numpy as np
import random
class Field:
def __init__(self):
self.row_width = 12
self.col_height = 20
self.block_width = 10
self.block_height = 10
self.field = np.zeros((self.col_height, self.row_width), dtype=np.int32)
self.platform_width = 4
self.platform_needed = True
self.platform = self.generate_platform()
self.layers_per_platform = 6
self.platform_gap = self.layers_per_platform
self.total_width = self.block_width * self.row_width
self.total_height = self.block_height * self.col_height
pass # placeholder
def update(self): # main method/function
#put this all in an if statement of whether or not the player reached the 3rd to the top row?
self.field = np.delete(self.field, 19, 0)
if self.platform_gap == self.layers_per_platform:
self.field = np.insert(self.field, 0, self.generate_platform(), 0)
else:
if self.coin_random():
self.field = np.insert(self.field, 0, self.generate_coin(), 0)
else:
self.field = np.insert(self.field, 0, np.zeros(self.row_width), 0)
self.platform_gap-=1
if self.platform_gap == 0:
self.platform_gap = self.layers_per_platform
def coin_random(self):
gen_coin = random.randint(1,20)
if gen_coin == 20:
return True
return False
def generate_coin(self):
new_row = np.zeros(self.row_width)
coin = random.randint(2,10)
new_row[coin]=0
return new_row
def generate_platform(self):
platform = np.zeros(self.row_width)
platform_start = random.randrange(2, self.row_width-self.platform_width - 2)
for i in range(platform_start, platform_start + self.platform_width):
platform[i] = 1
return platform
def copy(self):
return self.field.copy()
def __str__(self):
return self.__repr__()
def __repr__(self):
return self.field.__repr__()
def color(self, n):
if np.equal(n, 0):
return (0, 0, 0)
if np.equal(n, 3):
return (255, 255, 255)
if np.equal(n, 4):
return (0, 255, 255)
return (255, 0, 0)
#at least i think this is red
if __name__ == "__main__":
print("This code will only be executed when this is the file being called, "
"like python/python3 field.py. Use this for testing")
field = Field()
field.update()
print(field.field)