Ejemplo n.º 1
0
def maze(width=80, height=50):

    # White out maze
    Z = numpy.ones((height+borderSize,width+borderSize,3), dtype=float)

    # Generate Maze
    maze = MazeGenerator.getRandomMaze(cellsX, cellsY);

    # Reset
    for x in range(len(maze)):
        for y in range(len(maze[0])):
            maze[x][y].visited = False


    # Solve Maze
    cellStart = maze[0][0]
    cellEnd = maze[len(maze)-1][len(maze[0])-1]
    solve(cellStart, cellEnd)

    # Draw Maze
    for x in range(len(maze)):
        for y in range(len(maze[0])):
            if (x == len(maze)-1) and (y == len(maze[0])-1):
                maze[x][y].draw(Z, borderSize, cellSize, edgeSize, True)
            else:
                maze[x][y].draw(Z, borderSize, cellSize, edgeSize)
    for x in range(len(maze)):
        for y in range(len(maze[0])):
            if (maze[x][y].fillColor == None):
                if (x == len(maze)-1) and (y == len(maze[0])-1):
                    maze[x][y].draw(Z, borderSize, cellSize, edgeSize, True)
                else:
                    maze[x][y].draw(Z, borderSize, cellSize, edgeSize)
    return Z
Ejemplo n.º 2
0
def move_ghost(ghost, dimension):
    if dimension not in Node_List:
        Node_List.append(dimension)
        print('end node')
    End_Index = Node_List.index(dimension)
    Start = [ghost.rect.x // block_width, ghost.rect.y // block_width]
    if Start not in Node_List:
        Node_List.append(Start)
        print('new start node')
    Start_Index = Node_List.index(Start)
    Connection_Dict = MazeGenerator.getConnections(Wall_List, Node_List)
    try:
        Path_List = MazeGenerator.Dijkstra(Connection_Dict, Start_Index,
                                           End_Index)
    except:
        Path_List = []
    ghost.move(Path_List)
Ejemplo n.º 3
0
    def __init__(self, master):
        """
        """
        self._mazeGene = MazeGenerator.MazeGenerator()

        Frame.__init__(self, master)

        master.title("Maze Solver")
        master.minsize(300, 300)

        master.bind(self, "<Up>", self.moveplace)
        master.bind(self, "<Down>", self.moveplace)
        master.bind(self, "<Left>", self.moveplace)
        master.bind(self, "<Right>", self.moveplace)

        #Menu
        menubar = Menu(self.master)
        self.master.config(menu=menubar)

        File = Menu(menubar)
        menubar.add_cascade(label="File", menu=File)
        File.add_command(label="Open Maze File", command=self.openMaze)
        File.add_command(label="Save Maze File", command=self.saveMaze)
        File.add_command(label="Exit", command=self.quit)

        #Canvas

        self._canvas = Canvas(master, borderwidth=1, relief=SUNKEN, bg="black")
        self._canvas.pack(expand=1, anchor=CENTER)

        #Frames and Buttons

        frame1 = Frame(self)
        frame2 = Frame(frame1, relief=SUNKEN, bd=2)  #borderwidth = 2

        self._sp = Spinbox(frame2, from_=2, to=15,
                           width=15)  #put within frame2
        self._sp.pack(side=LEFT, padx=2, pady=2)

        but1 = Button(frame2, text="New", command=self.new)
        but1.pack(side=LEFT, ipadx=5)

        frame2.pack(side=LEFT)

        but2 = Button(frame1, text="Reset", command=self.reset)
        but2.pack(side=LEFT, ipadx=5, padx=20)

        but3 = Button(frame1, text="Quit", command=self.quit)
        but3.pack(side=LEFT, ipadx=5, padx=20)

        frame1.pack(side=TOP, expand=1, fill=BOTH)
        Frame.pack(self)
Ejemplo n.º 4
0
def main():
    """
    Main callable method to be used if this file is called by another class or file
    args:
    return:
    """
    global numrect
    global rectsize
    rectsize += 1
    if rectsize > 30:
        rectsize = 30
    numrect += 2
    # print("rectsize:\t" + str(rectsize))
    # print("numrect:\t" + str(numrect))
    maze, rectangles = MazeGenerator.main(msize, numrect, rectsize)
    global lvl
    # print(str(lvl))
    lvl += 1
    pygame.display.set_caption("Dungeon Crawlers" + "               " +
                               "Monsters Killed:   " + str(mobsKilled) +
                               "         Current Floor:   " + str(lvl))
    runMaze(maze, rectangles)
Ejemplo n.º 5
0
def main():
    MazeGenerator()
Ejemplo n.º 6
0
y = 700 - (700 % block_width)
size = (x, y)
screen = pygame.display.set_mode(size)
pygame.display.set_caption('PACMAN')
maze_x = size[0] // block_width
maze_y = size[1] // block_width
f = open(os.path.join(SCRIPT_PATH, 'PacMan-Maze.json'), "rt")
Wall_List = json.load(f)
f.close()
temp_node_list = []
wall_group = pygame.sprite.Group()
ghost_group = pygame.sprite.Group()
points_group = pygame.sprite.Group()
point_hit_group = pygame.sprite.Group()
all_sprites_group = pygame.sprite.Group()
Node_List = MazeGenerator.getNodes(Wall_List)
currentplayer = Node_List[0]
temp = (11 * block_width, 10 * block_width)
blinky = Ghost(block_width, temp, 'blinky')
temp = (10 * block_width, 11 * block_width)
inky = Ghost(block_width, temp, 'inky')
temp = (11 * block_width, 11 * block_width)
pinky = Ghost(block_width, temp, 'pinky')
temp = (12 * block_width, 11 * block_width)
sue = Ghost(block_width, temp, 'sue')
ghost_group.add(blinky, inky, pinky, sue)
all_sprites_group.add(blinky, inky, pinky, sue)
left_portal, right_portal = generate_wall(Wall_List, block_width)
all_sprites_group.add(left_portal, right_portal)
game_over = False
clock = pygame.time.Clock()
Ejemplo n.º 7
0
 def Maze(cls):
     width = random.randint(5, 10)
     height = random.randint(5, 10)
     maze = MazeGenerator.Maze(width, height)
     return cls(maze.getMap())
Ejemplo n.º 8
0
 def reset(self):
     MazeGenerator.MazeGenerator()._set_square(self._mazeGene, 1, 1, 'X')
     tkMessageBox.showinfo("Reset Notification",
                           "You have successfully reset the maze!")
Ejemplo n.º 9
0
 def new(self):
     sl = int(self._sp.get())
     self._genmaze = MazeGenerator.MazeGenerator().make_maze(sl)
     Maze(self._genmaze)
Ejemplo n.º 10
0
    def moveUp(self):
        self.y -= self.speed

    def moveDown(self):
        self.y += self.speed


# Initialization code
windowWidth = 1280
windowHeight = 720

player = Player()
SIZE = (19, 11)
FINISH_LINE = (SIZE[0] * 2 - 1, SIZE[1] * 2 - 1)
mazeGenerator = MazeGenerator.MazeGenerator(*SIZE)
maze = mazeGenerator.GetMaze()
maze.Print()
maze = maze.ToList()

pygame.init()
display_surf = pygame.display.set_mode((windowWidth, windowHeight),
                                       pygame.HWSURFACE)

pygame.display.set_caption('QuantumMaze')
running = True
image_surf = pygame.image.load("player.bmp").convert()
block_surf = pygame.image.load("block.bmp").convert()

TILE_SIZE = 32
Ejemplo n.º 11
0

# Test the Level class
if __name__ == '__main__' and True:
    import pygame
    from pygame.locals import *
    pygame.init()
    FIELD_WIDTH = 30
    FIELD_HEIGHT = 20
    screen = pygame.display.set_mode(
        (FIELD_WIDTH * TILE_WIDTH, FIELD_HEIGHT * TILE_HEIGHT))
    level = Level(FIELD_WIDTH, FIELD_HEIGHT)
    level.style = Tiles.tileStyles[Util.getRandom(1, 15)]

    import MazeGenerator
    room = MazeGenerator.Maze(7, 7).getMap()
    level.applyFeature(room, 1, 1)

    def draw():
        screen.fill((255, 255, 255))
        level.blit(screen)
        pygame.display.flip()

    draw()
    done = False
    while not done:
        for event in pygame.event.get():
            if event.type in [KEYDOWN, QUIT, JOYBUTTONDOWN]:
                done = True
            if event.type == MOUSEBUTTONDOWN:
                x = int(event.pos[0] / 24)
Ejemplo n.º 12
0
    def __init__(self, maze_name):

        self.maze = MG.Maze()
        self.maze.Load(maze_name)
        self.current_position = self.maze.start
        self.goal = self.maze.end
Ejemplo n.º 13
0
    def move(self, Path_List):
        self.direction = 'stop'
        self.node_queue = Path_List[1:]


# Initialize Pygame
User_Choice = input('Generate new maze? (Y/N): ')
block_width = int(input('Enter Block Size (integer):'))
pygame.init()
x = 1000 + (1000 % block_width)
y = 700 + (700 % block_width)
size = (x, y)
maze_x = size[0] // block_width
maze_y = size[1] // block_width
if User_Choice.upper() == 'Y':
    Wall_List = (MazeGenerator.generate(maze_x, maze_y)).tolist()
    FileIO.output_list(Wall_List)
else:
    Wall_List = FileIO.input_list()
#endif
wall_group = pygame.sprite.Group()
path_group = pygame.sprite.Group()
all_sprites_group = pygame.sprite.Group()
Node_List = MazeGenerator.getNodes(Wall_List)
End = random.choice(Node_List)
pos = (Node_List[0][0] * block_width, Node_List[0][1] * block_width)
player1 = Player(block_width, pos)
Start_Index = 0
End_Index = Node_List.index(End)
Connection_Dict = MazeGenerator.getConnections(Wall_List, Node_List)
Path_List = MazeGenerator.Dijkstra(Connection_Dict, Start_Index, End_Index)
Ejemplo n.º 14
0
if __name__ == '__main__':
    pygame.init()
    screen = pygame.display.set_mode((300, 300))
    level = Level.Level(LEVEL_WIDTH, LEVEL_HEIGHT)
    # level.style = Tiles.tileStyles[Util.getRandom(1, 15)]
    level.style = Tiles.tileStyles[2]
    # randomizeLevel(level)

    canvas = pygame.Surface(
        (LEVEL_WIDTH * Tiles.TILE_WIDTH, LEVEL_HEIGHT * Tiles.TILE_HEIGHT))

    s_map = ScrollingMap.Scrolling_Map(screen, canvas, Tiles.TILE_HEIGHT,
                                       Tiles.TILE_WIDTH)

    maze = MazeGenerator.Maze(10, 10).getMap()
    level.applyFeature(maze, 10, 10)

    for i in range(100):
        insertRandomRoom(level)

    stairsUp, upX, upY = level.placeTerrainFeature("stairs-up")
    stairsDown, downX, downY = level.placeTerrainFeature("stairs-down")

    level.connectFeatures(
    )  # This really slows things down; need to optimize it. Recommend turning it off while testing

    def draw():
        screen.fill((255, 255, 255))
        level.blit(s_map.image)
        s_map.blit()