forked from Berat-O/Python_Project
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproject-1-pig.py
More file actions
61 lines (54 loc) · 2.04 KB
/
project-1-pig.py
File metadata and controls
61 lines (54 loc) · 2.04 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
import random
def roll():
return random.randint(1, 6) # standard die
print("\n_______WELCOME TO PIG______\n")
# Setup players
while True:
min_players = int(input("Minimum Players : "))
max_players = int(input("Maximum Players : "))
players = input(f"Enter total number of players ({max_players} max): ")
if players.isdigit():
players = int(players)
if min_players <= players <= max_players:
break
elif players < min_players:
print(f"Minimum {min_players} players allowed")
else:
print(f"Only {min_players} - {max_players} allowed")
else:
print("Invalid number. Please do not enter letters or symbols.")
# Game setup
winning_score = 100
player_scores = [0 for _ in range(players)]
print(f"\nGame started with {players} players. First to {winning_score} wins!\n")
# Main game loop
winner = None
while not winner:
for player_idx in range(players):
print(f"\nPlayer {player_idx + 1}'s turn")
curr_score = 0
while True:
player_roll = input("Roll the die? (y/n): ").lower()
if player_roll == 'y':
value = roll()
print(f"You rolled {value}")
if value == 1:
print("Oops! You rolled a 1. Turn over, no points this round.")
curr_score = 0
break
else:
curr_score += value
print(f"Current turn score: {curr_score}")
elif player_roll == 'n':
print("Player chooses to hold. Turn over.")
break
else:
print("Invalid input. Please enter 'y' or 'n'.")
player_scores[player_idx] += curr_score
print(f"Total score for Player {player_idx + 1}: {player_scores[player_idx]}")
if player_scores[player_idx] >= winning_score:
winner = player_idx
break
# Announce winner
print("\nGame Over!")
print(f"Winner: Player {winner + 1} with {player_scores[winner]} points 🎉")