from gpiozero import LED, Button
from time import sleep
from random import uniform
from sys import exit

left_name = input('left player name is ')
right_name = input('right player name is ')

score_left = 0
score_right = 0

led = LED(4) #Setting the pin 4 as the LED output
right_button = Button(15)  # Setting the buttons as an input 
left_button = Button(14)
led.on() #Turning it on
sleep(uniform(5, 10))  #In order to play tha game we set the sleeping time to be random
led.off() # turning the LED off

def pressed(button):
    global score_left
    global score_right
    if button.pin.number == 14:
        print(left_name + ' won the game')
        score_left +=1
        print('Current score:' + repr(score_left))
    else:
        print(right_name+ ' won the game')
        score_right +=1
        print('Current score:' + repr(score_right))
    #exit()    If you want the game to only be played once you call exit()


while True:
    #print("Inside the while")
    right_button.when_pressed = pressed
    left_button.when_pressed = pressed


    time.sleep(1)