Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local t = peripheral.wrap("top") --Monitor
- t.setTextScale(0.5)
- local currentGame = {} --table for current game{name, offset, balance, current bet, base bet}
- local function setupCurrentGame(name, offset, bal, bet, base)
- currentGame.name = name
- currentGame.offset = offset
- currentGame.bal = bal
- currentGame.bet = bet
- currentGame.base = base
- end
- local function clearCurrentGame()
- count = #currentGame
- for i =1, count do
- currentGame[i] = nil
- end
- end
- local b = { --table for roulette game buttons {text, x, y, active, bg colour, fg colour, inactive bg colour, inactive fg colour}
- {text = "ODD", x = 3, y = 10, active = false, bg = 32768, fg = 1, inactivebg = 256, inactivefg = 1},
- {text = " 0 ", x = 7, y = 10, active = false, bg = 8192, fg = 1, inactivebg = 256, inactivefg = 1},
- {text = "EVN", x = 11, y = 10, active = false, bg = 16384, fg = 1, inactivebg = 256, inactivefg = 1},
- {text = "SPIN!", x = 6, y = 12, active = false, bg = 32, fg = 1, inactivebg = 256, inactivefg = 1},
- {text = "0", x = 8, y = 18, active = true, bg = 128, fg = 1},
- {text = " +", x = 9, y = 18, active = true, bg = 8192, fg = 1},
- {text = " >", x = 11, y = 18, active = true, bg = 32, fg = 1},
- {text = ' '..string.char(194,59), x = 13, y = 18, active = true, bg = 8192, fg = 1},
- {text = "- ", x = 6, y = 18, active = true, bg = 16384, fg = 1},
- {text = "< ", x = 4, y = 18, active = true, bg = 64, fg = 1},
- {text = string.char(194,43)..' ', x = 2, y = 18, active = true, bg = 16384, fg = 1}
- --,{text = "Quit", x = 8, y = 12, active = true, bg = 16384, fg = 1}
- }
- local function drawButton(buttonTable, i)
- t.setCursorPos(buttonTable[i].x, buttonTable[i].y)
- if buttonTable[i].active then
- t.setBackgroundColor(buttonTable[i].bg)
- t.setTextColor(buttonTable[i].fg)
- else
- t.setBackgroundColor(buttonTable[i].inactivebg)
- t.setTextColor(buttonTable[i].inactivefg)
- end
- t.write(buttonTable[i].text)
- end
- local function drawButtons(buttonTable)
- for i=1, #buttonTable do
- drawButton(buttonTable, i)
- end
- end
- local function drawBackground() --Set cyan background
- t.setBackgroundColor(512)
- t.clear()
- end
- local function drawStatic() --Draw all static boxes and words
- --Credits and bet boxes
- t.setCursorPos(3, 15)
- t.write(" BET")
- t.setCursorPos(3, 16)
- t.write(" ")
- end
- local function drawBal()
- t.setBackgroundColor(128)
- t.setTextColor(1)
- t.setCursorPos(3, 21)
- t.write(" ")
- text = tostring(currentGame.bal)
- t.setCursorPos(14 - #text, 21)
- t.write(text)
- end
- local function drawBet()
- t.setBackgroundColor(128)
- t.setTextColor(1)
- t.setCursorPos(3, 16)
- t.write(" ")
- text = tostring(currentGame.bet)
- t.setCursorPos(14 - #text, 16)
- t.write(text)
- end
- local function checkSpinButton()
- if currentGame.bet > 0 and (b[1].active or b[2].active or b[3].active) then
- b[4].active = true
- drawButton(b, 4)
- else
- b[4].active = false
- drawButton(b, 4)
- end
- end
- local function btnBetType(bType)
- for i=1, 3 do
- if i == bType then
- b[i].active = true
- drawButton(b, i)
- else
- b[i].active = false
- drawButton(b, i)
- end
- end
- checkSpinButton()
- end
- local function btnBet(amount)
- if amount == 0 then
- currentGame.bet = 0
- end
- currentGame.bet = currentGame.bet + amount
- if currentGame.bet < 0 then
- currentGame.bet = 0
- end
- if currentGame.bet > currentGame.bal then
- currentGame.bet = currentGame.bal
- end
- drawBet()
- checkSpinButton()
- end
- local function buttonControl(x, y)
- for i=1, #b do
- if y == b[i].y and x >= b[i].x and x < b[i].x + #b[i].text then
- if i == 1 then btnBetType(1); return
- elseif i == 2 then btnBetType(2); return
- elseif i == 3 then btnBetType(3); return
- elseif i == 4 and b[4].active and currentGame.bet > 0 then btnBetType(0); return
- elseif i == 5 then btnBet(0); return
- elseif i == 6 then btnBet(currentGame.base); return
- elseif i == 7 then btnBet(currentGame.base * 16); return
- elseif i == 8 then btnBet(currentGame.base * 64); return
- elseif i == 9 then btnBet(0-currentGame.base); return
- elseif i == 10 then btnBet(0-currentGame.base * 16); return
- elseif i == 11 then btnBet(0-currentGame.base * 64); return
- elseif i == 12 then return true
- end
- end
- end
- end
- local function drawXY(x, y)
- t.setBackgroundColor(128)
- t.setTextColor(1)
- t.setCursorPos(1, 1)
- t.write(x)
- t.setCursorPos(1, 2)
- t.write(y)
- end
- local function main()
- while true do
- local e, _, x, y, _ = os.pullEvent()
- if e == "monitor_touch" then
- drawXY(x, y)
- if buttonControl(x, y) then
- return
- end
- end
- end
- end
- local function gameSetup(name)
- setupCurrentGame(name, 5, 10000, 0, 1)
- drawBackground()
- drawStatic()
- drawButtons(b)
- drawBet()
- drawBal()
- t.setCursorPos(1, 1)
- t.write(#b[10].text)
- if main() then
- return
- end
- os.pullEvent("player_off")
- end
- gameSetup('test')
Advertisement
Add Comment
Please, Sign In to add comment