I'm in the process of making a text based game. Each screen tells you what is going on and you're given the option of what to do in the form of buttons presented to you. It's been working fine so far but I've gotten to a point where I want there to be what is essentially a game of rock paper scissors but dressed up a bit. However when I got to this point it would repeatedly loop through the options that are presented. I fixed this by adding in a section of code that makes the program wait. But when I want it to progress it requires another mouse click which then messes with the whole flow of the program.
def hblock():
Hero.brawlchoice = 3
BVariables.turn = 2
objects.clear()
def vupcut():
but = Button(10,410,360,130,upcut,null)
but2 = Button(410,410,360,30,heroch1,hupcut)
but3 = Button(410,450,360,30,heroch2,hjab)
but4 = Button(410,490,360,30,heroch3,hblock)
but.draw(screen)
but2.draw(screen)
but3.draw(screen)
but4.draw(screen)
event_happened = False
while not event_happened:
event = pygame.event.wait()
if event.type == pygame.MOUSEBUTTONDOWN:
event_happened = True
def vuhu():
but = Button(10,410,360,130, bothupcut, null)
but2 = Button(410,410,360,130, "Next.", brawl)
but.draw(screen)
but2.draw(screen)
Hero.health = Hero.health - 3
Vasher.health = Vasher.health - 3
BVariables.turn = 1
event_happened = False
while not event_happened:
event = pygame.event.wait()
if event.type == pygame.MOUSEBUTTONDOWN:
event_happened = True
def brawl():
objects.clear()
if gameover == 1 and BVariables.turn == 1:
global x
x = random.choice(Vasher.options)
if x == "Uppercut":
vupcut()
elif x == "Jab":
vjab()
else:
vblock()
if BVariables.turn == 2 and gameover == 1:
if x == "Uppercut" and Hero.brawlchoice == 1:
objects.clear()
vuhu()
elif x == "Uppercut" and Hero.brawlchoice == 2:
objects.clear()
vuhj()
elif x == "Uppercut" and Hero.brawlchoice == 3:
objects.clear()
vuhb()
elif x == "Jab" and Hero.brawlchoice == 1:
objects.clear()
vjhu()
elif x == "Jab" and Hero.brawlchoice == 2:
objects.clear()
vjhj()
elif x == "Jab" and Hero.brawlchoice == 3:
objects.clear()
vjhb()
elif x == "Block" and Hero.brawlchoice == 1:
objects.clear()
vbhu()
elif x == "Block" and Hero.brawlchoice == 2:
objects.clear
vbhj()
elif x == "Block" and Hero.brawlchoice == 3:
objects.clear
vbhb()
This is a pared down example of the code I'm using for this little fight section of the program. All I want is it for it to be a turn based game where the computer randomly selects a choice, the player is given a small hint of what they plan to do and then can choose their own choice in response but as the code currently is in order for it to progress you have to click the mouse again which changes what the computer's choice so messes up the whole point of the game. As well as this sometimes buttons will appear on top of others so nothing is readable. I can't figure out why any of this happens or how to fix it so any help would be greatly appreciated.