Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a Multiplayer Dice Rolling Simulator Script in Python Folder #1316

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import random
# FUNCTION CODE :
def DiceSimulator(m,Players):
x = "y"
player_no=1 #starting from player 1.
while x == "y":
no = random.randint(1,6) #to generate random number between 1 to 6 including them.
if m==2:
if player_no > Players:
player_no=1
print("Player {}".format(player_no)) #to print current player

if no == 1:
print("[-------]")
print("[ ]")
print("[ 0 ]")
print("[ ]")
print("[-------]")
if no == 2:
print("[-------]")
print("[ 0 ]")
print("[ ]")
print("[ 0 ]")
print("[-------]")
if no == 3:
print("[-------]")
print("[ 0 ]")
print("[ 0 ]")
print("[ 0 ]")
print("[-------]")
if no == 4:
print("[-------]")
print("[ 0 0 ]")
print("[ ]")
print("[ 0 0 ]")
print("[-------]")
if no == 5:
print("[-------]")
print("[ 0 0 ]")
print("[ 0 ]")
print("[ 0 0 ]")
print("[-------]")
if no == 6:
print("[-------]")
print("[ 0 0 ]")
print("[ 0 0 ]")
print("[ 0 0 ]")
print("[-------]")
print("\n")
if m==1 :
print("Yeah!! You got extra chance ,Roll Again !")
if m==2 :
#to know which player got an extra chance
print("Yeah!! Player {}, got extra chance ,Roll Again !".format(player_no))
player_no-=1 # To give same player the extra chance.

player_no+=1 #each time player should be incremented to give next player a chance.
if m==2:
if player_no>Players:
player_no=1 #to start next set of chances from Player 1
print("Next : Player {}".format(player_no)) #to print next player

x=input("\t\nPress y to roll and n to exit:")
print("\n")


# DRIVER CODE :
print ('***** WELCOME TO DICE ROLLING SIMULATOR *****')

players=int(input("\t\nEnter the number of Players :"))

while (players<=0):
print("Oops!! Insufficient Players !")
players=int(input("\t\nEnter the number of Players :"))

if (players==1):
DiceSimulator(1,players) #function call for single player.
else :
DiceSimulator(2,players) #function call for multi-player.










5 changes: 5 additions & 0 deletions Python/Multiplayer Dice Rolling Simulator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#MULTI-PLAYER DICE ROLLING SIMULATOR \

It is typical dice rolling simulator with additional multiplayer feature.So,One or more than one player can use the same simulator.

Here,we have imported a Python Module called _Random_ which have `random.randint(start,end)` function to generate random numbers between 1 to 6.