Skip to content

Commit

Permalink
Added Pig Dice Game
Browse files Browse the repository at this point in the history
  • Loading branch information
Saipradyumnagoud authored Oct 11, 2024
1 parent 205da3a commit e644d04
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
19 changes: 19 additions & 0 deletions Game_Development/Pig Dice Game/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Pig Dice Game

A simple command-line implementation of the **Pig Dice Game** in Python. Two players take turns rolling a die, racing to reach 100 points. The game has a risk/reward mechanic where rolling a 1 results in losing all points for the current turn.

## How to Play

1. Players take turns to roll a die.
2. On each roll, if the player rolls a 1, their turn ends and they score nothing for that turn.
3. If the player rolls a 2-6, they can choose to roll again or "hold".
4. If the player chooses to hold, their turn total is added to their overall score, and their turn ends.
5. The first player to reach 100 points wins the game.

## Setup Instructions

### Prerequisites

- Python 3.x installed on your system.


45 changes: 45 additions & 0 deletions Game_Development/Pig Dice Game/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import random

def roll_die():
return random.randint(1, 6)

def player_turn(player_name, total_score):
turn_score = 0
while True:
roll = roll_die()
print(f"{player_name} rolled a {roll}")
if roll == 1:
print(f"{player_name} rolled a 1! Turn over. No points added.")
return total_score
else:
turn_score += roll
print(f"{player_name}'s turn score is now {turn_score}")
choice = input("Do you want to 'roll' again or 'hold'? ").lower()
if choice == 'hold':
total_score += turn_score
print(f"{player_name} holds. Total score is now {total_score}")
return total_score

def pig_game():
player_1 = input("Enter Player 1's name: ")
player_2 = input("Enter Player 2's name: ")

score_1 = 0
score_2 = 0
winning_score = 100

while score_1 < winning_score and score_2 < winning_score:
print(f"\n{player_1}'s turn:")
score_1 = player_turn(player_1, score_1)
if score_1 >= winning_score:
print(f"\n{player_1} wins with a score of {score_1}!")
break

print(f"\n{player_2}'s turn:")
score_2 = player_turn(player_2, score_2)
if score_2 >= winning_score:
print(f"\n{player_2} wins with a score of {score_2}!")
break

if __name__ == "__main__":
pig_game()
2 changes: 2 additions & 0 deletions Game_Development/Pig Dice Game/tempCodeRunnerFile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

if score_1 >= winning_score:

0 comments on commit e644d04

Please sign in to comment.