-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.py
More file actions
89 lines (68 loc) · 2.67 KB
/
Main.py
File metadata and controls
89 lines (68 loc) · 2.67 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
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import pygame
from Nodes.board import Board
from Nodes.Consants import *
pygame.init()
FPS = 60
WIN = pygame.display.set_mode((WINDOWWIDTH + 200, WINDOWHEIGHT))
pygame.display.set_caption('A Star')
def get_row_col_from_mouse(pos):
x, y = pos
row = y // SQUARE_SIZE
col = x // SQUARE_SIZE
if x > WINDOWWIDTH:
return -1, -1
return row,col
def main():
run = True
clock = pygame.time.Clock()
board = Board(WIN)
pygame.font.init()
myfont = pygame.font.SysFont("monospace", 16)
Found = False
while run:
clock.tick(FPS)
pygame.draw.rect(WIN, WHITE, (WINDOWWIDTH, 0, 200, WINDOWHEIGHT))
if Found:
board.DrawFound()
else:
board.drawBoard()
pygame.draw.rect(WIN, BLACK, (WINDOWWIDTH, 0 , 5, WINDOWHEIGHT))
#Text Drawing
StartText = myfont.render("Start: {0}, {1}".format(str(board.start.current.x), str(board.start.current.y)), 0, BLACK)
GoalText = myfont.render("Goal : {0}, {1}".format(str(board.goal.current.x), str(board.goal.current.y)), 0, BLACK)
Instructions = myfont.render("Enter To Go ", 0, BLACK)
Instructions2 = myfont.render("Backspace To Reset", 0, BLACK)
Path = myfont.render("Path:", 0, BLACK)
WIN.blit(StartText, (WINDOWWIDTH + 10, 10))
WIN.blit(GoalText, (WINDOWWIDTH + 10, 25))
WIN.blit(Instructions, (WINDOWWIDTH + 10, 40))
WIN.blit(Instructions2, (WINDOWWIDTH + 10, 55))
WIN.blit(Path, (WINDOWWIDTH + 10, 70))
if Found:
counter = 1
for Cord in board.Path:
if not(70 + counter * 15 > WINDOWHEIGHT):
text = myfont.render("{0}: {1}".format(counter, str(Cord)), 0, BLACK)
WIN.blit(text, (WINDOWWIDTH + 10, 70 + counter * 15))
counter += 1
pygame.display.update()
#Event Loop
keysPressed = pygame.key.get_pressed()
board.changeNodeState(keysPressed)
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
'''if event.type == pygame.MOUSEBUTTONDOWN:
row, col = get_row_col_from_mouse(pygame.mouse.get_pos())
if row != -1 and col != -1:
board.changeNodeState(col, row)
'''
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_RETURN:
if board.runSimulation():
Found = True
if event.key == pygame.K_BACKSPACE:
Found = False
board.reset()
pygame.quit()
main()