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