Fix Crash on Pathfinding error

This commit is contained in:
Michał Gdula 2023-01-28 19:49:30 +00:00
parent 41a0ec665b
commit 760b29a761
4 changed files with 15 additions and 13 deletions

View file

@ -23,17 +23,20 @@ class PathFinding:
queue = deque([start])
visited = {start: None}
while queue:
cur_node = queue.popleft()
if cur_node == goal:
break
next_nodes = graph[cur_node]
try:
while queue:
cur_node = queue.popleft()
if cur_node == goal:
break
next_nodes = graph[cur_node]
for next_node in next_nodes:
if next_node not in visited and next_node not in self.game.object_handler.npc_positions:
queue.append(next_node)
visited[next_node] = cur_node
return visited
for next_node in next_nodes:
if next_node not in visited and next_node not in self.game.object_handler.npc_positions:
queue.append(next_node)
visited[next_node] = cur_node
return visited
except KeyError:
return visited
def get_next_nodes(self, x, y):
return [(x + dx, y + dy) for dx, dy in self.ways if (x + dx, y + dy) not in self.game.map.world_map]