Added auto-regeneration of captcha when complete
This shit starting to look like a game lads
This commit is contained in:
21
game.py
21
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):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user