SHOW:
|
|
- or go back to the newest paste.
| 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 | flip = math.random(2) | |
| 11 | m.setTextScale(1) | |
| 12 | m.setCursorPos(1,1) | |
| 13 | m.clear() | |
| 14 | if flip == 1 then | |
| 15 | m.setCursorPos(1,1) | |
| 16 | m.write("HEADS")
| |
| 17 | else | |
| 18 | m.setCursorPos(1,2) | |
| 19 | m.write("TAILS")
| |
| 20 | end | |
| 21 | end | |
| 22 | ||
| 23 | function roll() | |
| 24 | for r = 1, 5 do | |
| 25 | for x = 1, 2 do | |
| 26 | effect = math.random(dienum) | |
| 27 | m.setCursorPos(1,x) | |
| 28 | m.clear() | |
| 29 | m.setTextScale(3) | |
| 30 | if effect < 10 then | |
| 31 | m.write("0")
| |
| 32 | m.write(effect) | |
| 33 | else | |
| 34 | m.write(effect) | |
| 35 | end | |
| 36 | sleep(.05) | |
| 37 | end | |
| 38 | end | |
| 39 | rint = math.random(dienum) | |
| 40 | m.setCursorPos(1,1) | |
| 41 | m.clear() | |
| 42 | m.setTextScale(3) | |
| 43 | if rint < 10 then | |
| 44 | m.write("0")
| |
| 45 | m.write(rint) | |
| 46 | elseif rint == 100 then | |
| 47 | m.setTextScale(2) | |
| 48 | m.write(rint) | |
| 49 | m.setTextScale(3) | |
| 50 | - | function roll() |
| 50 | + | |
| 51 | m.write(rint) | |
| 52 | end | |
| 53 | - | local effect = math.random(dienum) |
| 53 | + | |
| 54 | m.write("^^")
| |
| 55 | end | |
| 56 | ||
| 57 | math.randomseed(os.time()) | |
| 58 | m = peripheral.wrap("back")
| |
| 59 | dienum = 0 | |
| 60 | while true do | |
| 61 | clear() | |
| 62 | print("Hello, Welcome to DICE!")
| |
| 63 | print("-------------------------------------")
| |
| 64 | print("Please select your die for this roll.")
| |
| 65 | print("-------------------------------------")
| |
| 66 | - | local rint = math.random(dienum) |
| 66 | + | |
| 67 | print("b. 4-Sided")
| |
| 68 | print("c. 6-Sided")
| |
| 69 | print("d. 8-Sided")
| |
| 70 | print("e. 10-Sided")
| |
| 71 | print("f. 20-Sided")
| |
| 72 | print("g. 100-Sided")
| |
| 73 | print("-------------------------------------")
| |
| 74 | ||
| 75 | local event, select = os.pullEvent("char")
| |
| 76 | if select == "a" then | |
| 77 | coin() | |
| 78 | elseif select == "b" then | |
| 79 | dienum = 4 | |
| 80 | roll() | |
| 81 | elseif select == "c" then | |
| 82 | dienum = 6 | |
| 83 | - | function coin() |
| 83 | + | |
| 84 | - | local flip = math.random(2) |
| 84 | + | |
| 85 | dienum = 8 | |
| 86 | roll() | |
| 87 | elseif select == "e" then | |
| 88 | dienum = 10 | |
| 89 | roll() | |
| 90 | elseif select == "f" then | |
| 91 | dienum = 20 | |
| 92 | roll() | |
| 93 | elseif select == "g" then | |
| 94 | dienum = 100 | |
| 95 | - | end |
| 95 | + | |
| 96 | else | |
| 97 | shell.run("dice")
| |
| 98 | end | |
| 99 | end |