theCountChuckula

DICE 2.7

May 13th, 2014
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --Dice in Computercraft
  2. --TheCountChuckula
  3.  
  4. function clear()
  5.   term.clear()
  6.   term.setCursorPos(1,1)
  7. end
  8.  
  9. function coin()
  10.   for r = 1, 10 do
  11.    effect = math.random(2)
  12.    m.clear()
  13.    m.setTextScale(3)
  14.    if effect == 1 then
  15.       m.setCursorPos(1,1)
  16.       m.write("HEAD")
  17.       sleep(.05)
  18.     else
  19.       m.setCursorPos(1,2)
  20.       m.write("TAIL")
  21.       sleep(.05)
  22.     end
  23.     flip = math.random(2)
  24.     m.setTextScale(2)
  25.     m.setCursorPos(1,1)
  26.     m.clear()
  27.     if flip == 1 then
  28.       m.setCursorPos(1,1)
  29.       m.write("HEAD")
  30.     else
  31.       m.setCursorPos(1,2)
  32.       m.write("TAIL")
  33.     end
  34.   end
  35. end
  36.  
  37. function roll()
  38.   for r = 1, 5 do
  39.     for x = 1, 2 do
  40.       effect = math.random(dienum)
  41.       m.setCursorPos(1,x)
  42.       m.clear()
  43.       m.setTextScale(3)
  44.       if effect < 10 then
  45.         m.write("0")
  46.         m.write(effect)
  47.       else
  48.         m.write(effect)
  49.       end
  50.       sleep(.05)
  51.     end
  52.     rint = math.random(dienum)
  53.     m.setCursorPos(1,1)
  54.     m.clear()
  55.     m.setTextScale(3)
  56.     if rint < 10 then
  57.       m.write("0")
  58.       m.write(rint)
  59.     elseif rint == 100 then
  60.       m.setTextScale(2)
  61.       m.write(rint)
  62.       m.setTextScale(3)
  63.     else
  64.       m.write(rint)
  65.     end
  66.     m.setCursorPos(1,2)
  67.     m.write("^^")
  68.   end
  69. end
  70.  
  71. math.randomseed(os.time())
  72. m = peripheral.wrap("back")
  73. dienum = 0
  74. while true do
  75.   clear()
  76.   print("Hello, Welcome to DICE!")
  77.   print("-------------------------------------")
  78.   print("Please select your die for this roll.")
  79.   print("-------------------------------------")
  80.   print("a. Flip a Coin")
  81.   print("b. 4-Sided")
  82.   print("c. 6-Sided")
  83.   print("d. 8-Sided")
  84.   print("e. 10-Sided")
  85.   print("f. 20-Sided")
  86.   print("g. 100-Sided")
  87.   print("-------------------------------------")
  88.  
  89.   local event, select = os.pullEvent("char")
  90.   if select == "a" then
  91.     coin()
  92.   elseif select == "b" then
  93.     dienum = 4
  94.     roll()
  95.   elseif select == "c" then
  96.     dienum = 6
  97.     roll()
  98.   elseif select == "d" then
  99.     dienum = 8
  100.     roll()
  101.   elseif select == "e" then
  102.     dienum = 10
  103.     roll()
  104.   elseif select == "f" then
  105.     dienum = 20
  106.     roll()
  107.   elseif select == "g" then
  108.     dienum = 100
  109.     roll()
  110.   else
  111.     shell.run("dice")
  112.   end
  113. end
Advertisement
Add Comment
Please, Sign In to add comment