-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfiring.py
106 lines (90 loc) · 3.21 KB
/
firing.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
from colorama import Fore, Style
from base import DIMENSION
import time
class Firing:
def __init__(self, xcoord, ycoord, color, shape, dir, inc):
self._xcoord = xcoord
self._ycoord = ycoord
self._shape = color + shape + Style.RESET_ALL
self._dir = dir
self._inc = inc
def die(self, grid):
grid[self._xcoord][self._ycoord] = ' '
def move(self, grid, xdis):
grid[self._xcoord][self._ycoord] = ' '
if self._dir == True:
self._ycoord += self._inc
if self._ycoord >= xdis + DIMENSION['frame_width'] or self._ycoord >= DIMENSION['width']:
self._ycoord -= self._inc
self.die(grid)
return 1
else:
self._ycoord -= self._inc
if self._ycoord < xdis:
self._ycoord += self._inc
self.die(grid)
return 1
grid[self._xcoord][self._ycoord] = self._shape
def get_xcoord(self):
return self._xcoord
def get_ycoord(self):
return self._ycoord
def get_dir(self):
return self._dir
def set_inc(self, inc):
self._inc = inc
def get_inc(self):
return self._inc
class Bullet(Firing):
pass
class Iceball(Firing):
def __init__(self, xcoord, ycoord, color, shape, dis, inc):
Firing.__init__(self, xcoord, ycoord, color, shape, True, inc)
self.__mando_dis = dis
self.__moved = 0
self.__cycle_time = 1
self.__cycle_count = 0
self.__last_count = 0
self.__iter = 0
def move(self, grid, xdis):
if self._xcoord >= DIMENSION['sky_height']:
grid[self._xcoord][self._ycoord] = ' '
if self._dir == True:
self.__cycle_count += 1
self.__last_count += 1
if self.__cycle_count == self.__cycle_time:
self._xcoord -= 1
self.__cycle_time += 1
self.__cycle_count = 0
self.__last_count = 0
else:
self.__cycle_count += 1
if self.__iter == 1:
if self.__cycle_count >= self.__last_count:
self._xcoord += 1
self.__cycle_time -= 1
self.__cycle_count = 0
self.__iter += 1
if self.__cycle_time == 0:
self.__cycle_time = 1
else:
if self.__cycle_count == self.__cycle_time:
self._xcoord += 1
self.__cycle_time -= 1
self.__cycle_count = 0
if self.__cycle_time == 0:
self.__cycle_time = 1
self._ycoord -= 1
self.__moved += 1
if self.__moved >= self.__mando_dis // 2:
self._dir = False
if self.__iter == 0:
self.__cycle_count = 0
self.__iter += 1
if self._xcoord >= DIMENSION['length'] - DIMENSION['ground_height']:
return True
elif self._ycoord < xdis:
return True
elif self._xcoord >= DIMENSION['sky_height']:
grid[self._xcoord][self._ycoord] = self._shape
return False