Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- OpenComputers Casino Program (Full Version)
- -- Author: ChatGPT / User Project
- -- Features: GUI, multiple games, PIM item input, ME item output, settings saving
- local component = require("component")
- local event = require("event")
- local term = require("term")
- local fs = require("filesystem")
- local serialization = require("serialization")
- local computer = require("computer")
- local gpu = component.gpu
- -- Optional components
- local me = component.isAvailable("me_interface") and component.me_interface
- local pim = component.isAvailable("pim") and component.pim
- -- Paths
- local configPath = "/casino_config.dat"
- -- Global state
- local screenWidth, screenHeight = gpu.getResolution()
- local balance = 0
- local settings = {
- payoutItem = "minecraft:diamond",
- payoutAmount = 1,
- games = { "slots", "coinflip" },
- }
- -- GUI Utilities
- local function centerText(y, text)
- local x = math.floor((screenWidth - #text) / 2)
- gpu.set(x, y, text)
- end
- local function drawFrame()
- gpu.fill(1, 1, screenWidth, screenHeight, " ")
- gpu.setForeground(0xFFFFFF)
- centerText(1, "=== Казино 9000 ===")
- gpu.set(2, 3, "Ваш баланс: " .. tostring(balance) .. " монет")
- end
- -- Save/Load config
- local function saveSettings()
- local file = io.open(configPath, "w")
- if file then
- file:write(serialization.serialize(settings))
- file:close()
- end
- end
- local function loadSettings()
- if fs.exists(configPath) then
- local file = io.open(configPath, "r")
- if file then
- local data = file:read("*a")
- settings = serialization.unserialize(data) or settings
- file:close()
- end
- end
- end
- -- PIM item payment (insert diamond to play)
- local function waitForPayment()
- if not pim then return end
- centerText(5, "Ожидание оплаты (вставьте алмаз в PIM)...")
- while true do
- local _, _, address, slot = event.pull("pim_inventory_changed")
- local stack = pim.getStackInSlot(slot)
- if stack and stack.name == settings.payoutItem then
- pim.pushItem(slot)
- balance = balance + 1
- break
- end
- end
- end
- -- ME item output (выдача выигрыша)
- local function payout()
- if not me then return end
- me.exportItem({name=settings.payoutItem, count=settings.payoutAmount}, "down")
- end
- -- Game logic
- local function playSlots()
- local result = {"🍒", "🔔", "💎", "🍋"}
- local spin = {}
- for i = 1, 3 do
- spin[i] = result[math.random(1, #result)]
- end
- centerText(10, table.concat(spin, " | "))
- if spin[1] == spin[2] and spin[2] == spin[3] then
- centerText(12, "Вы выиграли!")
- payout()
- else
- centerText(12, "Попробуйте снова!")
- end
- end
- local function playCoinflip()
- local outcome = math.random(1, 2)
- local side = outcome == 1 and "Орел 🪙" or "Решка 🪙"
- centerText(10, "Результат: " .. side)
- if outcome == 1 then
- centerText(12, "Вы выиграли!")
- payout()
- else
- centerText(12, "Попробуйте снова!")
- end
- end
- local function gameMenu()
- local choice = 1
- while true do
- drawFrame()
- centerText(6, "Выберите игру:")
- for i, game in ipairs(settings.games) do
- gpu.set(4, 7+i, (i == choice and "-> " or " ") .. game)
- end
- local _, _, _, key = event.pull("key_down")
- if key == 200 then -- up
- choice = choice > 1 and choice - 1 or #settings.games
- elseif key == 208 then -- down
- choice = choice < #settings.games and choice + 1 or 1
- elseif key == 28 then -- enter
- term.clear()
- if settings.games[choice] == "slots" then
- playSlots()
- elseif settings.games[choice] == "coinflip" then
- playCoinflip()
- end
- os.sleep(3)
- break
- end
- end
- end
- -- MAIN
- math.randomseed(os.time())
- loadSettings()
- while true do
- term.clear()
- drawFrame()
- waitForPayment()
- gameMenu()
- end
Add Comment
Please, Sign In to add comment