-
Notifications
You must be signed in to change notification settings - Fork 1
/
game.py
117 lines (108 loc) · 3.31 KB
/
game.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
117
import random
import time
print("\033[H\033[J")
print("/********************************************************/\n")
print(" Rock-Paper-Scissor \n")
print("/********************************************************/\n")
k = 0
comp_move = [" "," "," "," "," "]
user_move = [" "," "," "," "," "]
for i in range(5):
rand_num = random.randint(1,3)
if rand_num == 1:
comp_move[k] = "Rock"
elif rand_num == 2:
comp_move[k] = "Paper"
elif rand_num == 3:
comp_move[k] = "Scissor"
k = k + 1
scUser = 0
scComp = 0
name = input("\nEnter your name : ")
file = open("text/user.txt","w")
file.write(name)
file.close()
k=0
for i in range(5):
file = open("text/score.txt","w")
file.write(str(scUser))
file.write(str(scComp))
file.close()
print("\nPlay\n")
choice='a'
time.sleep(.800)
while(choice!='y'):
m = 3
for j in range(3):
print("\033[H\033[J")
print(m)
time.sleep(1)
m = m - 1
file = open("text/testfile.txt","r")
move = file.readline()
file.close()
print("\nYour move => "+move)
time.sleep(1)
choice = input("\nPress Y if its correct : ")
if choice=='y':
user_move[k]=move
time.sleep(.500)
print("\nPCs move => "+comp_move[k])
print("\n"+user_move[k]+" Vs "+comp_move[k])
if user_move[k]=="Scissor" and comp_move[k]=="Rock":
scComp = scComp + 1
time.sleep(1)
print("\nYou lose")
time.sleep(1)
print("\033[H\033[J")
elif user_move[k]=="Scissor" and comp_move[k]=="Paper":
scUser = scUser + 1
time.sleep(1)
print("\nYou win")
time.sleep(1)
print("\033[H\033[J")
elif user_move[k]=="Rock" and comp_move[k]=="Paper":
scComp = scComp + 1
time.sleep(1)
print("\nYou lose")
time.sleep(1)
print("\033[H\033[J")
elif user_move[k]=="Rock" and comp_move[k]=="Scissor":
scUser = scUser + 1
time.sleep(1)
print("\nYou win")
time.sleep(1)
print("\033[H\033[J")
elif user_move[k]=="Paper" and comp_move[k]=="Scissor":
scComp = scComp + 1
time.sleep(1)
print("\nYou lose")
time.sleep(1)
print("\033[H\033[J")
elif user_move[k]=="Paper" and comp_move[k]=="Rock":
scUser = scUser + 1
time.sleep(1)
print("\nYou win")
time.sleep(1)
print("\033[H\033[J")
else:
time.sleep(1)
print("\nDraw")
time.sleep(1)
print("\033[H\033[J")
k = k+1
time.sleep(2)
file = open("text/score.txt","w")
file.write(str(scUser))
file.write(str(scComp))
file.close()
k=0
for i in range(5):
print("\n"+user_move[k]+" Vs "+comp_move[k])
k=k+1
if scUser<scComp:
print("\nGame over...You lost :(")
elif scUser==scComp:
print("\nGame draw")
else:
print("\nCongratulations!! You won :)")