Skip to content

Refactor dice simulator into class structure with roll-again feature #350

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 68 additions & 60 deletions Dice_Rolling_Stimulator/dice_stimulator.py
Original file line number Diff line number Diff line change
@@ -1,71 +1,79 @@
import random
#CATEGORIZING OUTCOME INTO A LIST

one = """
("===========")
("| |")
("| O |")
("| |")
("===========")\n
"""
class DiceSimulator:
"""
A class to simulate rolling two dice.

Features:
- Randomly rolls two dice with ASCII representation.
- Offers user the option to roll again or quit.
"""

two = """
("===========")
("| |")
("| O O |")
("| |")
("===========")\n

dice_faces = [
"""
===========
| |
| O |
| |
===========
""",
"""
===========
| O |
| |
| O |
===========
""",
"""
===========
| O |
| O |
| O |
===========
""",
"""
===========
| O O |
| |
| O O |
===========
""",
"""
===========
| O O |
| O |
| O O |
===========
""",
"""
===========
| O O |
| O O |
| O O |
===========
"""
]



three = """
("===========")
("| O |")
("| O |")
("| O |")
("===========")\n

def roll_dice(self):
"""

four = """
("===========")
("| O O |")
("| 0 |")
("| O O |")
("===========")\n

Rolls two dice and prints their ASCII representation.
"""
dice_rolls = random.choices(self.dice_faces, k=2)
for die in dice_rolls:
print(die)

five = """
("===========")
("| O O |")
("| 0 |")
("| O O |")
("===========")\n

def start_game(self):
"""

six = """
("===========")
("| O O |")
("| O O |")
("| O O |")
("===========") \n
Starts the dice rolling game, giving the user the option to roll again.
"""
print("🎲 Welcome to the Dice Simulator! 🎲")
while True:
self.roll_dice()
choice = input("Do you want to roll again? (y/n): ").strip().lower()
if choice != 'y':
print("Thanks for playing! Goodbye!")
break



outcomes_list = [one, two, three, four, five, six]


print("This is a dice stimulator")
x = "y"
while x == "y":
randon_outcome = random.sample(outcomes_list, 2)
for outcome in randon_outcome:
print(outcome)

x = input("Press y to roll again ")
if __name__ == "__main__":
game = DiceSimulator()
game.start_game()