]> Skullheadx's Git Forge - word-hunt.git/commitdiff
unknown word list added
authorSkullheadx <94652084+Skullheadx@users.noreply.github.com>
Thu, 24 Nov 2022 20:48:35 +0000 (15:48 -0500)
committerSkullheadx <94652084+Skullheadx@users.noreply.github.com>
Thu, 24 Nov 2022 20:48:35 +0000 (15:48 -0500)
Main/__pycache__/game.cpython-310.pyc
Main/__pycache__/setup.cpython-310.pyc
Main/__pycache__/tile.cpython-310.pyc
Main/__pycache__/words_display.cpython-310.pyc [new file with mode: 0644]
Main/game.py
Main/main.py
Main/setup.py
Main/tile.py
Main/words_display.py [new file with mode: 0644]

index e1d42ecda27c91cf132299bd4ede3f6058475007..b47c4e2aabc74fa44ded3314e5b4f0689b42d9dd 100644 (file)
Binary files a/Main/__pycache__/game.cpython-310.pyc and b/Main/__pycache__/game.cpython-310.pyc differ
index da7e2e200e6ebbdafcd87c1d62dfb2c840312fb9..800458e329af3a0f5b2059fd6a639f2453d9dd37 100644 (file)
Binary files a/Main/__pycache__/setup.cpython-310.pyc and b/Main/__pycache__/setup.cpython-310.pyc differ
index 590779ff1db69cd5ada86530996312de18c9fb88..c274cebdb90fae9b13ce7eb127f94d1fbd0428bb 100644 (file)
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 (file)
index 0000000..be2ef95
Binary files /dev/null and b/Main/__pycache__/words_display.cpython-310.pyc differ
index 3eca2f20abc886203d593873ac7f8bfcc326e12d..cddbd90ed05a4126ca4bfaa92efa7816a2c242d3 100644 (file)
@@ -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))
index ba48ecbd53285494d04f076b0e850acfe1bf6dc4..cb2310faa22e8af0ce0f31deaa443497b844557e 100644 (file)
@@ -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)
 
index ce10e43725c4c58d62deeafff6c76111e90f7f5d..6f7e4e10b35e41e7cf0dd453b4b0b0f60a3fb4e7 100644 (file)
@@ -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()
index 6a61090539c3ecdf343b21fe0992aadb9dd2ed63..e366cc2cb56b6283f976d8d5681a21674ff2cd2f 100644 (file)
@@ -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 (file)
index 0000000..56d6c94
--- /dev/null
@@ -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