From: Skullheadx <94652084+Skullheadx@users.noreply.github.com> Date: Thu, 24 Nov 2022 20:48:35 +0000 (-0500) Subject: unknown word list added X-Git-Url: http://git.skullheadx.com/now.html?a=commitdiff_plain;h=fe6be98f26cfde3a379db40992e1efdd637b3e09;p=word-hunt.git unknown word list added --- diff --git a/Main/__pycache__/game.cpython-310.pyc b/Main/__pycache__/game.cpython-310.pyc index e1d42ec..b47c4e2 100644 Binary files a/Main/__pycache__/game.cpython-310.pyc and b/Main/__pycache__/game.cpython-310.pyc differ diff --git a/Main/__pycache__/setup.cpython-310.pyc b/Main/__pycache__/setup.cpython-310.pyc index da7e2e2..800458e 100644 Binary files a/Main/__pycache__/setup.cpython-310.pyc and b/Main/__pycache__/setup.cpython-310.pyc differ diff --git a/Main/__pycache__/tile.cpython-310.pyc b/Main/__pycache__/tile.cpython-310.pyc index 590779f..c274ceb 100644 Binary files a/Main/__pycache__/tile.cpython-310.pyc and b/Main/__pycache__/tile.cpython-310.pyc differ diff --git a/Main/__pycache__/words_display.cpython-310.pyc b/Main/__pycache__/words_display.cpython-310.pyc new file mode 100644 index 0000000..be2ef95 Binary files /dev/null and b/Main/__pycache__/words_display.cpython-310.pyc differ diff --git a/Main/game.py b/Main/game.py index 3eca2f2..cddbd90 100644 --- a/Main/game.py +++ b/Main/game.py @@ -1,8 +1,10 @@ +import pygame + from setup import * from tile import Tile from board import Board from word_connector import WordConnector - +from words_display import UnknownWordDisplay class Game: font = pygame.font.Font("font/Silkscreen-Regular.ttf", 40) @@ -15,7 +17,10 @@ class Game: colour_converter = {correct_colour: True, found_colour: False, wrong_colour: False} - + word_disp_separation_distance = 30 + bezel = 3 + edge_radius = 10 + inset = 5 def __init__(self, imported_file_name=None): if imported_file_name is None: length, width = 4, 4 @@ -32,13 +37,17 @@ class Game: self.seen = set() self.points = 0 self.title = self.title_font.render("Word Hunt", True, Colour.BLACK) - self.board = Board(pygame.Vector2(SCREEN_WIDTH / 2, SCREEN_HEIGHT *3/5), length, width, self.letters) + self.board = Board(pygame.Vector2(SCREEN_WIDTH / 3, SCREEN_HEIGHT *3/5), length, width, self.letters) + self.word_frequency = {i+1:0 for i in range(length * width)} + for i in self.word_list: + self.word_frequency[len(i)] += 1 self.word = "" self.word_display = self.font.render(self.word, True, Colour.BLACK, Colour.LIGHT_GRAY) self.word_connector = WordConnector() self.bg_colour = Colour.LIGHT_GRAY + self.unknown_word_display = UnknownWordDisplay((SCREEN_WIDTH*2/3-UnknownWordDisplay.inset,self.board.position.y),self.word_frequency) def update(self, delta): self.word += self.board.update(delta, self.bg_colour, self.points) @@ -55,23 +64,31 @@ class Game: self.word = "" self.word_connector.reset() + + self.unknown_word_display.update(delta,self.seen) self.bg_colour = self.wrong_colour + if self.word in self.seen: self.bg_colour = self.found_colour elif self.word in word_list: self.bg_colour = self.correct_colour - self.word_display = self.font.render(self.word, True, Colour.BLACK, self.bg_colour) + self.word_display = self.font.render(self.word, True, Colour.BLACK) def draw(self, surf): surf.fill(Palette.primary_shade1) self.board.draw(surf) - surf.blit(self.word_display, self.word_display.get_rect(center=(center.x, SCREEN_HEIGHT / 5))) + r = self.word_display.get_rect(center=(center.x, -self.word_display.get_height()/2 + self.board.get_rect().top - self.word_disp_separation_distance)) + bgr = pygame.Rect(r.left-self.inset,r.top,r.width + self.inset*2, r.height) + pygame.draw.rect(surf,self.bg_colour,bgr, border_radius=self.edge_radius) + pygame.draw.rect(surf,Colour.DARK_GRAY,bgr, width = self.bezel,border_radius=self.edge_radius) + surf.blit(self.word_display, r) surf.blit(self.title, self.title.get_rect(center=(center.x, SCREEN_HEIGHT / 10))) self.word_connector.draw(surf) + self.unknown_word_display.draw(surf) # pygame.draw.circle(surf, Colour.WHITE,r.center,5) # pygame.draw.line(surf, Colour.BLACK, (0, SCREEN_HEIGHT / 2), (SCREEN_WIDTH, SCREEN_HEIGHT / 2)) diff --git a/Main/main.py b/Main/main.py index ba48ecb..cb2310f 100644 --- a/Main/main.py +++ b/Main/main.py @@ -1,7 +1,7 @@ from setup import * from game import Game -puzzle = f"puzzles/PuzzlePack{4}/puzzle{4}.txt" +puzzle = f"puzzles/PuzzlePack{4}/puzzle{10}.txt" print(puzzle) scene = Game(puzzle) diff --git a/Main/setup.py b/Main/setup.py index ce10e43..6f7e4e1 100644 --- a/Main/setup.py +++ b/Main/setup.py @@ -13,7 +13,7 @@ pygame.init() SCREEN_WIDTH, SCREEN_HEIGHT = 720, 720 dimensions = pygame.Vector2(SCREEN_WIDTH, SCREEN_HEIGHT) center = pygame.Vector2(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2) -screen = pygame.display.set_mode(dimensions, pygame.RESIZABLE) +screen = pygame.display.set_mode(dimensions) pygame.display.set_caption("Word Hunt") clock = pygame.time.Clock() diff --git a/Main/tile.py b/Main/tile.py index 6a61090..e366cc2 100644 --- a/Main/tile.py +++ b/Main/tile.py @@ -3,7 +3,7 @@ import pygame.mouse from setup import * class Tile: - side_length = 85 + side_length = 80 bezel = 5 cutoff = 8 edge_radius = 15 diff --git a/Main/words_display.py b/Main/words_display.py new file mode 100644 index 0000000..56d6c94 --- /dev/null +++ b/Main/words_display.py @@ -0,0 +1,84 @@ +from setup import * + + +class ListDisplay: + font = pygame.font.Font("font/Silkscreen-Regular.ttf", 22) + + def __init__(self, position, frequencies): + self.position = pygame.Vector2(position) + self.frequencies = frequencies + self.display = [] + for i in self.frequencies: + self.display.append(self.font.render(f"({self.frequencies[i]}) {'?' * i}", True, Colour.BLACK)) + + def update(self, delta, seen): + f = {i + 1: 0 for i in range(16)} + for i in seen: + f[len(i)] += 1 + self.display = [] + for i in self.frequencies: + n = self.frequencies[i] - f[i] + if n > 0: + self.display.append(self.font.render(f"({n}) {'?' * i}", True, Colour.BLACK)) + + def get_rect(self): + def get_height(a): + return a.get_rect().height + + def get_width(a): + return a.get_rect().width + l,h = 0,0 + for i in self.display: + l =max(l, get_width(i)) + h += get_height(i) + + return pygame.Rect(self.position, (l,h)) + + def draw(self, surf): + prev = pygame.Vector2(self.position) + for i, val in enumerate(self.display): + if i == 0: + surf.blit(val, val.get_rect(topleft=self.position)) + + else: + surf.blit(val, prev) + prev.y += val.get_height() + +class UnknownWordDisplay: + font = pygame.font.Font("font/Silkscreen-Regular.ttf", 30) + title_font = pygame.font.Font("font/Silkscreen-Regular.ttf", 24) + inset = 15 + bezel = 5 + edge_radius = 15 + + def __init__(self, position, word_frequency): + self.position = pygame.Vector2(position) + self.word_frequency = word_frequency + self.words_found = 0 + self.total_words = sum(word_frequency.values()) + # self.title = self.title_font.render("Word Bank", True, Colour.DARK_GRAY) + self.title = self.title_font.render(f"Words: {self.words_found} / {self.total_words}", True, Colour.DARK_GRAY) + self.list_display = ListDisplay(self.position+ pygame.Vector2(0,self.title.get_height()/2), self.word_frequency) + + def update(self, delta, seen): + self.list_display.update(delta, seen) + self.words_found= len(seen) + self.title = self.title_font.render(f"Words: {self.words_found}/{self.total_words}", True, Colour.DARK_GRAY) + + def get_rect(self): + return pygame.Rect(self.position.x - self.inset, self.position.y - self.inset, + 2 * self.inset + max(self.title.get_width(), self.list_display.get_rect().width), + self.inset + self.list_display.get_rect().height + max(self.title.get_height(),self.inset)) + + 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(), width=self.bezel, border_radius=self.edge_radius) + self.list_display.draw(surf) + + + + surf.blit(self.title,self.title.get_rect(center=pygame.Vector2(self.position.x + self.get_rect().width/2 - self.inset,self.position.y + 0.5 * (self.list_display.position.y - self.position.y)))) +#self.position.y-self.inset + max(self.title.get_height(),self.inset)/2) + + # pygame.draw.circle(surf, Colour.RED,self.position, 4) + # pygame.draw.circle(surf, Colour.BLUE,self.list_display.position, 5) \ No newline at end of file