Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local event = require("event")
- local shell = require("shell")
- local com = require("component")
- local term = require("term")
- local fs = require("filesystem")
- local comp = require("computer")
- function event.shouldSoftInterrupt() return false end
- function event.shouldInterrupt() return false end
- local card = com.card_reader
- local red = com.redstone
- local gpu = com.gpu
- local owner = "lokin135" -- кому будет перечисляться червонцы
- local price = 50 -- цена за вход
- local side_red_prize = require("sides").down -- сторона, для подачи ред. сигнала на выдачу приза
- local timer_door = 3 -- время открытия двери
- local win_lvl = 2 -- шанс выигрыша. чем меньше, тем выше шанс
- local background = 0x161a1e
- local foreground = 0xf5f5f5
- local pach = "/home/log.txt" -- путь лога
- local user_num
- local result
- local start_page_txt
- local player
- local time
- local oldtime = 0
- local outwin
- function os.dateRL(format)
- if not fs.get("/").isReadOnly() then
- local time = io.open("/tmp/.time", "w")
- time:write()
- time:close()
- os.sleep(0.01)
- return os.date(format, fs.lastModified("/tmp/.time") / 1000)
- else
- return os.date(format)
- end
- end
- function logic(number)
- local output = {}
- local seed
- math.randomseed(os.time())
- for i=1,3 do
- seed = math.random(number,number + win_lvl)
- output[i] = seed
- os.sleep(1)
- end
- return output
- end
- function GUI_Start_Page()
- gpu.setBackground(background)
- gpu.setForeground(foreground)
- gpu.setResolution(40,20)
- start_page_txt = [[
- Казино "Lucky Loki"
- Для сильных духом
- Как играть:
- --Возьмите в руки смарт-карту;
- --Кликните правой кнопкой по считывателю
- карт;
- --Подтвердите платёж;
- --Введите число от 1 до 100 и нажмите
- Enter;
- --Надейтесь на милость Локи.
- ]]
- term.clear()
- print(start_page_txt)
- end
- function GUI_Play()
- term.clear()
- while true do
- term.clear()
- gpu.set(15,10,"Ваше число: ")
- term.setCursor(26,10)
- user_num = tonumber(term.read())
- term.clear()
- if type(user_num) == "number" and user_num<=100 and user_num>0 then result = logic(user_num); break else
- gpu.setForeground(0x7a0008)
- gpu.set(15,10,"Ошибка ввода")
- gpu.setForeground(foreground)
- os.sleep(1.5)
- term.clear()
- end
- end
- gpu.setResolution(8,4)
- for i=1,3 do gpu.set(4,1+i,result[i].." "); os.sleep(1) end
- term.clear()
- gpu.setResolution(14,7) -- 7
- if result[1] == result[2] and result[2] == result[3] and result[1] == user_num then
- gpu.setForeground(0x478c3c)
- gpu.set(1,4,"ВЫ ВЫЙГРАЛИ!!!")
- gpu.setForeground(foreground)
- outwin = true
- red.setOutput(side_red_prize,15)
- os.sleep(0.5)
- red.setOutput(side_red_prize,0)
- os.sleep(2)
- else
- gpu.setForeground(0x7a0008)
- gpu.set(1,4,"ВЫ ПРОИГРАЛИ!!")
- gpu.setForeground(foreground)
- outwin = false
- os.sleep(2)
- end
- term.clear()
- logging()
- end
- function upload_log()
- shell.execute("/lib/git.lua --t=ef23fcf68537cf199d899457a33675827187df65 -p --P=p --d=kazino --u=ed32e89643c51cb17eb26223f2c1bad1 /home/log.txt=log.txt")
- end
- function logging()
- local log = io.open(shell.resolve(pach),"a")
- time = comp.uptime()
- outwin = outwin and "Победа" or "Проигрыш"
- log:write("Игрок:"..player.." Время:"..os.dateRL("%x %X").." Результат:"..outwin.."\n")
- log:flush()
- log:close()
- if (comp.uptime() - oldtime) > 60*5 then upload_log(); oldtime = comp.uptime() end
- end
- function card_pass()
- card.pay(owner,price)
- local ev = table.pack(event.pull())
- player = ev[9]
- if ev[1] == "card_event" and ev[3] == "payment_result" and ev[4] then return true else return false end
- end
- while true do
- GUI_Start_Page()
- if card_pass() then GUI_Play() end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement