From 31b863b49b0e763a2e74d0eceb6a2134c18ed2c2 Mon Sep 17 00:00:00 2001 From: Brosef Date: Mon, 30 Jun 2025 14:43:15 +0100 Subject: [PATCH] Added auto-regeneration of captcha when complete This shit starting to look like a game lads --- game.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/game.py b/game.py index a2ae21b..25c939e 100644 --- a/game.py +++ b/game.py @@ -10,6 +10,10 @@ import json import time import os +# TODO: The current alphabets in the fonts.json file is kinda bullshit +# someone should probably play some test rounds and fix the diffuculty issue. +# TODO: Re-draw the captcha when a character is complete. + alphabet = string.ascii_letters + string.digits + string.punctuation def normalDist(difficulty): @@ -36,6 +40,7 @@ def PIL2PG(pilImage: Image) -> pygame.Surface: class Font: def __init__(self, data, fontSize): + self.path = data['file'] self.font = ImageFont.truetype(os.path.join('./fonts/', data['file']), fontSize) self.alphabet = data['alphabet'] self.difficulty = data['difficulty'] @@ -56,13 +61,16 @@ class Captcha: self.fonts.append(font) def match(self, char): + if self.charIdx == len(self.chars): + return True, True + matches = char.upper() == self.chars[self.charIdx] print(f'{char.upper()} == {self.chars[self.charIdx]}') if matches: self.charIdx += 1 - return True + return True, self.charIdx == len(self.chars) else: - return False + return False, self.charIdx == len(self.chars) class Game(gameUtils.Game): def __init__(self, *args, **kwargs): @@ -145,7 +153,8 @@ class Game(gameUtils.Game): # Store the created image self.currentCaptchaImg = PIL2PG(drawSurface) - print(captcha) + for char, font in zip(captcha.chars, captcha.fonts): + print(f'{char}: {font.path}') def onEvent(self, event): """ @@ -163,8 +172,12 @@ class Game(gameUtils.Game): print(self.gameDifficulty) elif event.key == pygame.K_F3: self.createCaptcha() + elif event.unicode != '' and event.unicode in alphabet: - print(self.currentCaptcha.match(event.unicode)) + correct, finished = self.currentCaptcha.match(event.unicode) + print(correct) + if finished: + self.createCaptcha() def update(self): """