Aggiungi la classe Point e implementa la gestione delle esplosioni nel gioco
This commit is contained in:
@@ -69,14 +69,18 @@ class MazeGenerator:
|
||||
if self.stack: # Continue updating only if there are cells left to visit
|
||||
self.window.after(10, self.update_maze)
|
||||
else:
|
||||
# After the maze is generated, remove some walls randomly
|
||||
for _ in range(int((self.width - 1) * (self.height - 1) * 0.1 // 4)):
|
||||
x = random.randrange(1, self.width - 1, 2)
|
||||
y = random.randrange(1, self.height - 1, 2)
|
||||
self.maze[y][x] = False
|
||||
self.add_random_passages()
|
||||
self.draw_maze()
|
||||
with open('maze.json', 'w') as json_file:
|
||||
json.dump(self.maze, json_file)
|
||||
json.dump(self.maze, json_file)
|
||||
|
||||
def add_random_passages(self):
|
||||
# Aggiungi passaggi casuali tra i corridoi
|
||||
for _ in range(30):
|
||||
x = random.randrange(1, self.width - 1, 2)
|
||||
y = random.randrange(1, self.height - 1, 2)
|
||||
print(x, y)
|
||||
self.maze[y][x] = False
|
||||
|
||||
def draw_maze(self):
|
||||
self.canvas.delete("all")
|
||||
@@ -92,6 +96,7 @@ class MazeGenerator:
|
||||
elif self.stack and (j, i) == self.stack[-1]:
|
||||
color = "blue" # Color the current position blue
|
||||
self.canvas.create_rectangle(j*10, i*10, (j+1)*10, (i+1)*10, fill=color)
|
||||
|
||||
|
||||
def run(self):
|
||||
self.update_maze()
|
||||
@@ -99,5 +104,5 @@ class MazeGenerator:
|
||||
self.window.mainloop()
|
||||
|
||||
# Crea e avvia il generatore di labirinti
|
||||
generator = MazeGenerator(7, 5)
|
||||
generator = MazeGenerator(15, 8)
|
||||
generator.run()
|
||||
|
||||
Reference in New Issue
Block a user