-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbomberman.py
142 lines (119 loc) · 5.41 KB
/
bomberman.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
130
131
132
133
134
135
136
137
138
139
140
141
142
'''The Bomberman class
The Bomberman class has all the
variables and functionality of
Bomberman, this includes the generation,
movement and bomb planting.
This inherits Enemy and Bomb.'''
import signal
from enemy import Enemy
from board import Board
from getch import _getChUnix as getChar
from check import checkboard
from alarmexception import AlarmException
from bomb import Bomb
from manage import Manage
class Bomberman(Enemy, Bomb):
'''main bomberman class'''
# Coordinates of Bomberman
bombera = 0
bomberb = 0
# Function for the gerneration of Bomberman
def generatebomberman(self):
'''generates bomberman'''
for j in range(0, 4):
Board.board[2][4 + j] = 'B'
Board.board[3][4 + j] = 'B'
# Function for the motion of bomberman as per user input
def movebomberman(self):
''' moves bomberman'''
def alarmhandler(signum, frame):
''' input method '''
raise AlarmException
def user_input(timeout=0.1):
''' input method '''
signal.signal(signal.SIGALRM, alarmhandler)
signal.setitimer(signal.ITIMER_REAL, timeout)
try:
text = getChar()()
signal.alarm(0)
return text
except AlarmException:
pass
signal.signal(signal.SIGALRM, signal.SIG_IGN)
return ''
char = user_input()
# Pressing 'i' is a cheat code, that adds extra life.
if char == 'i':
Manage.lives += 1
# Press 'q' for quit.
if char == 'q':
quit()
# Press 'w' for up.
if char == 'w' and checkboard(self, Bomberman.bombera,
Bomberman.bomberb - 1) == 'empty':
if checkboard(self, Bomberman.bombera,
Bomberman.bomberb) != 'bomb':
for j in range(0, 4):
Board.board[(Bomberman.bomberb + 1) *
2][(Bomberman.bombera + 1) * 4 + j] = ' '
Board.board[(Bomberman.bomberb + 1) * 2 +
1][(Bomberman.bombera + 1) * 4 + j] = ' '
Bomberman.bomberb = Bomberman.bomberb - 1
for j in range(0, 4):
Board.board[(Bomberman.bomberb + 1) *
2][(Bomberman.bombera + 1) * 4 + j] = 'B'
Board.board[(Bomberman.bomberb + 1) * 2 +
1][(Bomberman.bombera + 1) * 4 + j] = 'B'
# Press 's' for down.
if char == 's' and checkboard(self, Bomberman.bombera,
Bomberman.bomberb + 1) == 'empty':
if checkboard(self, Bomberman.bombera,
Bomberman.bomberb) != 'bomb':
for j in range(0, 4):
Board.board[(Bomberman.bomberb + 1) *
2][(Bomberman.bombera + 1) * 4 + j] = ' '
Board.board[(Bomberman.bomberb + 1) * 2 +
1][(Bomberman.bombera + 1) * 4 + j] = ' '
Bomberman.bomberb = Bomberman.bomberb + 1
for j in range(0, 4):
Board.board[(Bomberman.bomberb + 1) *
2][(Bomberman.bombera + 1) * 4 + j] = 'B'
Board.board[(Bomberman.bomberb + 1) * 2 +
1][(Bomberman.bombera + 1) * 4 + j] = 'B'
# Press 'a' for left.
if char == 'a' and checkboard(self,
Bomberman.bombera - 1,
Bomberman.bomberb) == 'empty':
if checkboard(self, Bomberman.bombera,
Bomberman.bomberb) != 'bomb':
for j in range(0, 4):
Board.board[(Bomberman.bomberb + 1) *
2][(Bomberman.bombera + 1) * 4 + j] = ' '
Board.board[(Bomberman.bomberb + 1) * 2 +
1][(Bomberman.bombera + 1) * 4 + j] = ' '
Bomberman.bombera = Bomberman.bombera - 1
for j in range(0, 4):
Board.board[(Bomberman.bomberb + 1) *
2][(Bomberman.bombera + 1) * 4 + j] = 'B'
Board.board[(Bomberman.bomberb + 1) * 2 +
1][(Bomberman.bombera + 1) * 4 + j] = 'B'
# Press 'd' for right.
if char == 'd' and checkboard(self,
Bomberman.bombera + 1,
Bomberman.bomberb) == 'empty':
if checkboard(self, Bomberman.bombera,
Bomberman.bomberb) != 'bomb':
for j in range(0, 4):
Board.board[(Bomberman.bomberb + 1) *
2][(Bomberman.bombera + 1) * 4 + j] = ' '
Board.board[(Bomberman.bomberb + 1) * 2 +
1][(Bomberman.bombera + 1) * 4 + j] = ' '
Bomberman.bombera = Bomberman.bombera + 1
for j in range(0, 4):
Board.board[(Bomberman.bomberb + 1) *
2][(Bomberman.bombera + 1) * 4 + j] = 'B'
Board.board[(Bomberman.bomberb + 1) * 2 +
1][(Bomberman.bombera + 1) * 4 + j] = 'B'
# Press 'b' to plant a bomb.
if char == 'b':
self.generatebomb(Bomberman.bombera, Bomberman.bomberb)