-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFun_game.py
More file actions
128 lines (93 loc) · 3.42 KB
/
Copy pathFun_game.py
File metadata and controls
128 lines (93 loc) · 3.42 KB
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
117
118
119
120
121
122
123
124
125
126
127
128
import random
from tkinter import *
from ending import end
lives=2
points=0
def open_game_window(player_name):
global rock, paper, scissors, computer_choice, winner
game = Toplevel()
def manp():
name = entry.get()
if len(name) <= 3:
house["text"] = "Your username has to be longer than 3 characters"
house['fg'] = "red"
elif len(name) >= 3:
pass
romt = Button(text="Sign in", command=manp)
romt.place(x=180, y=125)
square = Label(text="Write your name")
square.place(x=160, y=10)
entry = Entry()
entry.place(x=160, y=50)
house = Label(text="")
house.place(x=160, y=100)
computer_choice=Label(game,text="computer_choice",width=100, height=6,bg="#52f5e8",font="12")
computer_choice.pack()
def get_computer_choice(my_choice):
global computer_choice
nlo=random.choice(["rock", "paper", "scissors"])
computer_choice['text']=f"Computer chose {nlo}"
win(my_choice=my_choice,machine_choice=nlo)
winner=Label(game,text="Winner",width=40,bg="#5ff3d4",font="24")
winner.pack(pady=70)
def king(human):
global winner
name=player_name
winner["text"]=f"{name} has {points} points and {lives}"
if lives !=1:
winner['text']+=" lives"
else:
winner['text']+=" life"
color(human)
def color(human):
if human=="nobody":
winner["bg"]="#f1a14c"
elif human=="computer":
winner["bg"]="#d164e4"
elif human=="human":
winner["bg"]="#189b4b"
def win(my_choice,machine_choice):
global lives
global points
if my_choice==machine_choice:
human="nobody"
if my_choice=="scissors":
if machine_choice=="rock":
human="computer"
elif machine_choice=="paper":
human="human"
if my_choice=="rock":
if machine_choice=="scissors":
human="human"
elif machine_choice=="paper":
human="computer"
if my_choice=="paper":
if machine_choice=="rock":
human="human"
elif machine_choice=="scissors":
human="computer"
if human == "human":
points+=100
elif human == "computer":
lives-=1
if lives ==0:
rock.config(state="disabled")
paper.config(state="disabled")
scissors.config(state="disabled")
game.withdraw()
end(player_name=player_name,score=points)
king(human)
def yay(chosen):
rock.config(bd=5, relief="flat")
paper.config(bd=5, relief="flat")
scissors.config(bd=5, relief="flat")
chosen.config(bd=5,relief="raised")
def click_button(chosen):
yay(chosen)
get_computer_choice(my_choice=chosen ["text"].lower())
rock=Button(game,text="Rock",command=lambda:click_button(rock),width=5,height=1,bg="#f03521")
rock.pack(pady=50,padx=10,fill="x",expand=True,side="left")
paper=Button(game,text="Paper",command=lambda:click_button(paper),width=5,height=1,bg="#7af35f")
paper.pack(padx=10,side="left",fill="x",expand=True)
scissors=Button(game,text="Scissors",command=lambda:click_button(scissors),width=5,height=1,bg="#5f94f3")
scissors.pack(padx=10,side="left",fill="x",expand=True)