Advertisement
Taximaniac

Simple Dice Roller example v 0.0.1

Feb 12th, 2018
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.43 KB | None | 0 0
  1. """
  2.     This is just a small dice roller example i made for fun.
  3.    Author: taximaniac
  4.     Licence: Open Source, do what you want with it.
  5. """
  6. # import modules
  7. import time
  8. import random
  9. import os
  10.  
  11. # make dices
  12. dice1 = [1, 2, 3, 4, 5]
  13. dice2 = [1, 2, 3, 4, 5]
  14. dice3 = [1, 2, 3, 4, 5]
  15. dice4 = [1, 2, 3, 4, 5]
  16. dice5 = [1, 2, 3, 4, 5]
  17.  
  18. # add dices to dices list
  19. dices = [dice1, dice2, dice3, dice4, dice5]
  20.  
  21. # Make a empty list to hold value of rolled dices
  22. picked = []
  23.  
  24. def display_rolling_dice_message(count: int = 0, loop_times: int = 5, clear_time: float = 0.1) -> None:
  25.     """
  26.    make a loop to animate a Rolling dice Message
  27.    os.system("cls") clears the console for the next item
  28.    for each loop sleep execution for x amount of seconds to
  29.    slow down the execution of the loop
  30.    then increment the counter. when count is reached x loops it will
  31.    exit.
  32.    """
  33.     while count < loop_times:
  34.         os.system("cls")
  35.         print("Rolling Dices, Please Wait")
  36.         time.sleep(clear_time)
  37.         os.system("cls")
  38.         print("Rolling Dices, Please Wait.")
  39.         time.sleep(clear_time)
  40.         os.system("cls")
  41.         print("Rolling Dices, Please Wait..")
  42.         time.sleep(clear_time)
  43.         os.system("cls")
  44.         print("Rolling Dices, Please Wait...")
  45.         time.sleep(clear_time)
  46.         os.system("cls")
  47.         print("Rolling Dices, Please Wait....")
  48.         time.sleep(clear_time)
  49.         os.system("cls")
  50.         print("Rolling Dices, Please Wait.....")
  51.         time.sleep(clear_time)
  52.         os.system("cls")
  53.         print("Rolling Dices, Please Wait")
  54.  
  55.         count += 1
  56.  
  57.  
  58. # loop trough the list of dices and for each dice pick a random number
  59. # from the dice list using the random.choice() function and append it to
  60. # the picked list.
  61. for dice in dices:
  62.     picked.append(random.choice(dice))
  63.  
  64. # make a counter variable
  65. count = 0
  66.  
  67. # how many times we loop the wait text
  68. loop_times = 5
  69.  
  70. # how much time to sleep between new print.
  71. clear_time = 0.1
  72. # run the rolling message
  73. display_rolling_dice_message(count, loop_times, clear_time)
  74.  
  75. # clear the console for new message
  76. os.system("cls")
  77.  
  78. # print the result
  79. print("Your dice roll ended up with:")
  80. print("--------------------------")
  81. print("| D1 | D2 | D3 | D4 | D5 |")
  82. print("--------------------------")
  83. print(f"|  {picked[0]} |  {picked[1]} |  {picked[2]} |  {picked[3]} |  {picked[4]} |")
  84. print("--------------------------")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement