Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function resetCode()
- one = false
- two = false
- three = false
- four = false
- five = false
- six = false
- seven = false
- eight = false
- nine = false
- passwordString = " "
- end
- resetCode()
- --------------------------------------------
- local mon = peripheral.wrap("top")
- mon.setTextScale(1)
- mon.setTextColor(colors.white)
- local button={}
- mon.setBackgroundColor(colors.black)
- function setTable(name, func, xmin, xmax, ymin, ymax)
- button[name] = {}
- button[name]["func"] = func
- button[name]["active"] = false
- button[name]["xmin"] = xmin
- button[name]["ymin"] = ymin
- button[name]["xmax"] = xmax
- button[name]["ymax"] = ymax
- end
- function funcName()
- print("You clicked buttonText")
- end
- function fillTable()
- setTable("1", password1, 1, 1, 1, 1)
- setTable("2", password2, 3, 3, 1, 1)
- setTable("3", password3, 5, 5, 1, 1)
- setTable("4", password4, 1, 1, 3, 3)
- setTable("5", password5, 3, 3, 3, 3)
- setTable("6", password6, 5, 5, 3, 3)
- setTable("7", password7, 1, 1, 5, 5)
- setTable("8", password8, 3, 3, 5, 5)
- setTable("9", password9, 5, 5, 5, 5)
- setTable("*", passwordValid, 7, 7, 5, 5)
- setTable("C", resetCode, 7, 7, 1, 1)
- -- setTable("OtherButton is COOL!", funcName, 5, 35, 10, 12)
- end
- function password1()
- one = true
- print("ping")
- passwordString = passwordString.."1"
- end
- function password2()
- two = true
- print("ping")
- passwordString = passwordString.."2"
- end
- function password3()
- three = true
- print("ping")
- passwordString = passwordString.."3"
- end
- function password4()
- four = true
- print("ping4")
- passwordString = passwordString.."4"
- end
- function password5()
- five = true
- print("ping5")
- passwordString = passwordString.."5"
- end
- function password6()
- six = true
- passwordString = passwordString.."6"
- end
- function password7()
- seven = true
- passwordString = passwordString.."7"
- end
- function password8()
- eight = true
- passwordString = passwordString.."8"
- end
- function password9()
- nine = true
- passwordString = passwordString.."9"
- end
- function fill(text, color, bData)
- mon.setBackgroundColor(color)
- local yspot = math.floor((bData["ymin"] + bData["ymax"]) /2)
- local xspot = math.floor((bData["xmax"] - bData["xmin"] - string.len(text)) /2) +1
- for j = bData["ymin"], bData["ymax"] do
- mon.setCursorPos(bData["xmin"], j)
- if j == yspot then
- for k = 0, bData["xmax"] - bData["xmin"] - string.len(text) +1 do
- if k == xspot then
- mon.write(text)
- else
- mon.write(" ")
- end
- end
- else
- for i = bData["xmin"], bData["xmax"] do
- mon.write(" ")
- end
- end
- end
- mon.setBackgroundColor(colors.black)
- end
- function screen()
- local currColor
- for name,data in pairs(button) do
- local on = data["active"]
- if on == true then
- currColor = colors.lime
- currColor = colors.red
- else currColor = colors.red
- end
- fill(name, currColor, data)
- end
- end
- function checkxy(x, y)
- for name, data in pairs(button) do
- if y>=data["ymin"] and y <= data["ymax"] then
- if x>=data["xmin"] and x<= data["xmax"] then
- data["func"]()
- data["active"] = not data["active"]
- print(name)
- end
- end
- end
- end
- function heading(text)
- w, h = mon.getSize()
- mon.setCursorPos((w-string.len(text))/2+1, 1)
- mon.write(text)
- end
- fillTable()
- print(passwordString)
- function passwordValid()
- if one == true then
- print("test")
- end
- if passwordString == " 1234" then
- print("password accepted")
- print(passwordString)
- print("pass")
- redstone.setOutput("right", true)
- sleep(10)
- redstone.setOutput("right", false)
- passwordString = " "
- else
- print(passwordString)
- print("fail")
- end
- one = false
- two = false
- three = false
- four = false
- five = false
- six = false
- seven = false
- eight = false
- nine = false
- print("code reset")
- end
- passwordValid()
- print("PINGALING")
- while true do
- mon.clear()
- heading(" ")
- screen()
- local e,side,x,y = os.pullEvent("monitor_touch")
- print(x..":"..y)
- checkxy(x,y)
- sleep(.1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement