def moveenemies(self): for i in range(0, self.Enemies): if self.mark[i] == 0: if self.aEnemy[i] < gameboard.st + 80: if checkboard(self, self.aEnemy[i] + self.vEnemy[i], 28) == 'empty' and self.aEnemy[ i] + self.vEnemy[i] < gameboard.st + 80: gameboard.board[28][self.aEnemy[i]] = ' ' self.aEnemy[i] = self.aEnemy[i] + self.vEnemy[i] elif checkboard(self, self.aEnemy[i] + self.vEnemy[i], 28) == 'mario': gameManager.changelives() gameboard.board[28][self.aEnemy[i]] = ' ' self.aEnemy[i] = self.aEnemy[i] + -5 * self.vEnemy[i] else: self.vEnemy[i] = self.vEnemy[i] * (-1)
def moveBridges: for i in range(0,Bridge.Bridges): if Bridges.mark[i] == 0: if checkboard(self,Bridge.aBridge[i] + Bridge.vBridge[i],28) == 'empty': Board.board[28][Bridge.aBridge[i]]=' ' Bridge.aBridge[i] = Bridge.aBridge[i] + Bridge.vBridge[i] else: Bridge.vBridge[i] = Bridge.vBridge[i]*(-1)
def move(self,a): # print (Mario.x) if self.mark ==0 : for i in range(21,29): gameboard.board[i][self.x+1]=' ' gameboard.board[21][self.x]=' ' gameboard.board[21][self.x+2]=' ' if self.x < a + 30 and self.x > a : if checkboard(self,self.x-1,28) =='mario' or checkboard(self,self.x-1,27) =='mario' or checkboard(self,self.x-1,26) =='mario' or checkboard(self,self.x-1,25) =='mario' or checkboard(self,self.x-1,24) =='mario'or checkboard(self,self.x-1,23) =='mario': self.x =self.x+5 gameManager.changelives() else: self.x = self.x-1 elif self.x > a - 30 and self.x < a : if checkboard(self,self.x+1,28) =='mario': self.x =self.x-5 gameManager.changelives() else: self.x = self.x +1
def movebullets(self,a): if self.mark == 0: for i in range (0,self.missilecnt): if self.missilemark[i] == 0: gameboard.board[27][self.missile[i]]=' ' if checkboard(self,self.missile[i]+self.missileV[i],27) == 'empty' : self.missile[i]=self.missile[i] + self.missileV[i] elif self.missile[i]+self.missileV[i] == a or self.missile[i]+self.missileV[i] == a+1: gameManager.changelives() self.missilemark[i] = 1 else: self.missilemark[i] = 1
def clearexplosion(self, alpha, beta): '''clears bomb explosion''' for j in range(0, 4): Board.board[(beta + 1) * 2][(alpha + 1) * 4 + j] = ' ' Board.board[(beta + 1) * 2 + 1][(alpha + 1) * 4 + j] = ' ' beta = beta - 1 if checkboard(self, alpha, beta) == 'explosion': for j in range(0, 4): Board.board[(beta + 1) * 2][(alpha + 1) * 4 + j] = ' ' Board.board[(beta + 1) * 2 + 1][(alpha + 1) * 4 + j] = ' ' alpha = alpha + 1 beta = beta + 1 if checkboard(self, alpha, beta) == 'explosion': for j in range(0, 4): Board.board[(beta + 1) * 2][(alpha + 1) * 4 + j] = ' ' Board.board[(beta + 1) * 2 + 1][(alpha + 1) * 4 + j] = ' ' alpha = alpha - 2 if checkboard(self, alpha, beta) == 'explosion': for j in range(0, 4): Board.board[(beta + 1) * 2][(alpha + 1) * 4 + j] = ' ' Board.board[(beta + 1) * 2 + 1][(alpha + 1) * 4 + j] = ' ' alpha = alpha + 1 beta = beta + 1 if checkboard(self, alpha, beta) == 'explosion': for j in range(0, 4): Board.board[(beta + 1) * 2][(alpha + 1) * 4 + j] = ' ' Board.board[(beta + 1) * 2 + 1][(alpha + 1) * 4 + j] = ' ' beta = beta - 1 self.removebomb(alpha, beta)
def move(self): def alarmhandler(signum, frame): 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 '' # if Mario.flag == 0: char = user_input() if char == 'i': gameManager.lives += 1 # Press 'q' for quit. if char == 'q': quit() # Press 'w' for up. if char == 'w' and checkboard2(self, self.x, self.y) == 'empty' and ( checkboard(self, self.x, self.y + 1) != 'empty' or checkboard(self, self.x + 1, self.y + 1) != 'empty'): if (self.x == 285 or self.x == 284) and self.y == 11: self.superpower = 1 gameboard.board[8][283] = 'S' gameboard.board[8][284] = 'P' for i in range(0, 4): for j in range(0, 2): gameboard.board[(self.y - 1) - 2 * i][self.x + j] = ' ' gameboard.board[self.y - 2 * i][self.x + j] = ' ' self.y = self.y - self.jump if char == 'w' and checkboard2(self, self.x, self.y) == 'tile': for i in range(0, 1): for j in range(0, 2): gameboard.board[(self.y - 1) - 2 * i][self.x + j] = ' ' gameboard.board[self.y - 2 * i][self.x + j] = ' ' self.y = self.y - 3 if char == 'w' and checkboard2(self, self.x, self.y) == 'coin': for i in range(0, 4): for j in range(0, 2): gameboard.board[(self.y - 1) - 2 * i][self.x + j] = ' ' gameboard.board[self.y - 2 * i][self.x + j] = ' ' gameManager.changescore('coin') self.y = self.y - 6 if char == 'a' and checkboard( self, self.x - 1, self.y) == 'empty' and checkboard( self, self.x - 1, self.y - 1) == 'empty': for j in range(0, 2): gameboard.board[(self.y - 1)][self.x + j] = ' ' gameboard.board[self.y][self.x + j] = ' ' self.x = self.x - 1 if char == 'd' and checkboard( self, self.x + 2, self.y) == 'empty' and checkboard( self, self.x + 2, self.y - 1) == 'empty': if self.x == gameboard.st + 40: gameboard.st = gameboard.st + 1 # Mario.a = gameboard.st + 40 for j in range(0, 2): gameboard.board[(self.y - 1)][self.x + j] = ' ' gameboard.board[self.y][self.x + j] = ' ' self.x = self.x + 1 #pit if self.y > 29: for j in range(0, 2): gameboard.board[(self.y - 1)][self.x + j] = ' ' gameboard.board[self.y][self.x + j] = ' ' gameManager.changelives() self.x = self.x - 3 self.y = 28 if checkboard(self, self.x, self.y + 1) == 'empty' and checkboard( self, self.x + 1, self.y + 1) == 'empty': for j in range(0, 2): gameboard.board[(self.y - 1)][self.x + j] = ' ' gameboard.board[self.y][self.x + j] = ' ' self.y = self.y + 1 if checkboard(self, self.x, self.y + 1) == 'spring' or checkboard( self, self.x + 1, self.y + 1) == 'spring': for j in range(0, 2): gameboard.board[(self.y - 1)][self.x + j] = ' ' gameboard.board[self.y][self.x + j] = ' ' self.y = self.y - 20 if checkboard(self, self.x, self.y + 1) == 'enemy' or checkboard( self, self.x + 1, self.y + 1) == 'enemy': # s.play() dushman.killenemy(self.x) dushman.killenemy(self.x + 1) gameManager.changescore('enemy') for j in range(0, 2): gameboard.board[(self.y - 1)][self.x + j] = ' ' gameboard.board[self.y][self.x + j] = ' ' self.y = self.y + 1 if checkboard(self, self.x, self.y + 1) == 'boss' or checkboard( self, self.x + 1, self.y + 1) == 'boss': gameManager.changescore('boss') thanos.killboss() for j in range(0, 2): gameboard.board[(self.y - 1)][self.x + j] = ' ' gameboard.board[self.y][self.x + j] = ' ' self.y = self.y + 1 if self.superpower == 1: self.jump = self.superjump for j in range(0, 2): gameboard.board[(self.y - 1)][self.x + j] = 'O' gameboard.board[self.y][self.x + j] = 'T'
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)
def explosion(self, alpha, beta): '''Deals with explosion of bomb''' # For the oroginal position. for j in range(0, 4): Board.board[(beta + 1) * 2][(alpha + 1) * 4 + j] = 'e' Board.board[(beta + 1) * 2 + 1][(alpha + 1) * 4 + j] = 'e' beta = beta - 1 # For down. if checkboard(self, alpha, beta) == 'enemy': MANAGEINSTANCE.changescore('enemy') Enemy.removeenemy(self, alpha, beta) for j in range(0, 4): Board.board[(beta + 1) * 2][(alpha + 1) * 4 + j] = 'e' Board.board[(beta + 1) * 2 + 1][(alpha + 1) * 4 + j] = 'e' if checkboard(self, alpha, beta) == 'empty': for j in range(0, 4): Board.board[(beta + 1) * 2][(alpha + 1) * 4 + j] = 'e' Board.board[(beta + 1) * 2 + 1][(alpha + 1) * 4 + j] = 'e' if checkboard(self, alpha, beta) == 'bomberman': MANAGEINSTANCE.changelives() for j in range(0, 4): Board.board[(beta + 1) * 2][(alpha + 1) * 4 + j] = 'e' Board.board[(beta + 1) * 2 + 1][(alpha + 1) * 4 + j] = 'e' if checkboard(self, alpha, beta) == 'bomb': self.removebomb(alpha, beta) for j in range(0, 4): Board.board[(beta + 1) * 2][(alpha + 1) * 4 + j] = 'e' Board.board[(beta + 1) * 2 + 1][(alpha + 1) * 4 + j] = 'e' if checkboard(self, alpha, beta) == 'brick': MANAGEINSTANCE.changescore('brick') for j in range(0, 4): Board.board[(beta + 1) * 2][(alpha + 1) * 4 + j] = 'e' Board.board[(beta + 1) * 2 + 1][(alpha + 1) * 4 + j] = 'e' alpha = alpha + 1 beta = beta + 1 # For Right if checkboard(self, alpha, beta) == 'enemy': MANAGEINSTANCE.changescore('enemy') Enemy.removeenemy(self, alpha, beta) for j in range(0, 4): Board.board[(beta + 1) * 2][(alpha + 1) * 4 + j] = 'e' Board.board[(beta + 1) * 2 + 1][(alpha + 1) * 4 + j] = 'e' if checkboard(self, alpha, beta) == 'empty': for j in range(0, 4): Board.board[(beta + 1) * 2][(alpha + 1) * 4 + j] = 'e' Board.board[(beta + 1) * 2 + 1][(alpha + 1) * 4 + j] = 'e' if checkboard(self, alpha, beta) == 'bomberman': MANAGEINSTANCE.changelives() for j in range(0, 4): Board.board[(beta + 1) * 2][(alpha + 1) * 4 + j] = 'e' Board.board[(beta + 1) * 2 + 1][(alpha + 1) * 4 + j] = 'e' if checkboard(self, alpha, beta) == 'bomb': self.removebomb(alpha, beta) for j in range(0, 4): Board.board[(beta + 1) * 2][(alpha + 1) * 4 + j] = 'e' Board.board[(beta + 1) * 2 + 1][(alpha + 1) * 4 + j] = 'e' if checkboard(self, alpha, beta) == 'brick': MANAGEINSTANCE.changescore('brick') for j in range(0, 4): Board.board[(beta + 1) * 2][(alpha + 1) * 4 + j] = 'e' Board.board[(beta + 1) * 2 + 1][(alpha + 1) * 4 + j] = 'e' alpha = alpha - 2 # For Left if checkboard(self, alpha, beta) == 'enemy': MANAGEINSTANCE.changescore('enemy') Enemy.removeenemy(self, alpha, beta) for j in range(0, 4): Board.board[(beta + 1) * 2][(alpha + 1) * 4 + j] = 'e' Board.board[(beta + 1) * 2 + 1][(alpha + 1) * 4 + j] = 'e' if checkboard(self, alpha, beta) == 'empty': for j in range(0, 4): Board.board[(beta + 1) * 2][(alpha + 1) * 4 + j] = 'e' Board.board[(beta + 1) * 2 + 1][(alpha + 1) * 4 + j] = 'e' if checkboard(self, alpha, beta) == 'bomberman': MANAGEINSTANCE.changelives() for j in range(0, 4): Board.board[(beta + 1) * 2][(alpha + 1) * 4 + j] = 'e' Board.board[(beta + 1) * 2 + 1][(alpha + 1) * 4 + j] = 'e' if checkboard(self, alpha, beta) == 'bomb': self.removebomb(alpha, beta) for j in range(0, 4): Board.board[(beta + 1) * 2][(alpha + 1) * 4 + j] = 'e' Board.board[(beta + 1) * 2 + 1][(alpha + 1) * 4 + j] = 'e' if checkboard(self, alpha, beta) == 'brick': MANAGEINSTANCE.changescore('brick') for j in range(0, 4): Board.board[(beta + 1) * 2][(alpha + 1) * 4 + j] = 'e' Board.board[(beta + 1) * 2 + 1][(alpha + 1) * 4 + j] = 'e' alpha = alpha + 1 beta = beta + 1 # For Down if checkboard(self, alpha, beta) == 'enemy': MANAGEINSTANCE.changescore('enemy') Enemy.removeenemy(self, alpha, beta) for j in range(0, 4): Board.board[(beta + 1) * 2][(alpha + 1) * 4 + j] = 'e' Board.board[(beta + 1) * 2 + 1][(alpha + 1) * 4 + j] = 'e' if checkboard(self, alpha, beta) == 'empty': for j in range(0, 4): Board.board[(beta + 1) * 2][(alpha + 1) * 4 + j] = 'e' Board.board[(beta + 1) * 2 + 1][(alpha + 1) * 4 + j] = 'e' if checkboard(self, alpha, beta) == 'bomberman': MANAGEINSTANCE.changelives() for j in range(0, 4): Board.board[(beta + 1) * 2][(alpha + 1) * 4 + j] = 'e' Board.board[(beta + 1) * 2 + 1][(alpha + 1) * 4 + j] = 'e' if checkboard(self, alpha, beta) == 'bomb': self.removebomb(alpha, beta) for j in range(0, 4): Board.board[(beta + 1) * 2][(alpha + 1) * 4 + j] = 'e' Board.board[(beta + 1) * 2 + 1][(alpha + 1) * 4 + j] = 'e' if checkboard(self, alpha, beta) == 'brick': MANAGEINSTANCE.changescore('brick') for j in range(0, 4): Board.board[(beta + 1) * 2][(alpha + 1) * 4 + j] = 'e' Board.board[(beta + 1) * 2 + 1][(alpha + 1) * 4 + j] = 'e' beta = beta - 1
def moveenemies(self): '''moves enemies''' for i in range(0, len(self.aEnemy)): # flag to check for the death of bomberman flag = 0 tempa = self.aEnemy[i] tempb = self.bEnemy[i] temp = [] index = [] temp.append(checkboard(self, tempa + 1, tempb)) temp.append(checkboard(self, tempa - 1, tempb)) temp.append(checkboard(self, tempa, tempb + 1)) temp.append(checkboard(self, tempa, tempb - 1)) for j in range(0, 4): if temp[j] == 'empty' or temp[j] == 'bomberman': index.append(j) vara = len(index) if vara == 0: continue k = randint(0, len(index) - 1) if index[k] == 0: for j in range(0, 4): Board.board[(tempb + 1) * 2][(tempa + 1) * 4 + j] = ' ' Board.board[(tempb + 1) * 2 + 1][(tempa + 1) * 4 + j] = ' ' self.aEnemy[i] = self.aEnemy[i] + 1 tempa = self.aEnemy[i] if checkboard(self, tempa, tempb) == 'bomberman': flag = 1 for j in range(0, 4): Board.board[(tempb + 1) * 2][(tempa + 1) * 4 + j] = 'E' Board.board[(tempb + 1) * 2 + 1][(tempa + 1) * 4 + j] = 'E' elif index[k] == 1: for j in range(0, 4): Board.board[(tempb + 1) * 2][(tempa + 1) * 4 + j] = ' ' Board.board[(tempb + 1) * 2 + 1][(tempa + 1) * 4 + j] = ' ' self.aEnemy[i] = self.aEnemy[i] - 1 tempa = self.aEnemy[i] if checkboard(self, tempa, tempb) == 'bomberman': flag = 1 for j in range(0, 4): Board.board[(tempb + 1) * 2][(tempa + 1) * 4 + j] = 'E' Board.board[(tempb + 1) * 2 + 1][(tempa + 1) * 4 + j] = 'E' elif index[k] == 2: for j in range(0, 4): Board.board[(tempb + 1) * 2][(tempa + 1) * 4 + j] = ' ' Board.board[(tempb + 1) * 2 + 1][(tempa + 1) * 4 + j] = ' ' self.bEnemy[i] = self.bEnemy[i] + 1 tempb = self.bEnemy[i] if checkboard(self, tempa, tempb) == 'bomberman': flag = 1 for j in range(0, 4): Board.board[(tempb + 1) * 2][(tempa + 1) * 4 + j] = 'E' Board.board[(tempb + 1) * 2 + 1][(tempa + 1) * 4 + j] = 'E' elif index[k] == 3: for j in range(0, 4): Board.board[(tempb + 1) * 2][(tempa + 1) * 4 + j] = ' ' Board.board[(tempb + 1) * 2 + 1][(tempa + 1) * 4 + j] = ' ' self.bEnemy[i] = self.bEnemy[i] - 1 tempb = self.bEnemy[i] if checkboard(self, tempa, tempb) == 'bomberman': flag = 1 for j in range(0, 4): Board.board[(tempb + 1) * 2][(tempa + 1) * 4 + j] = 'E' Board.board[(tempb + 1) * 2 + 1][(tempa + 1) * 4 + j] = 'E' if flag: flag = 0 MANAGEINSTANCE.changelives()