jeudi 20 août 2020

Hey, How do I write rules for a Rock, Paper, Scissor that I've been writing with tkinter in python?

So, I've been trying to write a Rock, paper and scissor game with tkinter to learn python. And I have made the GUI and the bot displays different moves after each the button click. However, the changing buttons don't affect the scoreboard. I need help writing the rules since I'm new at coding. Please take a look at the code.

 # pictures on buttons
photo1 = PhotoImage(file=r"E:\ROCK.png")
photoimage = photo1.subsample(9, 9)
photo2 = PhotoImage(file=r"E:\download.png")
photoimage1 = photo2.subsample(4, 4)
photo3 = PhotoImage(file=r"E:\SCISSOR.png")
photoimage2 = photo3.subsample(4, 4)

 



#bot's move

global list
global choice
list = [1, 2, 3, 1, 2, 3, 1, 2, 3]
choice = random.choice(list)



 

global move
global imgbot
global bmove
bmove = int(choice)

#function of buttons

#function of Rock
def click():
    global move, imgbot, choice, i
    i = 1
    move = 1


    if choice == 1:
        imgbot = photoimage

    if choice == 2:
        imgbot = photoimage1

    if choice == 3:
        imgbot = photoimage2
    if move == 1 or move == 2 or move == 3:
        choice = random.choice(list)
        botmove.config(image=imgbot)


#function of paper
def click1():
    global move, imgbot, choice, i
    i = 2
    move = 2
    if choice == 1:
        imgbot = photoimage

    if choice == 2:
        imgbot = photoimage1

    if choice == 3:
        imgbot = photoimage2
    if move == 1 or move == 2 or move == 3:
        botmove.config(image=imgbot)
        choice = random.choice(list)



#function of scissor
def click2():
    global move, imgbot, choice, i
    i = 3
    move = 3
    if choice == 1:
        imgbot = photoimage

    if choice == 2:
        imgbot = photoimage1

    if choice == 3:
        imgbot = photoimage2
    if move == 1 or move == 2 or move == 3:
        botmove.config(image=imgbot)
        choice = random.choice(list)



  



 # components

#Score board
scorep = 0
scoreb = 0
Scoreboard = Label(window, text=str("BOT- ") + str(scoreb) + str(":") + str(scorep) + str(" -YOU "))

#other components
button2 = Button(window, text="Close Game", command=close, padx=20)
botmove = Button(window, padx=20, pady=20, image=photoimage3)
prock = Button(window, image=photoimage, command=click)
ppaper = Button(window, image=photoimage1, command=click1)
pscissor = Button(window, image=photoimage2, command=click2)

I want to be able to continuously update the score as they win or lose and display "WIN", "LOSE" or "DRAW", I can do the positioning myself. I defined move as an integer so that I could write "if move-bmove = something then display win, or lose or draw". There is a global variable "i" because I was playing around with other ways of doing this but they failed so you can ignore "i". I did not include the whole code, only the important bits and necessary context.

I hope you understand my problem. Thanks for your help.

Aucun commentaire:

Enregistrer un commentaire