-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.py
133 lines (116 loc) · 3.32 KB
/
game.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
from __future__ import print_function
import signal
import copy
import sys
import time
import os
from random import randint
from walls import *
from person import *
from bomberman import *
from bomb import *
from bricks import *
from board import *
from enemy import *
from alarmexception import *
from getchunix import *
from time import time
getch = GetchUnix()
BoardArray = [[' ' for x in range(84)] for y in range(42)]
CheckArray = [[0 for x in range(84)] for y in range(42)]
pointer = []
def alarmHandler(signum, frame):
raise AlarmException
def input_to(timeout=1):
signal.signal(signal.SIGALRM, alarmHandler)
signal.alarm(timeout)
try:
text = getch()
signal.alarm(0)
return text
except AlarmException:
pass
# print("\n Prompt timeout. Continuing...")
signal.signal(signal.SIGALRM, signal.SIG_IGN)
return ''
intialX = 2
initialY = 4
bombPosition = [0 for i in range(4)]
Board = WallStructure()
b = Board.makeWall(BoardArray)
enemies = Enemy()
enemies.generateEnemy(BoardArray, pointer)
caller = bomberman()
BOMB = Bomb()
caller.makeBomber(intialX, initialY, CheckArray)
obs = Bricks()
obs.makeBricks(CheckArray, BoardArray)
printer = BoardMaker()
print("Game Controls")
print("w -> move up")
print("s -> move down")
print("a -> move left")
print("d -> move right")
print("b -> plant bomb")
print("press 'q' to quit!")
print()
printer.printMatrix(BoardArray, CheckArray)
p = bomberman()
save = time()
life = 3
while True:
curr = time()
if (curr - save) >= 1:
enemies.move(pointer, BoardArray)
save = curr
move = input_to()
if move == 's':
if p.moveDown(intialX, initialY, CheckArray, BoardArray) == 1:
intialX = intialX + 2
elif move == 'w':
if p.moveUp(intialX, initialY, CheckArray, BoardArray) == 1:
intialX = intialX - 2
elif move == 'd':
if p.moveRight(intialX, initialY, CheckArray, BoardArray) == 1:
initialY = initialY + 4
elif move == 'a':
if p.moveLeft(intialX, initialY, CheckArray, BoardArray) == 1:
initialY = initialY - 4
elif move == 'b' and bombPosition[2] == 0:
bombPosition[0] = intialX
bombPosition[1] = initialY
bombPosition[2] = 4
BOMB.makeBomb(bombPosition[0], bombPosition[1], BoardArray)
# os.system("tput reset")
elif move == 'q':
break
if bombPosition[0] != 0:
# enemies.destroy(bombPosition,pointer,BoardArray)
if p.destroySelf(bombPosition, BoardArray, CheckArray):
life = life - 1
initialY = 4
intialX = 2
BOMB.bombExplode(bombPosition, BoardArray, pointer)
if enemies.destroyBomber(pointer, CheckArray, BoardArray):
life = life - 1
initialY = 4
intialX = 2
os.system("tput reset")
print("Game Controls")
print("w -> move up")
print("s -> move down")
print("a -> move left")
print("d -> move right")
print("b -> plant bomb")
print("press 'q' to quit!")
print()
printer.printMatrix(BoardArray, CheckArray)
BOMB.patternRemover(BoardArray, bombPosition[0], bombPosition[1])
print("Lives " + str(life))
print("Score " + str(bombPosition[3]))
if(len(pointer) == 0):
print("You win")
break
if life == 0:
print("you Lose")
break