-
Notifications
You must be signed in to change notification settings - Fork 0
/
player.py
131 lines (105 loc) · 3.07 KB
/
player.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
# class Person
# to make to have inheritence
import configs
import signal
import getch
import alarm
class Player:
def __init__(self):
import configs
self.__lives = 5
self.__y = configs.HEIGHT-2 #bottom
self.__x = 5 #left
self.__score = 0
self.__shield = 0
self.__inc=1
self.__time = 0
def getx(self):
return self.__x
def gety(self):
return self.__y
def setx(self,a):
self.__x=a
def loselife(self,game):
import time
self.__lives-=1
print("\033[2J")
# print("\033[0;0H")
print("\t\t\t\t\t<<\033[31m DEAD \033[0m>>\n\t\t\t\t<< PRESS ANY KEY TO START >>")
time.sleep(1)
if getch._getChUnix()() is not '': #press key to start
self.__x = game.getx() + 5
pass
print("\033[2J")
def getscore(self):
return self.__score
def getlives(self):
return self.__lives
def valid(self,move,game):
#if we can move u,d,l or r;
f=0
x = game.getx()
if x%3==0 and self.__y <= configs.HEIGHT-2:
self.__time+=1
if move=='w' and self.__y>3:
self.__y-=3
# if x%3:
# self.__inc+=1
return 1
if move=='a':
if self.__x>x:
self.__x-=2
else:
self.loselife(game)
return 1
if move=='d':
if self.__x < x+configs.WIDTH-2:
self.__x+=2
elif self.__x==x+configs.WIDTH-2:
self.__x-=3
return 1
# if move=
if move=='e':
game.shoot(self.__y,self.__x)
# return 1
if self.__y<configs.HEIGHT-2:
# self.__y+=self.__time
self.__y+=1
if self.__y >= configs.HEIGHT-1:
self.__y = configs.HEIGHT-2
self.__inc=1
self.__time=1
return f
def coincollected(self):
self.scoreup(100)
pass
def beamkilled(self):
self.scoreup(400)
def enemykilled(self):
self.scoreup(5000)
def scoreup(self,amount):
self.__score+=amount
def move(self,game):
def alarmhandler(signum,frame):
raise alarm.AlarmException
def user_input(timeout=0.1):
'''input method'''
signal.signal(signal.SIGALRM, alarmhandler )
signal.setitimer(signal.ITIMER_REAL, timeout)
try:
move = getch._getChUnix()()
signal.alarm(0)
return move
except alarm.AlarmException:
pass
signal.signal(signal.SIGALRM, signal.SIG_IGN)
return ''
move = user_input()
if move=='q':
quit()
if(self.valid(move,game)):
pass
def shielded(self):
return self.__shield
def setshield(self,a):
self.__shield = a