forked from UVA-CS3240-S18/Lab2Fork-101
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpig.py
60 lines (55 loc) · 2.11 KB
/
pig.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
# Mark Sherriff (mss2x)
import random
print("Welcome to Pig!")
done = False
player_temp_total = 0
player_total = 0
comp_temp_total = 0
comp_total = 0
turn = "player"
winning_score = 50
while not done:
while turn == "player" and not done:
print()
print("Player:", player_total, "Computer:", comp_total)
print("It's your turn!")
roll = random.randint(1,6)
print("You rolled a", roll)
if roll == 1:
turn = "computer"
player_temp_total = 0
print("PIG! Too bad! Your total is currently:", player_total)
else:
player_temp_total += roll
print("You currently have " + str(player_temp_total) + " banked.")
choice = input("Do you wish to roll again (y/n)?: ")
if choice == 'n':
player_total += player_temp_total
player_temp_total = 0
print("Your total socre is now:", player_total)
turn = "computer"
if player_total > winning_score:
print("You win! " + str(player_total) + " to " + str(comp_total))
done = True
while turn == "computer" and not done:
print()
print("Player:", player_total, "Computer:", comp_total)
print("It's the computer's turn!")
roll = random.randint(1,6)
print("The computer rolled a", roll)
if roll == 1:
turn = "player"
comp_temp_total = 0
print("PIG! Too bad! The computer's total is currently:", comp_total)
else:
comp_temp_total += roll
print("The computer has " + str(comp_temp_total) + " banked.")
if comp_temp_total > 6 or comp_total + comp_temp_total > winning_score:
print("The computer has chosen to end its turn.")
comp_total += comp_temp_total
comp_temp_total = 0
print("The computer's score is now:", comp_total)
turn = "player"
if comp_total > winning_score:
print("The computer wins! " + str(comp_total) + " to " + str(player_total))
done = True