I created own game, however, I don't still know and understand how to create function 'Again' when I click on button. How to create it? My part code:
import pygame
def beginning():
Beginning = True
while Beginning and not QuitState.quit:
clock.tick(FPS)
for event in pygame.event.get():
#[...]
if event.type == pygame.QUIT:
QuitState.set_quit()
mini_button = Button(230, 80)
screen.blit(important_phone_jpg, important_phone_rect)
print_text_5('Выживание с Соником', 320, 50)
mini_button.draw(535, 170, 'Играть', game1)
mini_button1 = Button(440, 80)
pygame.display.update()
def game1():
global health
Game = True
while Game and not QuitState.quit:
clock.tick(FPS)
for event in pygame.event.get():
#[...]
if event.type == pygame.QUIT:
QuitState.set_quit()
if player.score >= 900:
victory1()
if health <= 0:
game_over1()
show_health()
button = Button(195,80)
button.draw(20, 80, 'Пауза', pause1)
print_text('Очки ' + str(player.score), 725, 25)
print_text(':', 840, 25)
pygame.display.update()
all_sprites.update()
screen.blit(morning_png, morning_rect)
all_sprites.draw(screen)
def pause1():
Pause = True
while Pause and not QuitState.quit:
clock.tick(FPS)
for event in pygame.event.get():
if event.type == pygame.QUIT:
QuitState.set_quit()
screen.blit(phone_jpg, phone_rect)
buttonq = Button(120, 80)
print_text_2('Хотите продолжить игру?', 400, 270)
buttonq.draw(300, 340, 'Да!', game1)
buttonq_1 = Button(140, 80)
buttonq_1.draw(870, 340, 'Нет!', beginning)
pygame.display.update()
def game_over1():
Game_over = True
while not QuitState.quit:
clock.tick(FPS)
for event in pygame.event.get():
if event.type == pygame.QUIT:
QuitState.set_quit()
screen.blit(game_over_jpg, game_over_rect)
button_5 = Button(235,80)
print_text_3('К сожалению, вы проиграли! Попробуйте ещё раз!', 135, 400)
button_5.draw(400, 500, 'Заново', game1)
button_5.draw(700, 500, 'Назад', beginning)
pygame.display.update()
def victory1():
Victory = True
while Victory and not QuitState.quit:
clock.tick(FPS)
for event in pygame.event.get():
if event.type == pygame.QUIT:
QuitState.set_quit()
screen.blit(victory_jpg, victory_rect)
button_5 = Button(205,90)
print_text('Ура! Вы победили! Мои поздравления! Хотите сыграть ещё раз?', 280, 360)
button_5.draw(450, 500, 'Да', game1)
button_5.draw(650, 500, 'Нет', beginning)
pygame.display.update()
beginning()
pygame.quit()
*I want to player had ability to play again when click on buttons: 'button_5.draw(450, 500, 'Да', game1)' 'button_5.draw(400, 500, 'Заново', game1)' or when player quit from game1 and play again: 'mini_button.draw(535, 170, 'Играть', game1)'