Skip to content

Commit 0c1c651

Browse files
authored
Merge pull request larymak#154 from kaustav202/main
Add Multiplayer Dice Rolling Simulator Game
2 parents 342805f + d8d7469 commit 0c1c651

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

GAMES/Dice-Rolling-Game/Readme.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
## Dice Rolling Game
2+
3+
#### Play Dice virtually with your friends in this interesting dice rolling simulator game where the first player</br> to score 100 points Wins. It uses the inbuilt python module random.
4+
5+
## How to Run
6+
7+
- Clone this repo to your local machine
8+
- Go to the cloned directory and run `python dice_roll_sim.py`
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import random
2+
3+
4+
Points = []
5+
minPlayer = 2
6+
players = 0
7+
maxscore = 100
8+
DiceNum = 2
9+
gameRound = 0
10+
11+
def setPlayers():
12+
while True:
13+
players = input("How many players are playing?\n")
14+
if players.isdigit():
15+
players = int(players)
16+
if minPlayer <= players:
17+
for i in range(players):
18+
Points.append(0)
19+
return players
20+
21+
def diceroll(player, DiceNum):
22+
throw = 0
23+
print("\n\tPlayer {0}s turn:".format(player + 1),end = "")
24+
for i in range(DiceNum):
25+
print("\n\tHit Space Bar and Enter to throw die !!",end = " ")
26+
sp = input()
27+
if sp == " ":
28+
die = random.randint(1, 6)
29+
print("\t \tPlayer {0} has thrown die {1} which landed on {2}".format(player + 1, i + 1, die))
30+
throw += die
31+
else:
32+
print("your turn skipped!!")
33+
Points[player] += throw
34+
print("\n \tPlayer {0}s score for this round is : {1}".format(player + 1 , throw))
35+
print("\tPlayer {0}s total score is now: {1}".format(player + 1, Points[player]))
36+
return throw
37+
38+
def checkWin(maxscore):
39+
for player in range(players):
40+
if (Points[player] >= maxscore):
41+
print("\nPlayer {0} wins!! Congratulations!!".format(player + 1))
42+
return True
43+
44+
return False
45+
46+
47+
if __name__ == "__main__":
48+
players = setPlayers()
49+
while True:
50+
gameRound += 1
51+
print("\nRound: {0}".format(gameRound))
52+
for i in range(players):
53+
diceroll(i, DiceNum)
54+
print("\nScores after round {0} ".format(gameRound))
55+
for i in range(players):
56+
print("Player {0} --> {1}".format(i+1,Points[i]))
57+
if (checkWin(maxscore)):
58+
break

0 commit comments

Comments
 (0)