-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbox.py
More file actions
41 lines (27 loc) · 1.22 KB
/
box.py
File metadata and controls
41 lines (27 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from settings import *
import pygame
class Box:
def __init__(self, i, j): # i will be the rows and j will the be columns
self.x = i
self.y = j
self.isWall = False
self.isTarget = False
self.isStart = False
self.isQueued = False
self.isVisited = False
self.prior = None
self.distance = float("inf")
self.neighbors = []
def __lt__(self, other):
return self.distance < other.distance
def draw_box(self, canvas, color):
pygame.draw.rect(canvas, color, (self.x * BOX_WIDTH, self.y * BOX_HEIGHT, BOX_WIDTH - 2, BOX_HEIGHT - 2))
def _set_neighbors(self):
if self.x > 0:
self.neighbors.append((GRID[self.x - 1][self.y], 1 if not GRID[self.x - 1][self.y].isWall else 5))
if self.x < COLUMNS - 1:
self.neighbors.append((GRID[self.x + 1][self.y], 1 if not GRID[self.x + 1][self.y].isWall else 5))
if self.y > 0:
self.neighbors.append((GRID[self.x][self.y - 1], 1 if not GRID[self.x][self.y - 1].isWall else 5))
if self.y < ROWS - 1:
self.neighbors.append((GRID[self.x][self.y + 1], 1 if not GRID[self.x][self.y + 1].isWall else 5))