Осталось добавить проверку на правильность сборки алфавита.
import pygame
import random
def generate_alf():
alf = 'абвгдеёжзийклмнопрстуфхцчшщъыьэюя'
new_text = ""
nindex = []
for i in range(0,len(alf)):
nindex.append(i)
for i in range(0,(len(alf))):
ind = random.randint(0,len(alf)-1)
n = nindex[ind]
nindex[ind] = nindex[i]
nindex[i] = n
for i in range(0,len(alf)):
sym = alf[nindex[i]]
new_text = new_text[:i] + sym + new_text[i:]
return new_text
WIDTH = 825
HEIGHT = 700
FPS = 60
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
RED = (255, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
pygame.init()
screen = pygame.display.set_mode((WIDTH, HEIGHT))
f1 = pygame.font.Font(None, 36)
f2 = pygame.font.Font(None, 100)
running = True
obj_y = 0
alf = generate_alf()
alf_2 = "".ljust(50)
symbol = ""
counter_symbols = 0
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.MOUSEBUTTONDOWN:
if event.button == 1:
x = event.pos[0]//25
symbol = alf[x]
print(symbol)
li = list(alf_2)
li[counter_symbols] = symbol
alf_2 = ''.join(li)
counter_symbols = counter_symbols+1
for it_1 in range(0,825,25):
for it_2 in range(0,50,25):
pygame.draw.rect(screen,WHITE, (it_1,it_2,24,24))
pygame.draw.rect(screen,WHITE, (0,50,825,700))
for i in range(0,len(alf)):
text1 = f1.render(alf[i], False,(0, 180, 0))
screen.blit(text1, (i*25,0))
text2 = f1.render(alf_2[i], False,(0, 180, 0))
screen.blit(text2, (i*25,25))
text3 = f2.render(symbol, False,(0, 180, 0))
screen.blit(text3, (400,400))
pygame.display.flip()
pygame.time.delay(250)
pygame.quit()
|