Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- This is just a small dice roller example i made for fun.
- Author: taximaniac
- Licence: Open Source, do what you want with it.
- """
- # import modules
- import time
- import random
- import os
- # make dices
- dice1 = [1, 2, 3, 4, 5]
- dice2 = [1, 2, 3, 4, 5]
- dice3 = [1, 2, 3, 4, 5]
- dice4 = [1, 2, 3, 4, 5]
- dice5 = [1, 2, 3, 4, 5]
- # add dices to dices list
- dices = [dice1, dice2, dice3, dice4, dice5]
- # Make a empty list to hold value of rolled dices
- picked = []
- def display_rolling_dice_message(count: int = 0, loop_times: int = 5, clear_time: float = 0.1) -> None:
- """
- make a loop to animate a Rolling dice Message
- os.system("cls") clears the console for the next item
- for each loop sleep execution for x amount of seconds to
- slow down the execution of the loop
- then increment the counter. when count is reached x loops it will
- exit.
- """
- while count < loop_times:
- os.system("cls")
- print("Rolling Dices, Please Wait")
- time.sleep(clear_time)
- os.system("cls")
- print("Rolling Dices, Please Wait.")
- time.sleep(clear_time)
- os.system("cls")
- print("Rolling Dices, Please Wait..")
- time.sleep(clear_time)
- os.system("cls")
- print("Rolling Dices, Please Wait...")
- time.sleep(clear_time)
- os.system("cls")
- print("Rolling Dices, Please Wait....")
- time.sleep(clear_time)
- os.system("cls")
- print("Rolling Dices, Please Wait.....")
- time.sleep(clear_time)
- os.system("cls")
- print("Rolling Dices, Please Wait")
- count += 1
- # loop trough the list of dices and for each dice pick a random number
- # from the dice list using the random.choice() function and append it to
- # the picked list.
- for dice in dices:
- picked.append(random.choice(dice))
- # make a counter variable
- count = 0
- # how many times we loop the wait text
- loop_times = 5
- # how much time to sleep between new print.
- clear_time = 0.1
- # run the rolling message
- display_rolling_dice_message(count, loop_times, clear_time)
- # clear the console for new message
- os.system("cls")
- # print the result
- print("Your dice roll ended up with:")
- print("--------------------------")
- print("| D1 | D2 | D3 | D4 | D5 |")
- print("--------------------------")
- print(f"| {picked[0]} | {picked[1]} | {picked[2]} | {picked[3]} | {picked[4]} |")
- print("--------------------------")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement