-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrock-game-foundation.py
More file actions
77 lines (64 loc) · 2.05 KB
/
rock-game-foundation.py
File metadata and controls
77 lines (64 loc) · 2.05 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
'''
Rock Paper Sissors game
This is the foundation structure of the game without all of the
required logic to keep score. This is a good starting point.
'''
import random
# Global variables keep score and don't need to be passed into functions.
win = 0
loss = 0
tie = 0
def main():
#control loop with 'y' variable
play_again = 'y'
#start the game
while play_again == 'y':
display()
scoreboard()
user_choice = get_user_choice()
computer_choice = get_computer_choice()
pick_winner(user_choice, computer_choice)
print("User choice: ", user_choice)
print("Computer choice: ", computer_choice)
scoreboard()
play_again = input("Play again? (y/n): ")
if play_again != "y":
print("\n\nThank you for playing.")
print("FINAL SCORES.")
print("Win:\t", win)
print("Loss:\t", loss)
print("Tie:\t", tie)
# Intial display
def display():
print("\n\n========================================")
print("Let's play Rock, Paper, Sissors!")
# Display the scores
def scoreboard():
print("\nThe current scores.")
print("Win:\t", win)
print("Loss:\t", loss)
print("Tie:\t", tie)
# Loop continues until a valid choice is entered or ^C
def get_user_choice():
while True:
user_choice = input("\nType one of the following: rock, paper, or sissors: ")
if user_choice == "rock" or user_choice == "paper" or user_choice == "sissors":
return user_choice
else:
print("ERROR: Not a valid choice.")
# Get the computer choice
def get_computer_choice():
computer_choice = ['rock', 'paper', 'scissor']
return random.choice(computer_choice)
# TODO: add the logic for the winner
def pick_winner(user_choice, computer_choice):
global win
global loss
global tie
#TODO: Replace this with logic to keep real score. This just counts.
win = win + 1
loss = loss + 5
tie = tie + 10
# Format for running a main method.
if __name__ == "__main__":
main()