Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Dice in Computercraft
- --TheCountChuckula
- function clear()
- term.clear()
- term.setCursorPos(1,1)
- end
- function coin()
- for r = 1, 10 do
- effect = math.random(2)
- m.clear()
- m.setTextScale(3)
- if effect == 1 then
- m.setCursorPos(1,1)
- m.write("HEAD")
- sleep(.05)
- else
- m.setCursorPos(1,2)
- m.write("TAIL")
- sleep(.05)
- end
- flip = math.random(2)
- m.setTextScale(2)
- m.setCursorPos(1,1)
- m.clear()
- if flip == 1 then
- m.setCursorPos(1,1)
- m.write("HEAD")
- else
- m.setCursorPos(1,2)
- m.write("TAIL")
- end
- end
- function roll()
- for r = 1, 5 do
- for x = 1, 2 do
- effect = math.random(dienum)
- m.setCursorPos(1,x)
- m.clear()
- m.setTextScale(3)
- if effect < 10 then
- m.write("0")
- m.write(effect)
- else
- m.write(effect)
- end
- sleep(.05)
- end
- end
- rint = math.random(dienum)
- m.setCursorPos(1,1)
- m.clear()
- m.setTextScale(3)
- if rint < 10 then
- m.write("0")
- m.write(rint)
- elseif rint == 100 then
- m.setTextScale(2)
- m.write(rint)
- m.setTextScale(3)
- else
- m.write(rint)
- end
- m.setCursorPos(1,2)
- m.write("^^")
- end
- math.randomseed(os.time())
- m = peripheral.wrap("back")
- dienum = 0
- while true do
- clear()
- print("Hello, Welcome to DICE!")
- print("-------------------------------------")
- print("Please select your die for this roll.")
- print("-------------------------------------")
- print("a. Flip a Coin")
- print("b. 4-Sided")
- print("c. 6-Sided")
- print("d. 8-Sided")
- print("e. 10-Sided")
- print("f. 20-Sided")
- print("g. 100-Sided")
- print("-------------------------------------")
- local event, select = os.pullEvent("char")
- if select == "a" then
- coin()
- elseif select == "b" then
- dienum = 4
- roll()
- elseif select == "c" then
- dienum = 6
- roll()
- elseif select == "d" then
- dienum = 8
- roll()
- elseif select == "e" then
- dienum = 10
- roll()
- elseif select == "f" then
- dienum = 20
- roll()
- elseif select == "g" then
- dienum = 100
- roll()
- else
- shell.run("dice")
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment