Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local password = "12345"
- local buttons = {
- {"1","2","3"},
- {"4","5","6"},
- {"7","8","9"},
- {"C","0","#"},
- }
- local Obj = {}
- local inputCode = {}
- local xSize,ySize = term.getSize()
- local centerX = math.floor(xSize/2)
- local centerX = math.floor(ySize/2)
- --ПОИСК ПЕРИФЕРИИ
- local function findPeripheral(whatToFind)
- local PeriList = peripheral.getNames()
- for i=1,#PeriList do
- if peripheral.getType(PeriList[i]) == whatToFind then
- return PeriList[i]
- end
- end
- end
- --ЧТЕНИЕ КОНФИГА
- function configRead(pathToConfig,whatToRead)
- if not fs.exists(pathToConfig) then error("No such file") end
- local file = fs.open(pathToConfig,"r")
- while true do
- local line = file.readLine()
- if line ~= nil then
- local key, value = string.match(line,"(.*)=(.*)")
- if value ~= nil and key == whatToRead then
- file.close()
- return value
- end
- else
- file.close()
- break
- end
- end
- end
- --ЗАПИСЬ В КОНФИГ
- local function configWrite(pathToConfig,key,value)
- if not fs.exists(pathToConfig) then
- local file = fs.open(pathToConfig,"w")
- file.close()
- end
- local file = fs.open(pathToConfig,"r")
- local Massiv = {}
- local lineCounter = 1
- while true do
- local line = file.readLine()
- if line ~= nil then
- Massiv[lineCounter] = line
- else
- file.close()
- break
- end
- lineCounter = lineCounter + 1
- end
- local success = false
- for i=1,#Massiv do
- local key1, value1 = string.match(Massiv[i],"(.*)=(.*)")
- if value1 ~= nil and key1 == key then
- Massiv[i] = key.."="..value
- success = true
- end
- end
- if success == false then Massiv[#Massiv+1] = key.."="..value end
- local file = fs.open(pathToConfig,"w")
- for i=1,#Massiv do
- file.writeLine(Massiv[i])
- end
- file.close()
- end
- --ОБЪЕКТЫ
- local function newObj(name,x,y)
- Obj[name]={}
- Obj[name]["x"]=x
- Obj[name]["y"]=y
- end
- --ПРОСТАЯ ЗАЛИВКА ЭКРАНА ЦВЕТОМ
- local function clearScreen(color)
- term.setBackgroundColor(color)
- term.clear()
- end
- --ПРОСТОЙ ТЕКСТ
- local function usualText(x,y,text)
- term.setCursorPos(x,y)
- term.write(text)
- end
- --ОТРИСОВКА ВЕРХНЕЙ ШТУЧКИ
- local function drawTab(textColor,backColor)
- term.setBackgroundColor(backColor)
- term.setTextColor(textColor)
- term.setCursorPos(2,1)
- term.clearLine()
- term.write("-----")
- for i=1,#inputCode do
- usualText(1+i,1,inputCode[i])
- end
- end
- ----------------------CТАРТ ПРОГРАММЫ------------------------------------
- --ПОДКЛЮЧЕНИЕ МОНИТОРА
- local m = findPeripheral("monitor")
- if m ~= nil then
- m = peripheral.wrap(m)
- if not m.isColor() then error("This program works ONLY with advanced monitor.") end
- m.setTextScale(1)
- term.redirect(m)
- else
- error("This program requires advanced external monitor.")
- end
- --ЧТЕНИЕ КОНФИГА
- if fs.exists("System/CodeDoor/password.cfg") then
- password = configRead("System/CodeDoor/password.cfg","password")
- else
- configWrite("System/CodeDoor/password.cfg","password","12345")
- end
- term.setCursorBlink(false)
- clearScreen(colors.white)
- term.setTextColor(colors.black)
- for j=1,#buttons do
- for i=1,#buttons[j] do
- local xPos = i*2
- local yPos = 1+j
- usualText(xPos,yPos,buttons[j][i])
- newObj(buttons[j][i],xPos,yPos)
- end
- end
- drawTab(colors.white,colors.black)
- while true do
- local event,side,x,y = os.pullEvent()
- if event == "monitor_touch" then
- for key,val in pairs(Obj) do
- if x==Obj[key]["x"] and y==Obj[key]["y"] then
- term.setBackgroundColor(colors.green)
- term.setTextColor(colors.white)
- usualText(Obj[key]["x"],Obj[key]["y"],key)
- sleep(0.2)
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- usualText(Obj[key]["x"],Obj[key]["y"],key)
- if key ~= "C" and key ~= "#" then
- if #inputCode < 5 then
- inputCode[#inputCode+1] = key
- drawTab(colors.white,colors.black)
- end
- elseif key == "C" then
- inputCode = {}
- drawTab(colors.white,colors.black)
- elseif key == "#" then
- local inputPass = ""
- for i=1,#inputCode do
- inputPass = inputPass..inputCode[i]
- end
- if inputPass == password then
- drawTab(colors.white,colors.green)
- sleep(5)
- inputCode = {}
- drawTab(colors.white,colors.black)
- else
- drawTab(colors.white,colors.red)
- sleep(1)
- drawTab(colors.white,colors.black)
- end
- end
- break
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement