theCountChuckula

DICE 2.4

May 13th, 2014
187
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.  
  36. function roll()
  37.     for r = 1, 5 do
  38.       for x = 1, 2 do
  39.         effect = math.random(dienum)
  40.         m.setCursorPos(1,x)
  41.         m.clear()
  42.         m.setTextScale(3)
  43.         if effect < 10 then
  44.           m.write("0")
  45.           m.write(effect)
  46.         else
  47.           m.write(effect)
  48.         end
  49.         sleep(.05)
  50.       end
  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.  
  70. math.randomseed(os.time())
  71. m = peripheral.wrap("back")
  72. dienum = 0
  73. while true do
  74.   clear()
  75.   print("Hello, Welcome to DICE!")
  76.   print("-------------------------------------")
  77.   print("Please select your die for this roll.")
  78.   print("-------------------------------------")
  79.   print("a. Flip a Coin")
  80.   print("b. 4-Sided")
  81.   print("c. 6-Sided")
  82.   print("d. 8-Sided")
  83.   print("e. 10-Sided")
  84.   print("f. 20-Sided")
  85.   print("g. 100-Sided")
  86.   print("-------------------------------------")
  87.  
  88.   local event, select = os.pullEvent("char")
  89.   if select == "a" then
  90.     coin()
  91.   elseif select == "b" then
  92.     dienum = 4
  93.     roll()
  94.   elseif select == "c" then
  95.     dienum = 6
  96.     roll()
  97.   elseif select == "d" then
  98.     dienum = 8
  99.     roll()
  100.   elseif select == "e" then
  101.     dienum = 10
  102.     roll()
  103.   elseif select == "f" then
  104.     dienum = 20
  105.     roll()
  106.   elseif select == "g" then
  107.     dienum = 100
  108.     roll()
  109.   else
  110.     shell.run("dice")
  111.   end
  112. end
Advertisement
Add Comment
Please, Sign In to add comment