mardi 17 août 2021

How to STOP generating numbers

I have made a code that renders 2 different random numbers on screen, but it justs keep updating the numbers. I want the program to stop updating those numbers once the first 2 appear on screen. Here is the code:

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
    is_correct = False
    points = 0
    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,(260,120))
    input_rect.w = max(100,text_surface.get_width()+10)

running = True
while running:
    clock.tick(60)
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
    start_the_game()
    pygame.display.update()
pygame.quit()

Maybe using an if statement would be the solution, but I can't figure out where and what should I introduce to the code. How would you do it?




Aucun commentaire:

Enregistrer un commentaire