-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
143 lines (118 loc) · 3.83 KB
/
main.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
143
from __future__ import print_function
import signal, copy, sys, time, os
from wall import *
from bomber import *
from person import *
from enemy import *
from getchunix import *
from bomb import *
from random import randint
from time import time
from termcolor import colored
from allfuncs import *
Level = 1
bmb = 0
boardx = 84
boardy = 42
board = [[' ' for x in range(boardx)] for y in range(boardy)]
bomber = Bomber(4, 2)
BombStatus = 0
numEnemies = 4
enemies = []
Score = 0
numBricks = 20
gameplay = allfuncs()
getch = GetchUnix()
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:
print()
signal.signal(signal.SIGALRM, signal.SIG_IGN)
return ''
def moveEnemies(board):
for i in range(numEnemies):
enemies[i].RemovePerson(board)
enemies[i].RandomMove(board)
enemies[i].InsertPerson(board)
CreateTime = time()
gameplay.MakeWall(board, numEnemies, numBricks, boardx, boardy, enemies)
gameplay.PrintGame(board, bomber, Score, Level)
while (1):
curr = time()
mv = input_to()
if (curr - CreateTime >= 0.5):
moveEnemies(board)
CreateTime = curr
if (BombStatus == 2 and curr - bmb.getRtime() >= 0.5):
Score = gameplay.checkBomber(board, bmb, bomber, Score)
bmb.Explosion(board, ' ')
BombStatus = 0
if (BombStatus == 1 and curr - bmb.getRtime() >= 0.5):
bmb.setRtime(curr)
bmb.setTime(bmb.getTime() - 1)
if (bmb.getTime() == 0):
bmb.RemoveBomb(board)
Score = gameplay.checkWall(board, bmb, Score)
bmb.Explosion(board, 'e')
BombStatus = 2
[enemies, numEnemies, Score] = gameplay.checkEnemy(
board, bmb, numEnemies, enemies, Score)
else:
bmb.InsertBomb(board)
if (mv == 'q'):
print(colored("You Quitted the Game", 'red'))
print(colored("Your Score: ", 'yellow'), Score)
sys.exit(0)
if (mv == 'd'):
bomber.RemovePerson(board)
bomber.moveRight(board)
if (mv == 'a'):
bomber.RemovePerson(board)
bomber.moveLeft(board)
if (mv == 's'):
bomber.RemovePerson(board)
bomber.moveDown(board)
if (mv == 'w'):
bomber.RemovePerson(board)
bomber.moveUp(board)
if (mv == 'b'):
if (BombStatus == 0):
[p, q] = bomber.getPosition()
bmb = Bomb(p, q)
bmb.InsertBomb(board)
BombStatus = 1
os.system("tput reset")
gameplay.PrintGame(board, bomber, Score, Level)
for enemy in enemies:
if (enemy.getPosition() == bomber.getPosition()):
bomber.setLives(bomber.getLives() - 1)
bomber.setPosition(4, 2)
if (bomber.getLives() == 0):
bomber.RemovePerson(board)
# PrintGame(board)
print(colored("Game Over", 'red'))
print(colored("Your Score:", 'yellow'), Score)
sys.exit(0)
# PrintGame(board)
if (numEnemies == 0 and Level == 1):
print(colored("Level 1 Complete", 'green'))
numEnemies, Level, numBricks = 5, 2, 25
gameplay.LevelUp(board, bomber, numEnemies, numBricks, boardx, boardy,
enemies)
elif (numEnemies == 0 and Level == 2):
print(colored("Level 2 Complete", 'green'))
numEnemies, Level, numBricks = 6, 3, 30
gameplay.LevelUp(board, bomber, numEnemies, numBricks, boardx, boardy,
enemies)
if (numEnemies == 0 and Level == 3):
print(colored("You Won", 'green'))
print(colored("Your Score is :", 'yellow'), Score)
sys.exit(0)
# PrintGame(board)