def Restart(): #Creates new instance of the game with the same dificulty global character, score, dificulty_level, used_help, Window, list_x2, list_x1 pygame.time.delay(300) #Total score message img = image.load(const.imagespath + "bubble_large.png").convert_alpha() img.set_colorkey(RLEACCEL) rect = Rect((80, 75), (125, 200)) Window.blit(img, rect) font = pygame.font.Font(None, 36) text = font.render("Total de puntos: " + str(score), 1, const.red) textpos = Rect((150, 145), (165, 235)) Window.blit(text, textpos) #If the score is too low sends game over message else says its completed if (score < 200): text = font.render("Intenta de nuevo", 1, Color(1, 72, 152)) textpos = Rect((175, 180), (175, 245)) Window.blit(text, textpos) else: text = font.render("Muy bien!Prueba con experto", 1, Color(1, 72, 152)) textpos = Rect((175, 180), (175, 245)) Window.blit(text, textpos) pygame.display.flip() sleep(3.5) #Avatar wall displayed on the screen for Xil in list_x2: Xil.show(Window) pygame.display.flip() #Re generates maze if dificulty_level == 1: mymaze = maze(easy_maze[0], easy_maze[1]) else: mymaze = maze(hard_maze[0], hard_maze[1]) mymaze.generate_maze() character = Character(mymaze) #Checks if there was use of help on the last game if used_help: #Cleans variables with exeption of code generated Complete_cleanup(1) else: #Cleans variables completly Complete_cleanup(0) #To remove the wall of avatars while True: Window.fill(const.green) character.show(Window) render_widgets() if not list_x2: break i = 0 while i < 5: list_x2.remove(choice(list_x2)) i += 1 for Xil in list_x2: Xil.show(Window) pygame.display.flip() list_x2 = fill_list_x2(list_x1)
def Restart():#Creates new instance of the game with the same dificulty global character,score,dificulty_level,used_help,Window,list_x2,list_x1 pygame.time.delay(300) #Total score message img = image.load(const.imagespath+"bubble_large.png").convert_alpha() img.set_colorkey(RLEACCEL) rect = Rect((80,75), (125, 200)) Window.blit(img,rect) font = pygame.font.Font(None, 36) text = font.render("Total de puntos: "+str(score), 1, const.red) textpos = Rect((150,145),(165,235)) Window.blit(text, textpos) #If the score is too low sends game over message else says its completed if(score < 200): text = font.render("Intenta de nuevo", 1, Color(1,72,152)) textpos = Rect((175,180),(175,245)) Window.blit(text, textpos) else: text = font.render("Muy bien!Prueba con experto", 1, Color(1,72,152)) textpos = Rect((175,180),(175,245)) Window.blit(text, textpos) pygame.display.flip() sleep(3.5) #Avatar wall displayed on the screen for Xil in list_x2: Xil.show(Window) pygame.display.flip() #Re generates maze if dificulty_level == 1: mymaze = maze(easy_maze[0],easy_maze[1]) else: mymaze = maze(hard_maze[0],hard_maze[1]) mymaze.generate_maze() character = Character(mymaze) #Checks if there was use of help on the last game if used_help: #Cleans variables with exeption of code generated Complete_cleanup(1) else: #Cleans variables completly Complete_cleanup(0) #To remove the wall of avatars while True: Window.fill(const.green) character.show(Window) render_widgets() if not list_x2: break i = 0 while i < 5: list_x2.remove(choice(list_x2)) i += 1 for Xil in list_x2: Xil.show(Window) pygame.display.flip() list_x2 = fill_list_x2(list_x1)
def Update_display():#Re renders objects on the screen with the changes made on the values global character,character_time,Window,entry_score ##Sets miliseconds between a display loop if pygame.time.get_ticks() - character_time >= const.time_character_poll: character_time = pygame.time.get_ticks() character.poll() character.show(Window) entry_score.set("Puntos:"+str(score)) render_widgets() pygame.display.flip()
def Update_display( ): #Re renders objects on the screen with the changes made on the values global character, character_time, Window, entry_score ##Sets miliseconds between a display loop if pygame.time.get_ticks() - character_time >= const.time_character_poll: character_time = pygame.time.get_ticks() character.poll() character.show(Window) entry_score.set("Puntos:" + str(score)) render_widgets() pygame.display.flip()
def But_path():#Generates solution and solves current maze global character,input_from_user character.yellow_road = [] character.reverse = 0 line_counter = 0 #Gets where the goal is character.goal(((character.maze.w - 1), (character.maze.h - 1))) #Checks for previous written input from user if len(input_from_user) > 0: input_from_user = "" del const.instructions[:] #Gets path to follow road = character.get_goal((character.x, character.y), ((character.maze.w - 1), (character.maze.h - 1))) #Creates input from the solution found. for instruction in const.instructions: temp_entry = input_from_user input_from_user = temp_entry+instruction+"\n" line_counter += 1 render_widgets() #Moves character accordingly character.go_to(road)
def But_path(): #Generates solution and solves current maze global character, input_from_user character.yellow_road = [] character.reverse = 0 line_counter = 0 #Gets where the goal is character.goal(((character.maze.w - 1), (character.maze.h - 1))) #Checks for previous written input from user if len(input_from_user) > 0: input_from_user = "" del const.instructions[:] #Gets path to follow road = character.get_goal((character.x, character.y), ((character.maze.w - 1), (character.maze.h - 1))) #Creates input from the solution found. for instruction in const.instructions: temp_entry = input_from_user input_from_user = temp_entry + instruction + "\n" line_counter += 1 render_widgets() #Moves character accordingly character.go_to(road)
perso.move(const.down) if keys[K_LEFT]: if not perso.che_jaune: perso.move(const.left) if keys[K_RIGHT]: if not perso.che_jaune: perso.move(const.right) if time.get_ticks() - perso_time >= const.time_perso_poll: perso_time = time.get_ticks() perso.poll() perso.show(Window) render_widgets() display.flip() if perso.x == perso.laby.w - 1 and perso.y == perso.laby.h - 1: time.delay(300) '''for Bip in liste_b2: Bip.show(Window) display.flip()''' mylaby = laby(5, 5) mylaby.generate_laby() perso = Perso(mylaby) '''while True:
def main(difficulty): #---------------------Pygame init--------------------# myfont = font.SysFont("monospace", 15) #Création de la fenêtre WW, WH = 640, 480 Window = display.set_mode((WW, WH)) #icone = image.load("Bipo.png") #icone.set_colorkey(const.pink) #display.set_icon(icone) # FIN if difficulty == 0: time_limit = 40 elif difficulty == 1: time_limit = 30 elif difficulty == 2: time_limit = 20 #---------------------Some variables--------------------# mylaby = laby(5, 5) mylaby.generate_laby() perso = Perso(mylaby) perso_time = 0 display.flip() key.set_repeat(50, 55) # FIN first_time = time.time() while True: current_time = time.time() Window.fill(const.Porange) time_play = int(current_time - first_time) label = myfont.render(str(time_limit - time_play), 1, (0, 0, 0)) Window.blit(label, (200, 0)) if time_play >= time_limit: return -1 for event in handle_widgets(): if event.type == QUIT: quit() exit() pygame.time.wait(50) keys = key.get_pressed() if keys: if keys[K_UP]: if not perso.che_jaune: perso.move(const.up) if keys[K_DOWN]: if not perso.che_jaune: perso.move(const.down) if keys[K_LEFT]: if not perso.che_jaune: perso.move(const.left) if keys[K_RIGHT]: if not perso.che_jaune: perso.move(const.right) perso.show(Window) render_widgets() display.flip() if perso.x == perso.laby.w - 1 and perso.y == perso.laby.h - 1: return 0
can_execute = False #Toolbar update input_formatted = str(input_from_user) input_formatted = input_formatted.replace("\n", "\n\n") entryForInput.set(input_formatted) entry_score.set("Puntos:" + str(score)) ##Sets miliseconds between a display loop if pygame.time.get_ticks( ) - character_time >= const.time_character_poll: character_time = pygame.time.get_ticks() character.poll() ##Renders rest of display character.show(Window) if not input_initialized: Create_input() render_widgets() pygame.display.flip() #If the character is on the finish line if character.x == character.maze.w - 1 and character.y == character.maze.h - 1: Restart() elif (on_initial): ## Main page Window.fill(const.black) # Buttons # Levels section start_button = Button(Window, text="Principiante", width=95, height=30, bordercolor=const.Porange,
def main(difficulty): #---------------------Pygame init--------------------# init() myfont = font.SysFont("monospace", 15) #Création de la fenêtre WW, WH = 640, 480 Window = display.set_mode((WW, WH)) #icone = image.load("Bipo.png") #icone.set_colorkey(const.pink) #display.set_icon(icone) display.set_caption("Bipo Maze") # FIN if difficulty == 1: taille = 10 elif difficulty == 2: taille = 11 elif difficulty == 3: taille = 12 #---------------------Some variables--------------------# mylaby = laby(taille, taille) mylaby.generate_laby() perso = Perso(mylaby) perso_time = 0 display.flip() key.set_repeat(50, 55) # FIN while True: time.Clock().tick(30) Window.fill(const.Porange) time_play = time.get_ticks()/1000 label = myfont.render(str(time_play), 1, (0,0,0)) Window.blit(label, (200, 0)) for event in handle_widgets(): if event.type == QUIT: quit() exit() keys = key.get_pressed() if keys: if keys[K_UP]: if not perso.che_jaune: perso.move(const.up) if keys[K_DOWN]: if not perso.che_jaune: perso.move(const.down) if keys[K_LEFT]: if not perso.che_jaune: perso.move(const.left) if keys[K_RIGHT]: if not perso.che_jaune: perso.move(const.right) perso.show(Window) render_widgets() display.flip() if perso.x == perso.laby.w - 1 and perso.y == perso.laby.h - 1: quit() exit()