--- /dev/null
+import pygame.mouse
+
+from setup import *
+
+
+class Button:
+ font = pygame.font.Font("font/Silkscreen-Regular.ttf", 20)
+
+ edge_radius = 5
+ bezel = 3
+
+ inset = 5
+
+ cooldown_time = 250
+
+ def __init__(self, position, text, colour):
+ self.colour = colour
+ self.text = self.font.render(text,True, self.colour)
+ self.position = position
+ self.selected = False
+
+ self.width = self.text.get_width() + self.inset * 2
+ self.height = self.text.get_height()
+
+ self.time = 0
+ self.cooldown = 0
+
+ def update(self, delta, new_text=None):
+ if new_text is not None:
+ self.text = self.font.render(new_text, True, self.colour)
+ self.cooldown = max(self.cooldown - delta, 0)
+ if self.cooldown == 0:
+ if pygame.mouse.get_pressed(3)[0] and self.get_rect().collidepoint(pygame.mouse.get_pos()):
+ self.selected = True
+ self.cooldown = self.cooldown_time
+ else:
+ self.selected = False
+
+ def get_rect(self):
+ return pygame.Rect(self.position.x - self.width/2,self.position.y - self.height/2, self.width,self.height)
+
+ def draw(self,surf):
+ pygame.draw.rect(surf,Colour.LIGHT_GRAY,self.get_rect(),border_radius=self.edge_radius)
+ pygame.draw.rect(surf,Colour.DARK_GRAY,self.get_rect(),border_radius=self.edge_radius,width=self.bezel)
+ surf.blit(self.text,self.text.get_rect(center=self.position))
\ No newline at end of file
--- /dev/null
+from setup import *
+from button import Button
+
+
+class Confirmation:
+ font = pygame.font.Font("font/Silkscreen-Regular.ttf", 25)
+ edge_radius = 10
+ bezel = 4
+ separation_distance = 10
+ inset = 15
+
+ def __init__(self):
+ self.position = center.copy()
+ self.text = self.font.render("Show Solutions?",True,Colour.BLACK)
+ self.accept_button = Button(self.position, "Accept",Colour.BLACK)
+ self.deny_button = Button(self.position, "Cancel",Colour.BLACK)
+ self.width = self.inset * 2 + self.accept_button.get_rect().width + self.deny_button.get_rect().width + self.separation_distance
+ self.height = self.inset * 2 + self.accept_button.get_rect().height + self.text.get_rect().height + self.separation_distance
+
+
+ def update(self, delta):
+ for event in pygame.event.get():
+ if event.type == pygame.QUIT:
+ return COMMAND_EXIT
+
+
+ if self.accept_button.update(delta):
+ return COMMAND_CONFIRMATION
+ if self.deny_button.update(delta):
+ return COMMAND_GAME
+ pass
+
+ def get_rect(self):
+ return pygame.Rect(self.position.x-self.width/2,self.position.y -self.height/2,self.width,self.height)
+
+ def draw(self,surf):
+ pygame.draw.rect(surf,Colour.LIGHT_GRAY,self.get_rect(),border_radius=self.edge_radius)
+ pygame.draw.rect(surf,Colour.LIGHT_GRAY,self.get_rect(),width=self.bezel,border_radius=self.edge_radius)
+ surf.blit(self.text, self.text.get_rect(center = (self.position.x,self.position.y - self.text.get_rect().height/2 - self.separation_distance/2)))
+ self.accept_button.draw(surf)
+ self.deny_button.draw(surf)
\ No newline at end of file
self.unknown_word_display = UnknownWordDisplay((SCREEN_WIDTH*2/3-UnknownWordDisplay.inset,self.board.position.y),self.word_frequency)
self.timer = Timer(self.unknown_word_display.position +pygame.Vector2(0,self.unknown_word_display.get_rect().height-self.unknown_word_display.inset + self.word_disp_separation_distance/2))
def update(self, delta):
+ for event in pygame.event.get():
+ if event.type == pygame.QUIT:
+ return COMMAND_EXIT
+ elif event.type == pygame.K_ESCAPE: # for testing purposes
+ return COMMAND_PAUSE
self.word += self.board.update(delta, self.bg_colour, self.points)
self.word_connector.update(self.board.grid.last_selected, self.colour_converter[self.bg_colour])
if not pygame.mouse.get_pressed(3)[0]: # mouse not down
if self.word in word_list and self.word not in self.seen:
self.seen.add(self.word)
- # self.points += 10 ** (len(self.word) - 2)
- if len(self.word) == 3:
- self.points += 100
- else:
- self.points += 100 * 2 ** (len(self.word) - 2)
+ self.points += 100 * 2 ** (len(self.word) - 3)
+ # if len(self.word) == 3:
+ # self.points += 100
+ # else:
+ # self.points += 100 * 2 ** (len(self.word) - 2)
# self.points_display = self.text_font.render(f"Score: {self.points}", True, Colour.BLACK)
self.word = ""
self.word_display = self.font.render(self.word, True, Colour.BLACK)
self.timer.update(delta, self.unknown_word_display.position +pygame.Vector2(0,self.unknown_word_display.get_rect().height-self.unknown_word_display.inset + self.word_disp_separation_distance/2))
+ def get_next_scene(self):
+ return COMMAND_CONFIRMATION
+
def draw(self, surf):
surf.fill(Palette.primary_shade1)
from setup import *
from game import Game
+from confirmation import Confirmation
puzzle = f"puzzles/PuzzlePack{4}/puzzle{13}.txt"
print(puzzle)
is_running = True
delta = 1000/fps
+paused = False
+paused_scene = None
+
while is_running:
- # screen.fill(Colour.WHITE)
- if pygame.event.peek(pygame.QUIT):
+ status = scene.update(delta)
+
+ if status == COMMAND_EXIT:
is_running = False
+ elif status == COMMAND_PAUSE:
+ paused = not paused
+ if paused:
+ paused_scene = scene
+ status = scene.get_next_scene()
+ else:
+ scene = paused_scene
+ paused_scene = None
+ # Switching scenes
+ if status == COMMAND_CONFIRMATION:
+ scene = Confirmation()
+
- scene.update(delta)
scene.draw(screen)
pygame.display.update()
clock = pygame.time.Clock()
fps = 60
+COMMAND_START = 0 # go to level select
+COMMAND_EXIT = 1 # quit
+COMMAND_GAME_OVER = 2 # go to game over screen
+COMMAND_PAUSE = 3 # Pause game
+COMMAND_CONFIRMATION = 4 # Confirm show solutions
+COMMAND_GAME = 5 # switch to actual game
+
alphabet = string.ascii_lowercase
weights = [8.464812190575197, 1.8290213382006486, 4.377463842181293, 3.238497204031964, 10.77374340292079,
1.1220794892410257, 2.3639146242995768, 2.64283880414943, 8.95783107183879, 0.15584834882323761,