New to programming, please bear with me.......
I have a rock/paper/scissors game that works perfectly. I know I probably could have done it with 10% of the code I actually used, but please use my code to explain to me, it's how I understand it at the moment. I want to add a button (GPIO03) somewhere in the code to quit the game completely. I have, for 2 days, tried everything. but.is_pressed, but.wait_for_press etc. I just can't get it working. Maybe there is something I don't know about yet or I'm just using it wrong. Could someone please add or change the code to exit the game completely when the button is pressed anywhere in the game? I'm at my wits end......
from gpiozero import LED, Buzzer, Button
from time import sleep
buz = Buzzer(2)
but = Button(3)
def rps():
ledg = LED(15)
ledr = LED(14)
ledw = LED(18)
if p1 == 'r' and p2 == 'r':
print("Draw!!")
ledw.on()
sleep(3)
ledw.off()
elif p1 == 'p' and p2 == 'p':
print("Draw!!")
ledw.on()
sleep(3)
ledw.off()
elif p1 == 's' and p2 == 's':
print("Draw!!")
ledw.on()
sleep(3)
ledw.off()
elif p1 == 'r' and p2 == 'p':
print("P2 wins!!")
ledr.on()
sleep(3)
ledr.off()
elif p1 == 'r' and p2 == 's':
print("P1 wins!!")
ledg.on()
sleep(3)
ledg.off
elif p1 == 'p' and p2 == 'r':
print("P1 wins!!")
ledg.on()
sleep(3)
ledg.off
elif p1 == 'p' and p2 == 's':
print("P2 wins!!")
ledr.on()
sleep(3)
ledr.off()
elif p1 == 's' and p2 == 'r':
print("P2 wins!!")
ledr.on()
sleep(3)
ledg.off
elif p1 == 's' and p2 == 'p':
print("P1 wins!!")
ledg.on()
sleep(3)
ledr.off()
while True:
p1 = input("Choose r/p/s P1: (Type 'quit' to exit) ")
if p1 == 'r' or p1 == 'p' or p1 == 's':
pass
elif p1 == 'quit':
print("Bye!!")
break
else:
print("Invalid choice P1. Try again")
buz.on()
sleep(1)
buz.off()
continue
while True:
p2 = input("Choose r/p/s P2: (Type 'quit' to exit) ")
if p2 == 'r' or p2 == 'p' or p2 == 's':
pass
elif p2 == 'quit':
print("Chow!!")
return
else:
print("Invalid choice P2. Try again")
buz.on()
sleep(1)
buz.off()
continue
rps()
break
Thanks