Guest User

dice

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