def create_maze(grid): grid.reset(surface, 1) actualmaze = maze(gridsize[0] - 1, gridsize[1] - 1) for x, i in enumerate(actualmaze): for y, j in enumerate(i): if j: grid.walls.add((x,y)) grid.setwalls([])
def create_maze(grid): grid.reset(surface, 1) actualmaze = maze(gridsize[0] - 1, gridsize[1] - 1) for x, i in enumerate(actualmaze): for y, j in enumerate(i): if j: grid.walls.add((x, y)) grid.setwalls([])
def create_maze(grid): grid.reset(surface, 1) atualmaze = maze(99, 99) for x, i in enumerate(atualmaze): for y, j in enumerate(i): if j: grid.walls.append((x,y)) grid.setwalls([])
def create_maze(grid): grid.reset(surface, 1) atualmaze = maze(99, 99) for x, i in enumerate(atualmaze): for y, j in enumerate(i): if j: grid.walls.append((x, y)) grid.setwalls([])
from coords import * from maze import * import sys sys.setrecursionlimit(10**5) m = maze(55, 33) m.generate(0.03) # draw generation step with 0.03 sec delay m.solve(0.3) # draw solving step with 0.3 sec delay # m = maze(55, 33) # create maze 55 x 33 cells # m.generate() # m.show() # display maze # # ! maze has to be generated # m.solve() # m.show(m.solution) # show maze with solution # # ! maze has to be solved # print(m.solution) # print text solution
offset_x = (canvas_width - cell_size * maze.size) // 2 offset_y = (canvas_height - cell_size * maze.size) // 2 top_left = (offset_x, offset_y) #draw the outline of the maze canvas.create_rectangle(offset_x, offset_y, offset_x + cell_size* maze.size, offset_y + cell_size*maze.size, outline="black", fill="white") #for each cell in the maze for mx in range(maze.size): for my in range(maze.size): #get a list of adjacent cells, and the #cells that have no walls between them location = (mx, my) corridors = maze.get_corridors(location) neighbours = maze.get_neighbours(location) for adjacent in neighbours: if adjacent not in corridors: #if the cell is adjacent and it is a wall, then draw the line x1, y1, x2, y2 = get_coords(location, adjacent, top_left, cell_size) canvas.create_line(x1, y1, x2, y2, fill="black") #pause until the user closes the window tkinter.mainloop() #create a maze of a specific size and draw it. #anything over around 100 starts to get slow m = maze(20) draw(m)
a@@@@@@@\ | `| ''.' .' | ' /@@@@@@@@@a --------------------------------------------------------------------------------""") thunder() play_obj = wave_obj.play() dprint("This is your father's castle. Yet your adventure does not start in the throne\nroom, or the dining room, or even your bedroom.") dprint("You have awoken this morning locked in the jail cell in the cellar of the\ncastle. Surrounded by rats and other undesirables.") dprint("Your memory slowly returns as you clear the sleep from your eyes...") dprint("You remember the violent murder of your father at the hands of your uncle\nYou realize your uncle must have thrown you in the jail to keep you out of") dprint("the way until he can fully take over the kingdom!") dprint("You quickly escape the jail cell and decide to confront your uncle in the\nthrone room!") #Game Starts Here! #Predefined location, with one potion type random item. CurrEnv = 0 currfloor = maze(5,5,difficulty) #currfloor.display() #JailCell = Environment([EnvironmentGenerator.genObject(2,difficulty)],"smelly dark room outside your jail cell",[Door(False,"Up",0)]) CurrEnv = currfloor.getVertex(player.getLocation()[1],player.getLocation()[0]).getEnv() dprint(CurrEnv.toString()) #Testing RunCode while(1): if not play_obj.is_playing(): play_obj = wave_obj.play() #print("y:"+str(player.getLocation()[0])+" x:"+str(player.getLocation()[1])) print("\n") data = "" if(stot.lower() == 'n' or stot.lower() == 'no'): choice = input("What do you do..?\n\t") data = InputProcessor.processInput(choice,player,CurrEnv)
return pressed = pygame.key.get_pressed() if pressed[pygame.K_UP] and not(pressed[pygame.K_RIGHT]) and not(pressed[pygame.K_LEFT]): player.move(0,-player.speed) if pressed[pygame.K_DOWN] and not(pressed[pygame.K_RIGHT]) and not(pressed[pygame.K_LEFT]): player.move(0,player.speed) if pressed[pygame.K_RIGHT] and not(pressed[pygame.K_DOWN]) and not(pressed[pygame.K_UP]): player.move(player.speed,0) if pressed[pygame.K_LEFT] and not(pressed[pygame.K_DOWN]) and not(pressed[pygame.K_UP]): player.move(-player.speed,0) elif event.type == pygame.KEYUP: if event.key == pygame.K_UP or event.key == pygame.K_DOWN or event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT: player.movepos = [0,0] #Render text and sprites, draw to screen and redraw for each iteration of the game loop text = font.render("Level: " + str(cur_level + 1) + " Lives: " + str(player.num_lives),1,(10,10,10)) screen.blit(background, (0,0)) screen.blit(text, text.get_rect()) if not(exitobject == None): exitsprite = pygame.sprite.RenderPlain(exitobject) exitsprite.update(player) exitsprite.draw(screen) wallsprites = pygame.sprite.RenderPlain(wallobjects) wallsprites.update(player) wallsprites.draw(screen) enemysprites = pygame.sprite.RenderPlain(enemyobjects) enemysprites.update(player) enemysprites.draw(screen) playersprite.update() playersprite.draw(screen) pygame.display.flip() if __name__ == "__main__": maze()
self.robot.move_forward() self.update_maze() def turn_robot(self, clockwise_flag): # TODO include number of turns self.robot.turn(clockwise_flag) print('New direction: %r' % self.robot.direction) def update_system(self): # robot.update() # maze.update() pass def update_maze(self): self.maze.maze[self.robot.y_pos][self.robot.x_pos] = 'X' self.maze.print_maze() print('\n') if __name__ == '__main__': my_robot = robot(0, 0, 2) my_maze = maze(5) main = main(my_robot, my_maze) main.update_maze() main.move_robot_forward() main.move_robot_forward() main.move_robot_forward() main.move_robot_forward() main.turn_robot(0) main.move_robot_forward()
import maze import time maze = maze.maze testmaze = maze(50, 50) testmaze.showCreation(4, 1000) testmaze.showMazeSolver(1000, 4) time.sleep(10) quit()
def setUp(self): """ The setUp function is called each time one of your tests is run. We create an instance of the maze here before each test. """ self.m=maze()
# TODO check for OOB self.robot.move_forward() self.update_maze() def turn_robot(self, clockwise_flag): # TODO include number of turns self.robot.turn(clockwise_flag) print('New direction: %r' % self.robot.direction) def update_system(self): # robot.update() # maze.update() pass def update_maze(self): self.maze.maze[self.robot.y_pos][self.robot.x_pos] = 'X' self.maze.print_maze() print('\n') if __name__ == '__main__': my_robot = robot(0,0,2) my_maze = maze(5) main = main(my_robot, my_maze) main.update_maze() main.move_robot_forward() main.move_robot_forward() main.move_robot_forward() main.move_robot_forward() main.turn_robot(0) main.move_robot_forward()