-
Notifications
You must be signed in to change notification settings - Fork 8
/
game1.py
116 lines (93 loc) · 3.36 KB
/
game1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
from random import randint
from tkinter import *
from PIL import Image,ImageTk
# main windo
root=Tk()
root.title("Rock Scissor Paper")
root.configure(background="purple")
#picture
rock_img=ImageTk.PhotoImage(Image.open("rock-user.png"))
scissor_img=ImageTk.PhotoImage(Image.open("scissor-user.png"))
paper_img=ImageTk.PhotoImage(Image.open("paper-user.png"))
rock_img_comp=ImageTk.PhotoImage(Image.open("rock.png"))
scissor_img_comp=ImageTk.PhotoImage(Image.open("scissor.png"))
paper_img_comp=ImageTk.PhotoImage(Image.open("paper.png"))
#Insert picture
user_label=Label(root,image=paper_img,bg="purple")
comp_label=Label(root,image=paper_img_comp,bg="purple")
comp_label.grid(row=1,column=0)
user_label.grid(row=1,column=4)
#scores
playerscore=Label(root,text="",font=100,bg="purple",fg="white")
computerscore=Label(root,text="",font=100,bg="purple",fg="white")
playerscore.grid(row=1,column=1)
computerscore.grid(row=1,column=3)
#indicators
user_indicator=Label(root,font=50,text="USER",bg="purple",fg="white").grid(row=0,column=3)
comp_indicator=Label(root,font=50,text="COMPUTER",bg="purple",fg="white").grid(row=0,column=1)
#message
msg=Label(root,font=50,bg="purple",fg="white").grid(row=3,column=2)
#update message
def updatemessage(x):
msg ['text'] = x
#update user score
def updateUserscore ():
score=int (playerscore["text"])
score += 1
playerscore ["text"]=str(score)
#update computer score
def updateCompscore():
score=int (computerscore["text"])
score += 1
computerscore ["text"]=str(score)
# check winner
def checkwinner(Player,Computer):
if Player== Computer:
updatemessage("its tie!!")
elif Player == "rock":
if Computer == "paper":
updatemessage("You loose")
updateCompscore()
else:
updatemessage("You Win")
updateUserscore()
elif Player=="paper":
if Computer == "scissor":
updatemessage("You loose")
updateCompscore()
else:
updatemessage("You Win")
updateUserscore()
elif Player=="scissor":
if Computer == "rock":
updatemessage("You loose")
updateCompscore()
else:
updatemessage("You Win")
updateUserscore()
else:
pass
#update choice
choice=["rock","paper","scissor"]
def updatechoice(x):
#for computer
comchoice=choice[randint(0,2)]
if comchoice=="rock":
comp_label.configure(image=rock_img_comp)
elif comchoice=="paper":
comp_label.configure(image=paper_img_comp)
else:
comp_label.configure(image=scissor_img_comp)
#for user
if x=="rock":
user_label.configure(image=rock_img)
elif x=="paper":
user_label.configure(image=paper_img)
else:
user_label.configure(image=scissor_img)
checkwinner(x,comchoice)
#buttons
rock=Button(root,width=20,height=2,text="ROCK",bg="pink",fg="white",command= lambda:updatechoice("rock")).grid(row=2,column=1)
paper=Button(root,width=20,height=2,text="PAPER",bg="yellow",fg="white",command= lambda:updatechoice("paper")).grid(row=2,column=2)
scissor=Button(root,width=20,height=2,text="SCISSORS",bg="skyblue",fg="white",command= lambda:updatechoice("scissor")).grid(row=2,column=3)
root.mainloop()