def print_board(self, k): '''print board function''' if self.player.level == 1: print_background(self) print_player(self) draw_brick(self, self.bricks) print_enemy(self) print_bullet(self, self.bullets) print_bullet(self, self.ebul) if self.alivev == 1: print_villain(self, self.vil.posx, self.vil.posy) if self.alivev == 0: win(self) # time.sleep(3) temp = "" string = '\033[93m' + "Life=" + str( self.player.life) + " Score=" + str( self.player.score) + " Coins=" + str( self.player.coins) + "\n" + '\033[0m' if k >= 550 and self.alivev == 1: string += '\033[93m' + "Boss Life=" + \ str(self.vil.life) + "\n" + '\033[0m' temp += string for i in range(40): for j in range(k, k + 150, 1): temp += self.level1[i][j] print(temp) else: print_background(self) print_player(self) draw_brick(self, self.bricks2) draw_coin(self, self.coins) if time.time() - self.time >= 0.3: write(self) self.time = time.time() temp = "" string = '\033[93m' + "Life=" + str( self.player.life) + " Score=" + str( self.player.score) + " Coins=" + str( self.player.coins) + "\n" + '\033[0m' temp += string for i in range(40): for j in range(k, k + 150, 1): temp += self.level1[i][j] print(temp)
def play(): while not variables.finish: if variables.curPlayer == 1: variables.curChess = "*" print("\033[1;37;40m * - Enter the coords of the chess (e.g. A0): \033[0m") else: variables.curChess = "o" print("\033[1;30;42m o - Enter the coords of the chess (e.g. A0): \033[0m") user_input = input() ch = user_input[0] x = ord(ch.upper()) - 65 y = int(user_input[1]) if exist(x, y) and len(user_input) == 2: flag = update_board(x, y) if flag == 0: print("\033[31m****** The place has been taken! Please try again! \033[0m") continue f = check_win(x, y) if f == 1: win() break swap_player() show_board() else: print("\033[31m*** Invalid coords! Please try again! ***\033[0m")
def press(action): #check si l'action est bien zqsd if action == "z" or action == "q" or action == "s" or action == "d": # check si le moove est possible if moove.checkMoove(action, variables.positionY, variables.positionX, variables.checkLab): #appel de la fonction pour chager la position de l'avatar et l'avatar lui même mouvement = moove.moove(action, variables.positionY, variables.positionX, variables.avatar) #recuperer les tuples variables.positionY = mouvement[0] variables.positionX = mouvement[1] variables.avatar = mouvement[2] #comme dans le main clear() pMap.printTitre() pMap.printLab(variables.positionY, variables.positionX, variables.lab, variables.avatar) #check si win if variables.positionY == 0 or variables.positionX == 0 or variables.positionY == ( len(variables.lab) - 1) or variables.positionX == (len(variables.lab[0]) - 1): win.win() else: print("Vous ne pouvez pas traverser les murs") else: print("ZQSD uniquement merci")
def play_(self): running = True self.screen.blit(self.bg, (0, 0)) self.player1_char_set() self.player2_char_set() flag = 0 msg = False while running: self.player1_play() # self.player2(2) for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() temp = 0 mouse_pos = pygame.mouse.get_pos() for i, rect in enumerate(self.button): if rect.collidepoint(mouse_pos): if event.type == MOUSEBUTTONDOWN: flag = 1 self.attack = self.data[int( self.player1_id)]['attacks'][self.button.index( rect)]['attack_name'] self.attack_damage = self.data[int( self.player1_id)]['attacks'][self.button.index( rect)]['attack_damage'] self.attack_desc = self.data[int( self.player1_id)]['attacks'][self.button.index( rect)]['attack_desc'] self.attack_message = self.data[int( self.player1_id)]['attacks'][self.button.index( rect)]['attack_message'] if (flag == 1): self.update_player1() flag = 2 pygame.display.update() pygame.time.wait(2000) if (flag == 2): self.attack = self.data[int( self.player2_id)]['attacks'][0]['attack_name'] self.attack_damage = self.data[int( self.player2_id)]['attacks'][0]['attack_damage'] self.attack_desc = self.data[int( self.player2_id)]['attacks'][0]['attack_desc'] self.attack_message = self.data[int( self.player2_id)]['attacks'][0]['attack_message'] self.update_player2() flag = 0 if (self.win): running = False win(self.win) print(self.won, 'is the winner') break pygame.display.update() self.mainClock.tick(10)
def play(): print("Going to the Game...\n\n") game.start() file = open("gnav.txt") nav = file.read() file.close() if nav == "1": os.system('cls') win.win() score() elif nav == "2": os.system('cls') lose.lose() main() else: os.system('cls') main()
def play(): print("Going to the Game...\n\n") game.start() file=open("gnav.txt") nav=file.read() file.close() if nav=="1": os.system('cls') win.win() score() elif nav=="2": os.system('cls') lose.lose() main() else: os.system('cls') main()
def battleloop(): if player.hp > 0 and enemy.hp > 0: if player.agi > enemy.agi: pfirst() elif player.agi < enemy.agi: efirst() elif player.agi == enemy.agi: randord = r.randint(1, 2) if randord == 1: pfirst() elif randord == 2: efirst() else: battleloop() elif player.hp <= 0: d.death() elif enemy.hp <= 0: w.win() battleloop()
def fastwatch(self): ret = self.checktoken() if ret is None : return self.jsonify(code=1, msg='No permission') if self._curpic: picwin = win() picwin.wildfind(viewer_title) if picwin.valid(): return self.jsonify(code=0, data=self._curpic) if self.ppt and self.ppt.opened(): return self.jsonify(code=0, data=str(self.ppt.curslide())+'.png') return self.jsonify(code=0, data='')
def _whattoshow(self): if self._curpic: picwin = win() picwin.wildfind(viewer_title) #picwin.wildfind('Notepad') if picwin.valid(): print('I think we can find the window') return self._curpic if self._curppt: if self.ppt and self.ppt.opened(): return str(self.ppt.curslide()) + '.png' return ''
def _openppt(self, filename=None): self._closeall() if filename : self._curppt = filename if self._curppt is None: return path = os.path.join(os.path.abspath(os.path.join(os.path.dirname(__file__))),'files') self.ppt.open(path + os.sep + self._curppt) # slide's name is 1.png,2.png,.... self.ppt.makepics( path ) # manipulate ppt window pptwin = win() pptwin.wildfind(self._curppt) n = 3 while not pptwin.valid() and n: time.sleep(0.3) pptwin.wildfind(self._curppt) n = n - 1 if pptwin.valid(): pptwin.foreground() pptwin.activate() self._broadcast()
sac = subprocess.Popen('./a.out', shell=True, stdin=subprocess.PIPE, stdout=None, stderr=subprocess.PIPE) output[0] = int(output[0]) - 1 output[1] = int(output[1]) - 1 output[2] = int(output[2]) - 1 output[3] = int(output[3]) - 1 output = str(output[0]) + ' ' + str(output[1]) + ' ' + str( output[2]) + ' ' + str(output[3]) + ' ' + 'k' sac.communicate(output) print output if (win.win(1) == 'w'): flagwin = 1 vic = 1 #BOT 2 KA CODE else: no = 2 proc2 = subprocess.Popen('python runner2.py', shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) [a, b] = proc2.communicate() verd = int(a[12]) print verd if (verd == 5 or verd == 2):
def update(self, event): self.getbinpos(self.Player) worldob = self.get_binobjs(self.Player) dt = float(time.time() - self.timer) if dt >= 1: pass if dt >= 3: self.intro_text.set_alpha(self.intro_text.get_alpha() - (self.fade_rate + 2)) if self.intro_text.get_alpha() <= 0: pass if self.fade.get_alpha() - self.fade_rate <= 0: self.fade.set_alpha(0) else: curr_a = self.fade.get_alpha() curr_a -= self.fade_rate self.fade.set_alpha(curr_a) x = self.fade.get_alpha() self.check_esc() self.DRAW_DISP.fill(GAME_GLOBALS.BLACK) self.check_active_dialog() self.update_score(time.time() - self.time_flag) if self.currlevel == 2: self.leveltimer -= 2 if self.leveltimer == 0: GAME_GLOBALS.GAME_STATE = cutscene.Cutscene('../images/darkmaze.jpg','../resource/EVEmaze', self.nextl) for f in self.finish: if self.currlevel == 4: self.final = True self.music.stop() if self.Player.rect.collidepoint(f): if self.final: GAME_GLOBALS.GAME_STATE = win.win() elif self.currlevel == 0: GAME_GLOBALS.GAME_STATE = cutscene.Cutscene('../images/Eve awake.png','../resource/EVEawkeningcinematic', self.nextl) elif self.currlevel == 1: GAME_GLOBALS.GAME_STATE = cutscene.Cutscene('../images/darkalley.jpg','../resource/EVEknows', self.nextl) elif self.currlevel == 3: GAME_GLOBALS.GAME_STATE = cutscene.Cutscene('../images/flare.png','../resource/EVEplots', self.nextl) for e in self.Enemygroup: self.getbinpos(e) proj = e.update(self.Player.rect, self.get_binobjs(e)) if proj != None: self.Projectiles.add(proj) for p in self.Projectiles: test = p.update(self.Wallgroup, self.Player.rect, self.Player) if test == True and p.hitplayer == True: bloodsplatter = pygame.sprite.Group() self.splatter = True for j in range(20): bloodsplatter.add(Ball.Ball((0,0,0),100,self.Player.rect.center)) self.currentsplatter = bloodsplatter self.Projectiles.remove(p) p = None elif test == True: self.Projectiles.remove(p) flags = self.Player.update(event, worldob, self.Enemygroup, self.current_score, self.Projectiles) if flags == 'died': GAME_GLOBALS.GAME_STATE = deathscreen.Deathscreen(self.current_score, self.levelname) if 'player_dmg' in flags: bloodsplatter = pygame.sprite.Group() self.splatter = True for j in range(20): bloodsplatter.add(Ball.Ball((0,1,0),100,self.Player.rect.center)) self.currentsplatter = bloodsplatter for d in self.Doorgroup: dpos = d.teleport_hax(self.Player.rect) self.Player.rect.centerx += dpos[0] self.camera.update(self.Player.rect.center) for i in self.Enemygroup: if i.health <= 0: bloodsplatter = pygame.sprite.Group() self.splatter = True for j in range(20): bloodsplatter.add(Ball.Ball((0,0,0),100,i.rect.center)) self.currentsplatter = bloodsplatter self.current_score += 500 scoretext = pygame.Surface((100,100)) scoretext.fill(GAME_GLOBALS.BLACK) scoretext.set_colorkey(GAME_GLOBALS.BLACK) scoretext.blit(self.font_obj.render("+500", 1, (random.randint(1,255), random.randint(1,255), random.randint(1,255))), (0,0)) scoretext.set_alpha(255) newball = Ball.Ball((0, 0, 0), 2, i.rect.topleft, im=scoretext) self.extras.append(newball) self.points.play() self.Enemygroup.remove(i) self.DRAW_DISP.blit(self.camera.current_frame, (0, 0)) for e in self.Enemygroup: p = (e.rect.left - self.camera.r.left, e.rect.top - self.camera.r.top) self.DRAW_DISP.blit(e.image, p) for p in self.Projectiles: f = (p.rect.left - self.camera.r.left, p.rect.top - self.camera.r.top) self.DRAW_DISP.blit(p.image, f) if self.splatter: if len(self.currentsplatter) != 0: for b in self.currentsplatter: if b.update() == 1: self.currentsplatter.remove(b) else: c = (b.rect.left - self.camera.r.left, b.rect.top - self.camera.r.top) self.DRAW_DISP.blit(b.image,c) else: self.splatter = False self.HUD.update((self.Player.current_health, self.Player.max_health), self.current_score, self.Player.invuln, self.col, self.row, self.newmap, self.currlevel) if self.Player.state == gameobj.ATTACKING: if self.Player.angle in [0, -45, -90]: self.DRAW_DISP.blit(self.Player.image, (462, 434 - self.Player.image.get_size()[1])) elif self.Player.angle in [180, -135]: self.DRAW_DISP.blit(self.Player.image, (462, 334)) elif self.Player.angle == 45: self.DRAW_DISP.blit(self.Player.image, (562- self.Player.image.get_size()[0], 434- self.Player.image.get_size()[1])) else: self.DRAW_DISP.blit(self.Player.image, (562 - self.Player.image.get_size()[0], 334)) else: self.DRAW_DISP.blit(self.Player.image, (462, 334)) if self.currlevel == 2 or self.currlevel == 4: if self.shaketimer == 500: self.shakecooldown = 0 if self.shaketimer != 500 and self.shakecooldown == 1000: x = self.shake() temp = pygame.Surface(GAME_GLOBALS.WINDOW_SIZE) temp.blit(self.DRAW_DISP, (0,0)) self.DRAW_DISP.blit(temp, x) self.shaketimer += 2 else: self.shakecooldown += 5 self.shaketimer = 0 for e in self.extras: if e.update() == 1: self.extras.remove(e) else: c = (e.rect.left - self.camera.r.left, e.rect.top - self.camera.r.top) self.DRAW_DISP.blit(e.image, c) self.DRAW_DISP.blit(self.fade, (0, 0)) self.DRAW_DISP.blit(self.intro_text, (GAME_GLOBALS.WINDOW_WIDTH/2 - self.intro_text.get_size()[0]/2, GAME_GLOBALS.WINDOW_HEIGHT/3)) if GAME_GLOBALS.BALANCE >= 0: GAME_GLOBALS.LOFFSET.set_alpha(abs(GAME_GLOBALS.BALANCE) * 20) self.DRAW_DISP.blit(GAME_GLOBALS.LOFFSET, (0,0), None, 0) else: GAME_GLOBALS.DOFFSET.set_alpha(abs(GAME_GLOBALS.BALANCE) * 20) self.DRAW_DISP.blit(GAME_GLOBALS.DOFFSET, (0,0), None, 0) if self.levelname == '../images/ASCIILEVEL3.txt': self.DRAW_DISP.blit(self.shade, (0, 0), special_flags=pygame.BLEND_MULT) self.HUD.update((self.Player.current_health, self.Player.max_health), self.current_score, self.Player.invuln, self.col, self.row, self.newmap, self.currlevel) if self.ds != None: self.ds.update() self.DRAW_DISP.blit(self.ds.backsurf, (GAME_GLOBALS.WINDOW_WIDTH/2 - self.ds.backsurf.get_size()[0]/2, GAME_GLOBALS.WINDOW_HEIGHT/2 - self.ds.backsurf.get_size()[1]/2)) self.check_esc()
output=str(output[0])+' '+str(output[1])+' '+str(output[2])+' '+str(output[3])+' '+'m' print output sac.communicate(output) elif(result=='k'): sac=subprocess.Popen('./a.out',shell=True,stdin=subprocess.PIPE,stdout=None,stderr=subprocess.PIPE) output[0]=int(output[0])-1 output[1]=int(output[1])-1 output[2]=int(output[2])-1 output[3]=int(output[3])-1 output=str(output[0])+' '+str(output[1])+' '+str(output[2])+' '+str(output[3])+' '+'k' sac.communicate(output) print output if(win.win(1)=='w'): flagwin=1 vic=1 #BOT 2 KA CODE else: no=2 proc2=subprocess.Popen('python runner2.py',shell=True,stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE) [a,b]=proc2.communicate() verd=int(a[12]) print verd if (verd==5 or verd==2): if verd==5: #print "time limit exceeded,exiting" #exit() error=1