diff --git a/project-1-pig.py b/project-1-pig.py index fcd3359..4640573 100644 --- a/project-1-pig.py +++ b/project-1-pig.py @@ -1,25 +1,15 @@ -# Mini-Project-1: Pig -""" -Players take turns to roll a single die as many times as they wish, adding all roll results to a running total, -but losing their gained score for the turn if they roll a 1. -The first player to score the maximum points wins. -""" - import random -import time def roll(): - min_val = 0 - max_val = 19 - roll = random.randint(min_val, max_val) - return roll + return random.randint(1, 6) # standard die -print("\n_______WELCOME_TO_PIG______\n") +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): ") + players = input(f"Enter total number of players ({max_players} max): ") if players.isdigit(): players = int(players) if min_players <= players <= max_players: @@ -29,36 +19,43 @@ def roll(): else: print(f"Only {min_players} - {max_players} allowed") else: - print("Invalid Number. Please do not enter alphanumerics or symbols.") -print(players) + print("Invalid number. Please do not enter letters or symbols.") -max_score = 100 +# Game setup +winning_score = 100 player_scores = [0 for _ in range(players)] -print(player_scores) +print(f"\nGame started with {players} players. First to {winning_score} wins!\n") -for player_idx in range(players): - print(f"\nPlayer No. {player_idx + 1} turn has now started") - curr_score = 0 - while True: - player_roll = input("Would you like to roll(y/n)? ") - if player_roll.lower() == 'y': - value = roll() - else: - break - if value == 1: - print("You rolled 1. Turn done!") - break - elif player_roll.lower() == 'n': - print("Player choses to stop. Turn done!") +# 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 - else: - curr_score += value - print(f"You rollled {value}") - print(f"Current Score : {curr_score}") - player_scores[player_idx] += curr_score - print(f"Player Total Score: {player_scores[player_idx]}") -print(player_scores) -max_score = max(player_scores) -winner = player_scores.index(max_score) -print(f"Winner : {winner + 1}, Score : {max_score}") \ No newline at end of file +# Announce winner +print("\nGame Over!") +print(f"Winner: Player {winner + 1} with {player_scores[winner]} points 🎉")