-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoin.py
69 lines (53 loc) · 1.92 KB
/
coin.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
import random
from base import DIMENSION, COLOR
from colorama import Fore, Style
class Coins:
def __init__(self, xcoord, ycoord, dim):
self.__xcoord = xcoord
self.__ycoord = ycoord
self.__dim = dim
self.__coins_left = self.__dim['x'] * self.__dim['y']
self.__coin_shape = COLOR['coin'] + '$' + Style.RESET_ALL
self.__shape = [[self.__coin_shape for _ in range(self.__dim['y'])] for _ in range(self.__dim['x'])]
def place_coins(self, grid):
for i in range(self.__dim['x']):
for j in range(self.__dim['y']):
grid[self.__xcoord+i][self.__ycoord+j] = self.__shape[i][j]
def remove_coin(self, coord):
self.__shape[coord[0]][coord[1]] = ' '
self.__coins_left -= 1
def get_xcoord(self):
return self.__xcoord
def get_ycoord(self):
return self.__ycoord
def get_dim(self):
return self.__dim
def get_coins_left(self):
return self.__coins_left
def get_coin_shape(self):
return self.__coin_shape
def get_shape(self):
return self.__shape
def create_coins():
x = DIMENSION['sky_height'] + random.randint(1, 3)
y = random.randint(50, 100)
obj_list = []
while y < DIMENSION['width'] - DIMENSION['frame_width']:
dim = {}
dim['x'] = random.randint(1, 5)
dim['y'] = random.randint(1, 5)
coins = Coins(x, y, dim)
obj_list.append(coins)
x = DIMENSION['sky_height'] + random.randint(2, 10)
y += random.randint(30, 50)
return obj_list
def place_coins(obj_list, grid, xdis):
for coins in obj_list:
if coins.get_ycoord() > xdis + DIMENSION['frame_width']:
break
elif coins.get_ycoord() < xdis - coins.get_dim()['y']:
obj_list.remove(coins)
elif coins.get_coins_left() == 0:
obj_list.remove(coins)
else:
coins.place_coins(grid)