Advertisement
lokin135

kazino

Jul 21st, 2017
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.10 KB | None | 0 0
  1. local event = require("event")
  2. local shell = require("shell")
  3. local com = require("component")
  4. local term = require("term")
  5. local fs = require("filesystem")
  6. local comp = require("computer")
  7. function event.shouldSoftInterrupt() return false end
  8. function event.shouldInterrupt() return false end
  9. local card = com.card_reader
  10. local red = com.redstone
  11. local gpu = com.gpu
  12. local owner = "lokin135" -- кому будет перечисляться червонцы
  13. local price = 50 -- цена за вход
  14. local side_red_prize = require("sides").down -- сторона, для подачи ред. сигнала на выдачу приза
  15. local timer_door = 3 -- время открытия двери
  16. local win_lvl = 2 -- шанс выигрыша. чем меньше, тем выше шанс
  17. local background = 0x161a1e
  18. local foreground = 0xf5f5f5
  19. local pach = "/home/log.txt" -- путь лога
  20. local user_num
  21. local result
  22. local start_page_txt
  23. local player
  24. local time
  25. local oldtime = 0
  26. local outwin
  27.  
  28. function os.dateRL(format)
  29.   if not fs.get("/").isReadOnly() then
  30.     local time = io.open("/tmp/.time", "w")
  31.       time:write()
  32.         time:close()
  33.         os.sleep(0.01)
  34.       return os.date(format, fs.lastModified("/tmp/.time") / 1000)
  35.   else
  36.     return os.date(format)
  37.   end
  38. end
  39. function logic(number)
  40.   local output = {}
  41.   local seed
  42.   math.randomseed(os.time())
  43.   for i=1,3 do
  44.     seed = math.random(number,number + win_lvl)
  45.     output[i] = seed
  46.     os.sleep(1)
  47.   end
  48.   return output
  49. end
  50.  
  51. function GUI_Start_Page()
  52.   gpu.setBackground(background)
  53.   gpu.setForeground(foreground)
  54.   gpu.setResolution(40,20)
  55.   start_page_txt = [[
  56.  
  57.  
  58.  
  59.  
  60.            Казино "Lucky Loki"
  61.             Для сильных духом
  62.  
  63. Как играть:
  64. --Возьмите в руки смарт-карту;
  65. --Кликните правой кнопкой по считывателю
  66.   карт;
  67. --Подтвердите платёж;
  68. --Введите число от 1 до 100 и нажмите
  69.   Enter;
  70. --Надейтесь на милость Локи.
  71. ]]
  72.   term.clear()
  73.   print(start_page_txt)
  74. end
  75.  
  76. function GUI_Play()
  77.   term.clear()
  78.   while true do
  79.     term.clear()
  80.     gpu.set(15,10,"Ваше число: ")
  81.     term.setCursor(26,10)
  82.     user_num = tonumber(term.read())
  83.     term.clear()
  84.     if type(user_num) == "number" and user_num<=100 and user_num>0 then result = logic(user_num); break else
  85.     gpu.setForeground(0x7a0008)
  86.     gpu.set(15,10,"Ошибка ввода")
  87.     gpu.setForeground(foreground)
  88.     os.sleep(1.5)
  89.     term.clear()
  90.      end
  91.   end
  92.   gpu.setResolution(8,4)
  93.   for i=1,3 do gpu.set(4,1+i,result[i].." "); os.sleep(1) end
  94.   term.clear()
  95.   gpu.setResolution(14,7) -- 7
  96.   if result[1] == result[2] and result[2] == result[3] and result[1] == user_num then
  97.     gpu.setForeground(0x478c3c)
  98.     gpu.set(1,4,"ВЫ ВЫЙГРАЛИ!!!")
  99.     gpu.setForeground(foreground)
  100.     outwin = true
  101.     red.setOutput(side_red_prize,15)
  102.     os.sleep(0.5)
  103.     red.setOutput(side_red_prize,0)
  104.     os.sleep(2)
  105.   else
  106.     gpu.setForeground(0x7a0008)
  107.     gpu.set(1,4,"ВЫ ПРОИГРАЛИ!!")
  108.     gpu.setForeground(foreground)
  109.     outwin = false
  110.     os.sleep(2)
  111.   end
  112.   term.clear()
  113.   logging()
  114. end
  115.  
  116. function upload_log()
  117.   shell.execute("/lib/git.lua --t=ef23fcf68537cf199d899457a33675827187df65 -p --P=p --d=kazino --u=ed32e89643c51cb17eb26223f2c1bad1 /home/log.txt=log.txt")
  118. end
  119.  
  120. function logging()
  121.   local log = io.open(shell.resolve(pach),"a")
  122.   time = comp.uptime()
  123.   outwin = outwin and "Победа" or "Проигрыш"
  124.   log:write("Игрок:"..player.." Время:"..os.dateRL("%x %X").." Результат:"..outwin.."\n")
  125.   log:flush()
  126.   log:close()
  127.   if (comp.uptime() - oldtime) > 60*5 then upload_log(); oldtime = comp.uptime() end
  128. end
  129.  
  130. function card_pass()
  131.     card.pay(owner,price)
  132.     local ev = table.pack(event.pull())
  133.     player = ev[9]
  134.     if ev[1] == "card_event" and ev[3] == "payment_result" and ev[4] then return true else return false end
  135. end
  136.  
  137. while true do
  138.   GUI_Start_Page()
  139.   if card_pass() then GUI_Play() end
  140. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement