Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- monitor = peripheral.wrap("monitor_3")
- glass = peripheral.wrap("openperipheral_bridge_1")
- correct = 0
- required = 5
- while true do
- function RandKey()
- rand = math.random(0,9)
- return rand
- end
- digit = RandKey()
- displayDigit = tostring(digit)
- dCorrect = tostring(correct)
- glass.clear()
- glass.addText(225,120,displayDigit,0xffffff)
- -- glass.addText(225,150,correct,0x00f000)
- glass.sync()
- t = {
- {text = "1", x = 1, y = 1, txtCol = colours.white, bgCol = colours.blue},
- {text = "2", x = 3, y = 1, txtCol = colours.white, bgCol = colours.blue},
- {text = "3", x = 5, y = 1, txtCol = colours.white, bgCol = colours.blue},
- {text = "4", x = 1, y = 3, txtCol = colours.white, bgCol = colours.blue},
- {text = "5", x = 3, y = 3, txtCol = colours.white, bgCol = colours.blue},
- {text = "6", x = 5, y = 3, txtCol = colours.white, bgCol = colours.blue},
- {text = "7", x = 1, y = 5, txtCol = colours.white, bgCol = colours.blue},
- {text = "8", x = 3, y = 5, txtCol = colours.white, bgCol = colours.blue},
- {text = "9", x = 5, y = 5, txtCol = colours.white, bgCol = colours.blue},
- {text = "0", x = 7, y = 1, txtCol = colours.white, bgCol = colours.blue},
- --{text = tostring(required-correct), x = 7, y = 3, txtCol = colors.white, bgCol = colors.blue}
- }
- function writeButtons(_table)
- for i, v in pairs(_table) do
- monitor.setCursorPos(v.x, v.y)
- monitor.setTextColour(v.txtCol)
- monitor.setBackgroundColour(v.bgCol)
- monitor.write(v.text)
- end
- end
- function isValidClick(_table, mx, my)
- for i, v in pairs(_table) do
- if mx >= v.x and mx <= (v.x + #v.text) and my == v.y then
- return true, v.text
- end
- end
- return false, nil
- end
- writeButtons(t)
- _, but, x, y = os.pullEvent("monitor_touch")
- bClick, option = isValidClick(t, x, y)
- if bClick then
- if tonumber(option) == digit then correct = correct + 1
- else if tonumber(option) ~= digit then correct = 0
- end
- end
- end
- monitor.setCursorPos(7,5)
- monitor.setBackgroundColor(colors.green)
- monitor.setTextColor(colors.white)
- monitor.write(tostring(required-correct))
- if correct >= required then
- redstone.setBundledOutput("back",colors.red)
- sleep(2)
- redstone.setBundledOutput("back",0)
- correct = 0
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement