def movedown(self, board): """method docstring""" xcoordinate = self.x ycoordinate = self.y xcoordinate_list = [ xcoordinate, xcoordinate + 1, xcoordinate + 2, xcoordinate + 3 ] ycoordinate_list = [ycoordinate + 2, ycoordinate + 3] board = replace(xcoordinate_list, ycoordinate_list, ['E' * 4, 'E' * 4], board) ycoordinate_list = [ycoordinate, ycoordinate + 1] board = replace(xcoordinate_list, ycoordinate_list, [' ' * 4, ' ' * 4], board) self.y = ycoordinate + 2 return board
def addbricks(board): """as the name suggests,it adds 20 bricks to the board""" count = 0 while count < 20: brick1 = Bricks( randint(1, 19) * 4, randint(1, 19) * 2, ['/' * 4, '/' * 4]) flag = 0 xcoordinate = brick1.getx() ycoordinate = brick1.gety() xcoordinate_list = [ xcoordinate, xcoordinate + 1, xcoordinate + 2, xcoordinate + 3 ] ycoordinate_list = [ycoordinate, ycoordinate + 1] for i in xcoordinate_list: for j in ycoordinate_list: if board[j][i] != ' ': flag = 1 break if flag == 0: board = replace(xcoordinate_list, ycoordinate_list, brick1.getlist(), board) count += 1 else: continue return board
def moveleft(self, board): """method docstring""" xcoordinate = self.x ycoordinate = self.y xcoordinate_list = [ xcoordinate - 4, xcoordinate - 3, xcoordinate - 2, xcoordinate - 1 ] ycoordinate_list = [ycoordinate, ycoordinate + 1] board = replace(xcoordinate_list, ycoordinate_list, ['E' * 4, 'E' * 4], board) xcoordinate_list = [ xcoordinate, xcoordinate + 1, xcoordinate + 2, xcoordinate + 3 ] board = replace(xcoordinate_list, ycoordinate_list, [' ' * 4, ' ' * 4], board) self.x = xcoordinate - 4 return board
def moveright(self, board): """method docstring""" xcoordinate = self.x ycoordinate = self.y xcoordinate_list = [ xcoordinate + 4, xcoordinate + 5, xcoordinate + 6, xcoordinate + 7 ] ycoordinate_list = [ycoordinate, ycoordinate + 1] board = replace(xcoordinate_list, ycoordinate_list, ['E' * 4, 'E' * 4], board) xcoordinate_list = [ xcoordinate, xcoordinate + 1, xcoordinate + 2, xcoordinate + 3 ] board = replace(xcoordinate_list, ycoordinate_list, [' ' * 4, ' ' * 4], board) self.x = xcoordinate + 4 return board
def clearbomb(self, board, loc): """aftermath of explosion""" row_list = [] xcoordinate = self.x xcoordinate_list = [xcoordinate, xcoordinate + 1, xcoordinate + 2, xcoordinate + 3] ycoordinate = self.y ycoordinate_list = [ycoordinate, ycoordinate + 1] for i in range(loc[0], loc[2] + 1): row_list.append(i) column_list, new_list = [], [] for i in range(loc[1], loc[3] + 1): column_list.append(i) new_list.append(' ' * 4) board = replace(row_list, ycoordinate_list, [' ' * (loc[2] - loc[0] + 1), ' ' * (loc[2] - loc[0] + 1)], board) board = replace(xcoordinate_list, column_list, new_list, board) return board
def explode(self, board, loc, xbm, ybm): """after explosion""" row_list = [] xcoordinate = self.x xcoordinate_list = [xcoordinate, xcoordinate + 1, xcoordinate + 2, xcoordinate + 3] ycoordinate = self.y ycoordinate_list = [ycoordinate, ycoordinate + 1] for i in range(loc[0], loc[2] + 1): row_list.append(i) column_list, new_list = [], [] for i in range(loc[1], loc[3] + 1): column_list.append(i) new_list.append('^' * 4) this_round, life_gone = 0, 0 if board[ycoordinate][loc[0]] == '/': this_round += 20 if board[ycoordinate][loc[2] - 3] == '/': this_round += 20 if board[loc[1]][xcoordinate] == '/': this_round += 20 if board[loc[3] - 1][xcoordinate] == '/': this_round += 20 if board[ycoordinate][loc[0]] == 'E': this_round += 100 if board[ycoordinate][loc[2] - 3] == 'E': this_round += 100 if board[loc[1]][xcoordinate] == 'E': this_round += 100 if board[loc[3] - 1][xcoordinate] == 'E': this_round += 100 if(board[ycoordinate][loc[0]] == 'B' or board[ycoordinate][loc[2] - 3] == 'B' or board[loc[1]][xcoordinate] == 'B' or board[loc[3] - 1][xcoordinate] == 'B' or (xcoordinate == xbm and ycoordinate == ybm)): this_round = 0 life_gone = 1 board = replace(row_list, ycoordinate_list, ['^' * (loc[2] - loc[0] + 1), '^' * (loc[2] - loc[0] + 1)], board) board = replace(xcoordinate_list, column_list, new_list, board) return [this_round, life_gone, board]
def goup(self, board): """method docstring""" xcoordinate = self.x ycoordinate = self.y flag = 0 if ycoordinate > 3: my_var = ycoordinate ycoordinate -= 2 xcoordinate_list = [ xcoordinate, xcoordinate + 1, xcoordinate + 2, xcoordinate + 3 ] ycoordinate_list = [ycoordinate, ycoordinate + 1] flag = 0 for i in xcoordinate_list: for j in ycoordinate_list: if board[j][i] != ' ': flag = 1 break if flag == 1: break if flag == 0: oldlist = [] for i in range(my_var, my_var + 2): temp = '' for j in range(xcoordinate, xcoordinate + 4): temp += board[i][j] oldlist.append(temp) board = replace(xcoordinate_list, ycoordinate_list, self.l, board) if oldlist == ['[' + 'O' * 2 + ']', '[' + 'O' * 2 + ']']: board = replace([i for i in xcoordinate_list], [i + 2 for i in ycoordinate_list], oldlist, board) else: board = replace([i for i in xcoordinate_list], [i + 2 for i in ycoordinate_list], [' ' * 4, ' ' * 4], board) self.x = xcoordinate self.y = ycoordinate return board
def addenemy(board): """add enemy docstring""" count = 0 while count < 1: xcoordinate = randint(1, 19) * 4 ycoordinate = randint(1, 19) * 2 xcoordinate_list = [ xcoordinate, xcoordinate + 1, xcoordinate + 2, xcoordinate + 3 ] ycoordinate_list = [ycoordinate, ycoordinate + 1] flag = 0 for i in xcoordinate_list: for j in ycoordinate_list: if board[j][i] != ' ': flag = 1 break if flag == 0: new_enemy = Enemy(xcoordinate, ycoordinate, ['E' * 4, 'E' * 4]) board = replace(xcoordinate_list, ycoordinate_list, ['E' * 4, 'E' * 4], board) count += 1 else: continue return [board, new_enemy]
import getchar from BOMB import Bomb from addbricks import addbricks, NBOARD from enemy import addenemy GETCH = getchar.Getch() class AlarmException(Exception): """class docstring""" pass # place the Bomberman B = Bomberman(4, 2, ['B' * 4, 'B' * 4]) NBOARD = replace([4, 5, 6, 7], [2, 3], B.getlist(), NBOARD) SCORE, LIFES = 0, 5 # add enemies L = addenemy(NBOARD) NBOARD = L[0] FIRST = L[1] DEATH_1 = True L = addenemy(NBOARD) NBOARD = L[0] SECOND = L[1] DEATH_2 = True L = addenemy(NBOARD) NBOARD = L[0] THIRD = L[1] DEATH_3 = True # for colour printing