-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblock.py
69 lines (51 loc) · 1.37 KB
/
block.py
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import pygame
from enum import Enum
class BlockType(Enum):
DEFAULT = 1
WALL = 2
START = 3
END = 4
OPEN = 5
CLOSED = 6
PATH = 7
type_color = {
BlockType.DEFAULT: [87, 89, 93],
BlockType.WALL: [0, 0, 0],
BlockType.START: [24, 71, 24],
BlockType.END: [88, 45, 45],
BlockType.OPEN: [0, 255, 0],
BlockType.CLOSED: [255, 0, 0],
BlockType.PATH: [39, 41, 80],
}
class Block:
def __init__(self, row, col, width):
self.row = row
self.col = col
self.x = row * width
self.y = col * width
self.width = width
self.type = BlockType.DEFAULT
self.gCost = 0
self.hCost = 0
self.parent = None
self.rect = pygame.Rect(self.x, self.y, width, width)
def get_rect(self):
return self.rect
def set_default(self):
self.type = BlockType.DEFAULT
def set_wall(self):
self.type = BlockType.WALL
def set_start(self):
self.type = BlockType.START
def set_end(self):
self.type = BlockType.END
def set_closed(self):
self.type = BlockType.CLOSED
def set_open(self):
self.type = BlockType.OPEN
def set_path(self):
self.type = BlockType.PATH
def draw(self, win, color):
pygame.draw.rect(win, color, self.rect)
def f_cost(self):
return self.gCost + self.hCost