Skip to content

Commit

Permalink
core/fix: updated visuals, fixed bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
marhcouto committed Mar 26, 2023
1 parent fa33356 commit a2578aa
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 33 deletions.
Binary file modified assets/img/backspace.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/img/esc.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/img/info.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/img/light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified robot_mazes_linux
Binary file not shown.
23 changes: 9 additions & 14 deletions src/controller/game_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,29 +142,28 @@ def game_win(self):
super().game_win()

def tips(self):
index = 1
wrong = False
if self.__results is None:
self.__results: AlgorithmStats = self._algorithm(self._game_model)
i = 0
for i in range(len(self._moves)):
if self._moves[i] != self.__results.solution_state.moves[i]:
wrong = True
break
index = i + 1
index = i + 1
if wrong:
self.__game_view.tips("Change the direction number {}".format(index))
self.__game_view.tips(" Change the direction number {} ".format(index))
elif len(self._moves) != self._game_model.no_moves:
self.__game_view.tips("Add more moves")
self.__game_view.tips(" Add more moves ")
else:
self.__game_view.tips("You might have done it")
self.__game_view.tips(" You might have done it! ")
pygame.display.update()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
quit()
keys = pygame.key.get_pressed()
if keys[pygame.K_ESCAPE] or keys[pygame.K_BACKSPACE] or keys[pygame.K_RETURN]:
return
if event.type == pygame.KEYDOWN or event.type == pygame.MOUSEBUTTONDOWN:
return

def instructions(self):
self.__game_view.instructions()
Expand All @@ -173,10 +172,6 @@ def instructions(self):
for event in pygame.event.get():
if event.type == pygame.QUIT:
quit()
keys = pygame.key.get_pressed()
if keys[pygame.K_ESCAPE] or keys[pygame.K_BACKSPACE] or keys[pygame.K_RETURN]:
return



if event.type == pygame.KEYDOWN or event.type == pygame.MOUSEBUTTONDOWN:
return

50 changes: 31 additions & 19 deletions src/view/game_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,16 @@ def draw_static(self):

self._build()

moves_string = 'Moves: {}'.format(self.model[1])
moves_string_1 = 'Moves:'
moves_string_2 = '{}'.format(self.model[1])

text = pygame.font.Font(None, 48).render(moves_string, True, COLOR, BACKGROUND)
self._surface.blit(text, (30, 10))
font_underlined = pygame.font.Font(None, 48)
font_underlined.set_underline(True)

text1 = font_underlined.render(moves_string_1, True, COLOR, BACKGROUND)
text2 = pygame.font.Font(None, 48).render(moves_string_2, True, COLOR, BACKGROUND)
self._surface.blit(text1, (30, 10))
self._surface.blit(text2, (150, 10))

x = 20
y = 50
Expand Down Expand Up @@ -139,21 +145,27 @@ def draw_static(self):

if self.model is None:
return


font_underlined = pygame.font.Font(None, 32)
font_underlined.set_underline(True)

data = [
"Execution Time: {0} ms".format(self.model.time),
"Iterations: {0}".format(self.model.iterations),
"Solution Depth: {0}".format(len(self.model.solution_history)),
"Found Solution: {0}".format(self.__render_solution())
("Execution Time:", " {0} ms".format(self.model.time)),
("Iterations:", " {0}".format(self.model.iterations)),
("Solution Depth:", " {0}".format(len(self.model.solution_history))),
("Found Solution:", " {0}".format(self.__render_solution()))
]

text = pygame.font.Font(None, 48).render("Algorithm Stats:", True, COLOR, BACKGROUND)
self._surface.blit(text, (30, 200))

y = 240
for sentence in data:
text = pygame.font.Font(None, 32).render(sentence, True, COLOR, BACKGROUND)
self._surface.blit(text, (30, y))
text1 = font_underlined.render(sentence[0], True, COLOR, BACKGROUND)
text2 = pygame.font.Font(None, 32).render(sentence[1], True, COLOR, BACKGROUND)
self._surface.blit(text1, (30, y))
self._surface.blit(text2, (14*len(sentence[0]), y))
y += 30

def __render_solution(self):
Expand Down Expand Up @@ -198,7 +210,10 @@ def draw_dynamic(self, position: Position):

def draw_win(self):
surface_w, _ = self._surface.get_size()
text = pygame.font.Font(None, 64).render("Maze Complete!", True, RED, COLOR)
font = pygame.font.Font(None, 80)
font.set_underline(True)
font.set_bold(True)
text = font.render("Maze Complete!", True, COLOR, BACKGROUND)
self._surface.blit(text, ((surface_w - text.get_size()[0]) // 2, 200))

def draw_buttons(self):
Expand Down Expand Up @@ -231,13 +246,13 @@ def tips(self, tip: str):

def instructions(self):
text = []
text.append(pygame.font.Font(None, 30).render(" - Arrow keys or buttons to", True, COLOR, BACKGROUND))
text.append(pygame.font.Font(None, 30).render("choose directions.", True, COLOR, BACKGROUND))
text.append(pygame.font.Font(None, 30).render(" - Backspace or button to", True, COLOR, BACKGROUND))
text.append(pygame.font.Font(None, 30).render("remove them.", True, COLOR, BACKGROUND))
text.append(pygame.font.Font(None, 30).render(" - Enter or button to make", True, COLOR, BACKGROUND))
text.append(pygame.font.Font(None, 30).render(" - Arrow keys or arrow buttons", True, COLOR, BACKGROUND))
text.append(pygame.font.Font(None, 30).render("to choose directions.", True, COLOR, BACKGROUND))
text.append(pygame.font.Font(None, 30).render(" - Backspace or backspace button", True, COLOR, BACKGROUND))
text.append(pygame.font.Font(None, 30).render("to remove them.", True, COLOR, BACKGROUND))
text.append(pygame.font.Font(None, 30).render(" - Enter or enter button to make", True, COLOR, BACKGROUND))
text.append(pygame.font.Font(None, 30).render("the robot cycle.", True, COLOR, BACKGROUND))
text.append(pygame.font.Font(None, 30).render(" - Escape or button to exit", True, COLOR, BACKGROUND))
text.append(pygame.font.Font(None, 30).render(" - Escape or escape button to exit", True, COLOR, BACKGROUND))
text.append(pygame.font.Font(None, 30).render("to menu.", True, COLOR, BACKGROUND))
text.append(pygame.font.Font(None, 30).render(" - I or lightbulb button for tips.", True, COLOR, BACKGROUND))
y = 105
Expand All @@ -250,9 +265,6 @@ def instructions(self):






class IAView(View):

def __init__(self, surface: pygame.Surface, model):
Expand Down

0 comments on commit a2578aa

Please sign in to comment.