I need the following function to work:
import pygame
import random
pygame.init()
clock = pygame.time.Clock()
surface = pygame.display.set_mode((600, 400))
pygame.display.set_caption("Projecte MatZanfe")
font = pygame.font.SysFont('comicsans', 50)
base_font = pygame.font.Font(None, 32)
user_text = ''
color_active = pygame.Color('lightskyblue3')
def start_the_game():
# Variables
points = 0
while True:
x = random.randint(0, 10)
y = random.randint(0, 10)
z = x + y
surface.fill((255, 70, 90))
text = font.render(str(x) + "+" + str(y), True, (255, 255, 255))
input_rect = pygame.Rect(200, 200, 180, 50)
pygame.draw.rect(surface, color_active,input_rect)
text_surface = base_font.render(user_text,True,(255,255,255))
surface.blit(text_surface, input_rect)
surface.blit(text, (0, 0))
pygame.display.update()
result = int(input())
for event in pygame.event.get():
if event.type == pygame.QUIT:
exit()
if result == z:
print("Correct")
points += 5
print("You have this many points: ", points)
else:
if result != z:
print("Wrong!")
parar = input("Would you like to stop? ")
if parar == "yes":
print("You have made " + str(points) + "points")
break
else:
continue
start_the_game()
At the moment the window just freezes. I have been told that the inputs are the problems, so I have thought of adding an entry box to make it work. However, I don't know how could I continue from here. I need to use the input box at every input that the program requires right now, but I don't know how to do it. Any tips?