I am doing a math program for my school project, and I have already prepared the menu for the game and the process of the game, that basically consists in doing endless loop of sums till you fail, giving you 5 points for every correct answer (in the future I have planned to connect it to a SQLite base, because it asks you a name and your age). Anyway, here are the code of the sums and the menu:
https://www.sololearn.com/Discuss/2848691/help-me-to-turn-this-into-a-function-and-make-this-infinite-school-project https://www.sololearn.com/Discuss/2856421/making-the-school-project-menu-with-pygame-menu-school-project
[Updated] The problem consists in when I try to make the code of the sums to appear in the window that the menu produces after pressing 'Comencem', the sums appear in the Python Console, but not in the window. I would like it to appear in the window, but I don't know how to do it. Any help please?
import pygame
import pygame_menu
from pygame import mixer
import random
pygame.init()
#Mida i nom de la finestra
surface = pygame.display.set_mode((600, 400))
pygame.display.set_caption("Projecte MatZanfe")
#Logotip de la finestra
logotip = pygame.image.load("calculator.png")
pygame.display.set_icon(logotip)
font = pygame_menu.font.FONT_8BIT
font1 = pygame_menu.font.FONT_NEVIS
def start_the_game():
# Variables
puntuacio = 0
while True:
x = random.randint(0, 10)
y = random.randint(0, 10)
z = x + y
print(str(x) + "+" + str(y))
resultat = int(input())
if resultat == z:
print("Correcte")
puntuacio = puntuacio + 5
print("Tens aquests punts:", puntuacio)
else:
if resultat != z:
print("Malament!")
parar = input("Vols parar? ")
if parar == ("si"):
print("Has aconseguit " + str(puntuacio) + " punts")
break
else:
continue
menu = pygame_menu.Menu('Projecte MatZanfe', 600, 400,
theme=pygame_menu.themes.THEME_SOLARIZED)
menu.add.text_input('Usuari: ', font_name = font1, font_color = 'blue')
mixer.music.load('MusicaMenu.wav')
mixer.music.play(-1)
menu.add.text_input('Edat: ', font_name = font1,font_color = 'Black')
menu.add.button('Comencem', start_the_game,font_name = font, font_color = 'green')
menu.add.button('Sortir', pygame_menu.events.EXIT, font_name = font,font_color = 'red')
menu.mainloop(surface)
(Some words are in catalan but I think you can understand them. I will change it if you can't).