-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.py
82 lines (60 loc) · 1.7 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
# importing Python modules
import random
import time
import sys
print("Welcome to classic Rock, Paper, Scissors!")
userScore = 0
computerScore = 0
def countdown(game_time):
while game_time:
mins, secs = divmod(game_time, 60)
timeformat = "Rock, Paper, Scissors, Shoot! {:2d}:{:2d}\n".format(mins, secs)
print(timeformat, end="\r")
time.sleep(0.5)
game_time -= 1
def startGame():
global userScore
global computerScore
userMove = input(
"\nPlease type your move: Rock, Paper, or Scissors: \n"
).capitalize()
computerMove = random.choice(["Rock", "Paper", "Scissors"])
countdown(4)
print(f"\nUser: {userMove}")
print(f"Computer: {computerMove}\n")
if (
userMove == "Rock"
and computerMove == "Paper"
or userMove == "Scissors"
and computerMove == "Rock"
or userMove == "Paper"
and computerMove == "Scissors"
):
print("Computer wins")
computerScore += 1
print(userScore)
print(computerScore)
elif (
userMove == "Paper"
and computerMove == "Rock"
or userMove == "Rock"
and computerMove == "Scissors"
or userMove == "Scissors"
and computerMove == "Paper"
):
print("User wins")
userScore += 1
print(userScore)
print(computerScore)
else:
print("Its a draw")
print(userScore)
print(computerScore)
while True:
if userScore < 4 and computerScore < 4:
startGame()
else:
print("\nBest of 7 reached. Game Over")
print("\nRun program to play again\n")
sys.exit()
startGame()