]> Skullheadx's Git Forge - word-hunt.git/commitdiff
import puzzle
authorSkullheadx <94652084+Skullheadx@users.noreply.github.com>
Mon, 21 Nov 2022 21:10:04 +0000 (16:10 -0500)
committerSkullheadx <94652084+Skullheadx@users.noreply.github.com>
Mon, 21 Nov 2022 21:10:04 +0000 (16:10 -0500)
Main/__pycache__/board.cpython-310.pyc
Main/__pycache__/game.cpython-310.pyc
Main/__pycache__/tile.cpython-310.pyc
Main/board.py
Main/game.py
Main/main.py
Main/puzzle_generator.py [new file with mode: 0644]
Main/puzzles/templates/puzzle.txt [new file with mode: 0644]
Main/tile.py

index 67a9d2c52d920244ccaa20bf7fc05002dbf3439f..f25d6f4acb44f9f7d072e741791a136d3a620e7d 100644 (file)
Binary files a/Main/__pycache__/board.cpython-310.pyc and b/Main/__pycache__/board.cpython-310.pyc differ
index 260740c39f690dfb3099bd6b09850640ccf13c7c..fc0e4e0d83b010c1b93d1e6b65be3402f45887c1 100644 (file)
Binary files a/Main/__pycache__/game.cpython-310.pyc and b/Main/__pycache__/game.cpython-310.pyc differ
index cb06862dd7b5790041213e73295340b0949e932f..450e962d029f0b585c829ba98dccdcdf9d60f1b1 100644 (file)
Binary files a/Main/__pycache__/tile.cpython-310.pyc and b/Main/__pycache__/tile.cpython-310.pyc differ
index 1c2c042d9a92c750ec51b81a79c22bfb843f1c0b..89f5f8b4077154306a70d6134704accf2ea3b2ed 100644 (file)
@@ -1,16 +1,15 @@
-import pygame
-
 from setup import *
 from tile import Tile
 
 
 class Board:
 
-    def __init__(self,position, length, width):
+    def __init__(self, position, length, width, letters):
         self.position = pygame.Vector2(position)
         self.length = length
         self.width = width
-        self.board = [[Tile((self.position.x + i * Tile.side_length,self.position.y + j * Tile.side_length)) for j in range(self.width)][:] for i in range(self.length)]
+        self.board = [[Tile((self.position.x + col * Tile.side_length, self.position.y + row * Tile.side_length),
+                            letters[row * self.width + col]) for col in range(self.width)][:] for row in range(self.length)]
 
         self.tiles = []
         for i in range(self.length):
@@ -22,16 +21,14 @@ class Board:
         letter = ""
         for tile in self.tiles:
             if self.last_selected is None:
-
-                l = tile.update(delta,tile.neighbors)
+                l = tile.update(delta, tile.neighbors)
             else:
-                l = tile.update(delta,self.last_selected.neighbors)
+                l = tile.update(delta, self.last_selected.neighbors)
             if l != "":
                 letter += l
                 self.last_selected = tile
 
-
-        if not pygame.mouse.get_pressed(3)[0]: # mouse not down
+        if not pygame.mouse.get_pressed(3)[0]:  # mouse not down
             for tile in self.tiles:
                 tile.reset()
             self.last_selected = None
@@ -39,11 +36,11 @@ class Board:
         return letter
 
     def draw(self, surf):
-        pygame.draw.rect(surf,Colour.BLACK,pygame.Rect(self.position-pygame.Vector2(Tile.bezel/2), (self.length * Tile.side_length+Tile.bezel, self.width*Tile.side_length +Tile.bezel)))
+        pygame.draw.rect(surf, Colour.BLACK, pygame.Rect(self.position - pygame.Vector2(Tile.bezel / 2), (
+            self.length * Tile.side_length + Tile.bezel, self.width * Tile.side_length + Tile.bezel)))
         for tile in self.tiles:
             tile.draw(surf)
         # debug
         # if self.last_selected is not None:
         #     for i in self.last_selected.neighbors:
         #         pygame.draw.rect(surf,Colour.BLUE,pygame.Rect(i,(Tile.side_length,Tile.side_length)),3)
-
index 9f8e11ed4670edcba15afd5db790e082cdb23c74..712ab32581b660ffedd840b8e62ec95848d0aabc 100644 (file)
@@ -1,21 +1,30 @@
-import pygame
-
 from setup import *
 from tile import Tile
 from board import Board
 
+
 class Game:
     font = pygame.font.Font("font/Silkscreen-Regular.ttf", 40)
 
-    def __init__(self):
-        self.board = Board(center - pygame.Vector2(2 * Tile.side_length),4,4)
+    def __init__(self, imported_file_name=None):
+        if imported_file_name is None:
+            length, width = 4,4
+            self.letters = [random.choice(alphabet) for i in range(length  * width)]
+        else:
+            with open(imported_file_name,"r") as f:
+                file_contents = f.read().split("\n")
+                length, width = tuple(map(int,file_contents[0].split()))
+                self.letters = file_contents[1]
+
+        self.board = Board(center - pygame.Vector2(2 * Tile.side_length), length, width, self.letters)
+
         self.word = ""
-        self.word_display = self.font.render(self.word,True,Colour.BLACK,Colour.LIGHT_GRAY)
+        self.word_display = self.font.render(self.word, True, Colour.BLACK, Colour.LIGHT_GRAY)
         self.seen = set()
 
     def update(self, delta):
         self.word += self.board.update(delta)
-        if not pygame.mouse.get_pressed(3)[0]: # mouse not down
+        if not pygame.mouse.get_pressed(3)[0]:  # mouse not down
             if self.word in word_list:
                 self.seen.add(self.word)
             self.word = ""
@@ -26,9 +35,8 @@ class Game:
         elif self.word in word_list:
             bg_colour = Colour.GREEN
 
-        self.word_display = self.font.render(self.word,True,Colour.BLACK,bg_colour)
-
+        self.word_display = self.font.render(self.word, True, Colour.BLACK, bg_colour)
 
     def draw(self, surf):
         self.board.draw(surf)
-        surf.blit(self.word_display, self.word_display.get_rect(center=(center.x,SCREEN_HEIGHT/5)))
+        surf.blit(self.word_display, self.word_display.get_rect(center=(center.x, SCREEN_HEIGHT / 5)))
index beee3c603060af13944e4d993db02f355066952c..3c0238c96c03a7f3a8b1cd2bc547b0887d254fe0 100644 (file)
@@ -4,7 +4,7 @@ from setup import *
 from game import Game
 
 
-scene = Game()
+scene = Game("puzzles/templates/puzzle.txt")
 
 is_running = True
 delta = 1000/fps
diff --git a/Main/puzzle_generator.py b/Main/puzzle_generator.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/Main/puzzles/templates/puzzle.txt b/Main/puzzles/templates/puzzle.txt
new file mode 100644 (file)
index 0000000..14c84b0
--- /dev/null
@@ -0,0 +1,2 @@
+4 4
+abcdefghijklmnop
\ No newline at end of file
index 82cd3dede7dc4e6e5b428d6f4ac2b1ec0f13dbf4..fb21c0aa3598b305bf3bf0335e6e69ef0b03e7b6 100644 (file)
@@ -5,13 +5,13 @@ from setup import *
 class Tile:
     side_length = 80
     bezel = 5
-    cutoff = 7.5
+    cutoff = 8
     font = pygame.font.Font("font/Silkscreen-Regular.ttf", 20)
 
-    def __init__(self, position):
+    def __init__(self, position, letter):
         self.position = pygame.Vector2(position)
         self.selected = False
-        self.letter = random.choice(alphabet)
+        self.letter = letter #random.choice(alphabet)
         self.text = self.font.render(self.letter,True, Colour.BLACK)
         self.neighbors = []
         for i in range(-1,2):