From 55e8399030fbb8fd9c00c31080e443694b2c7fb2 Mon Sep 17 00:00:00 2001 From: Shivani Thorve Date: Sun, 6 Mar 2022 00:30:16 +0530 Subject: [PATCH 1/2] script for multiplayer dice rolling simulator --- .../Multiplayer Dice Rolling Simulator.py | 89 +++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 Python/Multiplayer Dice Rolling Simulator/Multiplayer Dice Rolling Simulator.py diff --git a/Python/Multiplayer Dice Rolling Simulator/Multiplayer Dice Rolling Simulator.py b/Python/Multiplayer Dice Rolling Simulator/Multiplayer Dice Rolling Simulator.py new file mode 100644 index 000000000..6b881a4b1 --- /dev/null +++ b/Python/Multiplayer Dice Rolling Simulator/Multiplayer Dice Rolling Simulator.py @@ -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. + + + + + + + + + + From 5156275d2371732beab835d40bb2243c91cec504 Mon Sep 17 00:00:00 2001 From: Shivani Thorve Date: Sun, 6 Mar 2022 00:30:41 +0530 Subject: [PATCH 2/2] readme file --- Python/Multiplayer Dice Rolling Simulator/README.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 Python/Multiplayer Dice Rolling Simulator/README.md diff --git a/Python/Multiplayer Dice Rolling Simulator/README.md b/Python/Multiplayer Dice Rolling Simulator/README.md new file mode 100644 index 000000000..ca7087919 --- /dev/null +++ b/Python/Multiplayer Dice Rolling Simulator/README.md @@ -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. \ No newline at end of file