Repository navigation
Expand file tree
/
Copy pathcoins.py
More file actions
66 lines (56 loc) · 1.94 KB
/
Copy pathcoins.py
File metadata and controls
66 lines (56 loc) · 1.94 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
'''Functions related to coins'''
from base import Point, Dimension, IDENTIFIER
COINS = {}
USED_COINS = []
COINDICT = {}
totalcoin = 0
class Coins:
''' Coins from Mario World'''
def __init__(self, point, board):
self.point = point
self.shape = [[IDENTIFIER['coin']]]
self.dimensions = Dimension(1, 1)
self.board = board
self.pre = []
self.id = totalcoin
self.store_coin(self.point)
self.draw()
def store_coin(self, point):
COINS[totalcoin] = self
if point.y in COINDICT.keys():
tmpDict = COINDICT[point.y]
else:
tmpDict = {}
tmpDict[point.x] = totalcoin
COINDICT[point.y] = tmpDict
def draw(self):
'''Function to render coin on board'''
self.pre = self.board.current(self.point, self.shape, self.dimensions)
self.board.update(self.point, self.shape, self.dimensions)
def check(self):
'''Logic to check presence of coin'''
self.board.status.add_coin()
self.removeCoin()
def restore(self):
'''Function to restore coin after enemy'''
ch = self.board.matrix[self.point.x][self.point.y]
if ch != IDENTIFIER['coin']:
return
else:
self.board.update(self.point,self.pre,self.dimensions)
USED_COINS.remove(self)
def removeCoin(self):
'''Function to remove coin'''
self.board.update(self.point,self.pre,self.dimensions)
USED_COINS.append(self)
del COINS[self.id]
COINDICT[self.point.y].pop(self.point.x)
if len(COINDICT[self.point.y]) == 0:
del COINDICT[self.point.y]
def coin_row(point, dimensions, board):
'''Function to generate a row of coins'''
for i in range(dimensions.length):
for j in range(dimensions.breadth):
Coins(Point(point.x + i,point.y + j),board)
global totalcoin
totalcoin += 1