Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local event = require("event")
- local chest = component.chest
- local interface = component.me_interface
- local unicode = require("unicode")
- local gpu = component.gpu
- local computer = require('computer')
- local terminal = require("term")
- local cb = component.chat_box
- local setTextColor = gpu.setForeground
- -- local timeRelog = 10
- local nickPlayer = ""
- -- local eventTimer
- local digit = ""
- local stateMoney = false
- cb.setName("§cУгадай§7Число§7")
- local colors = {
- main = 0xFF5555,
- white = 0xFFFFFF
- }
- local digitsOfStr = {
- "один",
- "два",
- "три",
- "четыре",
- "пять"
- -- "шесть",
- -- "семь",
- -- "восемь",
- -- "девять",
- -- "десять"
- }
- local maxW, maxH = 90, 26
- gpu.setResolution(maxW, maxH)
- function drawBox(x, y, width, height, colorBorder, text, colorText, align)
- setTextColor(colorBorder)
- gpu.fill(x, y, 1, height, "│")
- gpu.fill(x + width - 1 , y, 1, height, "│")
- gpu.set(x, y, "┌" .. string.rep('─', width - 2) .. "┐")
- gpu.set(x, y + height - 1,"└" .. string.rep("─", width - 2) .. "┘")
- if text then
- setTextColor(colorText)
- gpu.set(x + align, y + 1, text)
- end
- end
- function drawScreenMain()
- terminal.clear()
- drawBox(1, 1, maxW, maxH, colors.main, _, _, _)
- setTextColor(colors.white)
- drawBox(25, 1, 40, 3, colors.white, "Привет, удачи и приятной игры!", colors.white, 5)
- drawBox(3, 5, 40, 18, colors.white, _, _, _)
- gpu.set(17, 5, "| Пояснения |")
- gpu.set(5, 8, "Суть игры проста, тебе нужно")
- gpu.set(5, 10, "угадать число от 1 до 5")
- gpu.set(5, 12, "Ставка: деньги х1")
- gpu.set(5, 14, "Приз: деньги х5")
- gpu.set(5, 17, "Сейчас в банке: " .. interface.getStackInSlot(1).qty .. " банкнот")
- gpu.set(5, 18, "Тыкай по кнопке и вперед!")
- gpu.set(5, 20, "В случае проблем: /tell FERROUS")
- drawBox(47, 5, 41, 18, colors.white, _, _, _)
- gpu.set(62, 5, "| Правила |")
- gpu.set(49, 8, "1. Формат ответа: один, два, три и тд")
- gpu.set(49, 10, "2. Писать ответ в локал. чат")
- -- gpu.set(49, 12, "3. Время на игру - 40 секунд")
- gpu.set(49, 12, "3. Приходить еще и звать друзей:)")
- drawBox(35, 24, 21, 3, colors.main, "Начать игру", colors.white, 4)
- end
- function drawScreenGame()
- drawBox(1, 1, maxW, maxH, colors.main, _, _, _)
- drawBox(30, 1, 32, 3, colors.white, "Игрок: " .. nickPlayer, colors.white, 3)
- drawBox(30, maxH / 2, 30, 3, colors.main, "Бот загадал число", colors.white, 7)
- end
- function randomDigit()
- return digitsOfStr[math.random(1, 5)]
- end
- function resetUsers()
- local users = { computer.users() }
- for i = 1, #users do
- computer.removeUser(users[i])
- end
- end
- function gameOver(digit)
- -- event.cancel(eventTimer)
- resetUsers()
- gpu.fill(30, maxH / 2, 35, 3, " ")
- drawBox(30, maxH / 2, 35, 3, colors.main, "Бот загадал число - " .. digit, colors.white, 5)
- os.sleep(2)
- -- timeRelog = 10
- stateMoney = false
- drawScreenMain()
- end
- -- function printTime(digit)
- -- timeRelog = timeRelog - 1
- -- if timeRelog <= 0 then
- -- event.cancel(eventTimer)
- -- resetUsers()
- -- gpu.fill(30, maxH / 2, 35, 3, " ")
- -- drawBox(30, maxH / 2, 35, 3, colors.main, "Время вышло!", colors.white, 12)
- -- os.sleep(2)
- -- timeRelog = 10
- -- stateMoney = false
- -- drawScreenMain()
- -- end
- -- if nickPlayer ~= nil then
- -- gpu.set(50, 2, "Время: " .. timeRelog .. "c.")
- -- end
- -- end
- function findElement(array, str)
- local state = false
- for k, v in pairs(array) do
- if v == str then
- state = true
- end
- end
- return state
- end
- drawScreenMain()
- while true do
- local e, _, w, h, _, name = event.pull(1, "touch")
- if e == "touch" then
- nickPlayer = name
- computer.addUser(nickPlayer)
- if w >= 35 and w <= 55 and h >= 24 and h <= 26 then
- for i = 1, chest.getInventorySize() do
- local item = chest.getStackInSlot(i)
- if item and item.name == "npcMoney" and item.qty >= 1 then
- if interface.getStackInSlot(1) and interface.getStackInSlot(1).qty >= 5 then
- chest.pushItemIntoSlot("DOWN", i, 1, 1)
- terminal.clear()
- drawScreenGame()
- -- eventTimer = event.timer(1, printTime, math.huge)
- digit = randomDigit()
- while true do
- local _, _, nick, msg = event.pull(1, "chat_message")
- if msg ~= nil and nick ~= nil then
- if nick == nickPlayer then
- if findElement(digitsOfStr, msg) then
- if msg == digit then
- gpu.fill(30, maxH / 2, 30, 3,' ')
- drawBox(30, maxH / 2, 30, 3, colors.main, "Ты выиграл!", colors.white, 9)
- cb.say("§a" .. nickPlayer .. " выиграл 5 эм")
- interface.pushItemIntoSlot("UP", 1, 5, 1)
- os.sleep(1)
- else
- gpu.fill(30, maxH / 2, 30, 3,' ')
- drawBox(30, maxH / 2, 30, 3, colors.main, "Ты проиграл!", colors.white, 9)
- os.sleep(1)
- end
- gameOver(digit)
- break
- end
- end
- end
- end
- end
- else
- stateMoney = true
- end
- end
- end
- if stateMoney then
- stateMoney = false
- cb.say("§a" .. nickPlayer .. ", для начала надо внести ставку (деньги х1)")
- resetUsers()
- end
- end
- end
Add Comment
Please, Sign In to add comment