Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local board_img_id = "vkckzmq3"
- local mon, old, loggedIn, selected, name, balance, winningNumber
- local state = {
- red = 0,
- black = 0,
- onetosix = 0,
- fourtonine = 0,
- seventotwelve = 0,
- one = 0,
- two = 0,
- three = 0,
- four = 0,
- five = 0,
- six = 0,
- seven = 0,
- eight = 0,
- nine = 0,
- ten = 0,
- eleven = 0,
- twelve = 0,
- zero = 0
- }
- function init()
- shell.run("delete board.nfp")
- shell.run("pastebin", "get", board_img_id, "board.nfp")
- board_img = paintutils.loadImage("board.nfp")
- mon = peripheral.find("monitor")
- mon.setTextScale(0.5)
- old = term.redirect(mon)
- w, h = term.getSize()
- rednet.open("left")
- loggedIn = false
- selected = 1
- winningNumber = nil
- end
- function renderBoard()
- if board_img ~= nil then
- paintutils.drawImage(board_img, 1, 1)
- end
- term.setBackgroundColor(colors.green)
- term.setTextColor(colors.red)
- term.setCursorPos(3, 23)
- term.write("leave")
- term.setTextColor(colors.white)
- term.setCursorPos(22, 1)
- term.write("welcome, ")
- term.write(name)
- term.write("!")
- term.setCursorPos(42, 1)
- term.write("balance: $")
- term.write(balance)
- term.setCursorPos(9,7)
- if state.red ~= 0 then setCoinColor(state.red) else term.setBackgroundColor(colors.red) end
- term.write(" ")
- term.setCursorPos(9,16)
- if state.black ~= 0 then setCoinColor(state.black) else term.setBackgroundColor(colors.black) end
- term.write(" ")
- term.setCursorPos(19,6)
- if state.onetosix ~= 0 then setCoinColor(state.onetosix) else term.setBackgroundColor(colors.green) end
- term.write("1 - 6")
- term.setCursorPos(19,12)
- if state.fourtonine ~= 0 then setCoinColor(state.fourtonine) else term.setBackgroundColor(colors.green) end
- term.write("4 - 9")
- term.setCursorPos(19,18)
- if state.seventotwelve ~= 0 then setCoinColor(state.seventotwelve) else term.setBackgroundColor(colors.green) end
- term.write("7 - 12")
- term.setCursorPos(34,6)
- if state.three ~= 0 then setCoinColor(state.three) else term.setBackgroundColor(colors.red) end
- term.write("3")
- term.setCursorPos(34,12)
- if state.two ~= 0 then setCoinColor(state.two) else term.setBackgroundColor(colors.black) end
- term.write("2")
- term.setCursorPos(34,18)
- if state.one ~= 0 then setCoinColor(state.one) else term.setBackgroundColor(colors.red) end
- term.write("1")
- term.setCursorPos(41,6)
- if state.six ~= 0 then setCoinColor(state.six) else term.setBackgroundColor(colors.black) end
- term.write("6")
- term.setCursorPos(41,12)
- if state.five ~= 0 then setCoinColor(state.five) else term.setBackgroundColor(colors.red) end
- term.write("5")
- term.setCursorPos(41,18)
- if state.four ~= 0 then setCoinColor(state.four) else term.setBackgroundColor(colors.black) end
- term.write("4")
- term.setCursorPos(48,6)
- if state.nine ~= 0 then setCoinColor(state.nine) else term.setBackgroundColor(colors.red) end
- term.write("9")
- term.setCursorPos(48,12)
- if state.eight ~= 0 then setCoinColor(state.eight) else term.setBackgroundColor(colors.black) end
- term.write("8")
- term.setCursorPos(48,18)
- if state.seven ~= 0 then setCoinColor(state.seven) else term.setBackgroundColor(colors.red) end
- term.write("7")
- term.setCursorPos(55,6)
- if state.twelve ~= 0 then setCoinColor(state.twelve) else term.setBackgroundColor(colors.black) end
- term.write("12")
- term.setCursorPos(55,12)
- if state.eleven ~= 0 then setCoinColor(state.eleven) else term.setBackgroundColor(colors.red) end
- term.write("11")
- term.setCursorPos(55,18)
- if state.ten ~= 0 then setCoinColor(state.ten) else term.setBackgroundColor(colors.black) end
- term.write("10")
- term.setCursorPos(62,12)
- if state.zero ~= 0 then setCoinColor(state.zero) else term.setBackgroundColor(colors.green) end
- term.write("0")
- term.setTextColor(colors.black)
- term.setCursorPos(72,6)
- if selected == 1 then term.setBackgroundColor(colors.red) else term.setBackgroundColor(colors.yellow) end
- term.write("$1")
- term.setCursorPos(72,10)
- if selected == 4 then term.setBackgroundColor(colors.red) else term.setBackgroundColor(colors.orange) end
- term.write("$4")
- term.setCursorPos(72,14)
- if selected == 16 then term.setBackgroundColor(colors.red) else term.setBackgroundColor(colors.pink) end
- term.write("$16")
- term.setCursorPos(72,18)
- if selected == 64 then term.setBackgroundColor(colors.red) else term.setBackgroundColor(colors.lightBlue) end
- term.write("$64")
- end
- function clickHandler()
- event, side, x, y = os.pullEvent("monitor_touch")
- if side ~= nil then
- if checkBounds(x, y, 1, 22, 10, 24) then
- loggedIn = false
- local b = fs.open("/disk/b.dat", "w")
- b.write(balance)
- b.close()
- disk.eject("right")
- name = nil
- balance = nil
- end
- if checkBounds(x, y, 5, 4, 14, 11) then
- if state.red == selected then
- balance = balance + state.red
- state.red = 0
- elseif selected <= balance then
- balance = balance - selected
- state.red = selected
- end
- end
- if checkBounds(x, y, 5, 13, 14, 20) then
- if state.black == selected then
- balance = balance + state.black
- state.black = 0
- elseif selected <= balance then
- balance = balance - selected
- state.black = selected
- end
- end
- if checkBounds(x, y, 17, 4, 25, 8) then
- if state.onetosix == selected then
- balance = balance + state.onetosix
- state.onetosix = 0
- elseif selected <= balance then
- balance = balance - selected
- state.onetosix = selected
- end
- end
- if checkBounds(x, y, 17, 10, 25, 14) then
- if state.fourtonine == selected then
- balance = balance + state.fourtonine
- state.fourtonine = 0
- elseif selected <= balance then
- balance = balance - selected
- state.fourtonine = selected
- end
- end
- if checkBounds(x, y, 17, 16, 25, 20) then
- if state.seventotwelve == selected then
- balance = balance + state.seventotwelve
- state.seventotwelve = 0
- elseif selected <= balance then
- balance = balance - selected
- state.seventotwelve = selected
- end
- end
- if checkBounds(x, y, 32, 4, 36, 8) then
- if state.three == selected then
- balance = balance + state.three
- state.three = 0
- elseif selected <= balance then
- balance = balance - selected
- state.three = selected
- end
- end
- if checkBounds(x, y, 32, 10, 36, 14) then
- if state.two == selected then
- balance = balance + state.two
- state.two = 0
- elseif selected <= balance then
- balance = balance - selected
- state.two = selected
- end
- end
- if checkBounds(x, y, 32, 16, 36, 20) then
- if state.one == selected then
- balance = balance + state.one
- state.one = 0
- elseif selected <= balance then
- balance = balance - selected
- state.one = selected
- end
- end
- if checkBounds(x, y, 39, 4, 43, 8) then
- if state.six == selected then
- balance = balance + state.six
- state.six = 0
- elseif selected <= balance then
- balance = balance - selected
- state.six = selected
- end
- end
- if checkBounds(x, y, 39, 10, 43, 14) then
- if state.five == selected then
- balance = balance + state.five
- state.five = 0
- elseif selected <= balance then
- balance = balance - selected
- state.five = selected
- end
- end
- if checkBounds(x, y, 39, 16, 43, 20) then
- if state.four == selected then
- balance = balance + state.four
- state.four = 0
- elseif selected <= balance then
- balance = balance - selected
- state.four = selected
- end
- end
- if checkBounds(x, y, 46, 4, 50, 8) then
- if state.nine == selected then
- balance = balance + state.nine
- state.nine = 0
- elseif selected <= balance then
- balance = balance - selected
- state.nine = selected
- end
- end
- if checkBounds(x, y, 46, 10, 50, 14) then
- if state.eight == selected then
- balance = balance + state.eight
- state.eight = 0
- elseif selected <= balance then
- balance = balance - selected
- state.eight = selected
- end
- end
- if checkBounds(x, y, 46, 16, 50, 20) then
- if state.seven == selected then
- balance = balance + state.seven
- state.seven = 0
- elseif selected <= balance then
- balance = balance - selected
- state.seven = selected
- end
- end
- if checkBounds(x, y, 53, 4, 57, 8) then
- if state.twelve == selected then
- balance = balance + state.twelve
- state.twelve = 0
- elseif selected <= balance then
- balance = balance - selected
- state.twelve = selected
- end
- end
- if checkBounds(x, y, 53, 10, 57, 14) then
- if state.eleven == selected then
- balance = balance + state.eleven
- state.eleven = 0
- elseif selected <= balance then
- balance = balance - selected
- state.eleven = selected
- end
- end
- if checkBounds(x, y, 53, 16, 57, 20) then
- if state.ten == selected then
- balance = balance + state.ten
- state.ten = 0
- elseif selected <= balance then
- balance = balance - selected
- state.ten = selected
- end
- end
- if checkBounds(x, y, 60, 4, 64, 20) then
- if state.zero == selected then
- balance = balance + state.zero
- state.zero = 0
- elseif selected <= balance then
- balance = balance - selected
- state.zero = selected
- end
- end
- if checkBounds(x, y, 71, 5, 75, 7) then selected = 1 end
- if checkBounds(x, y, 71, 9, 75, 11) then selected = 4 end
- if checkBounds(x, y, 71, 13, 75, 15) then selected = 16 end
- if checkBounds(x, y, 71, 17, 75, 19) then selected = 64 end
- end
- end
- function checkBounds(x, y, x1, y1, x2, y2)
- return x >= x1 and y >= y1 and x <= x2 and y <= y2
- end
- function setCoinColor(coin)
- if coin == 1 then
- term.setBackgroundColor(colors.yellow)
- elseif coin == 4 then
- term.setBackgroundColor(colors.orange)
- elseif coin == 16 then
- term.setBackgroundColor(colors.pink)
- else
- term.setBackgroundColor(colors.lightBlue)
- end
- end
- function calculateWinnings()
- local p = 0
- if winningNumber == 0 then
- if state.zero ~= 0 then p = p + (12 * state.zero) end
- elseif winningNumber == 1 then
- if state.one ~= 0 then p = p + (12 * state.one) end
- if state.red ~= 0 then p = p + (2 * state.red) end
- if state.onetosix ~= 0 then p = p + (3 * state.onetosix) end
- elseif winningNumber == 2 then
- if state.two ~= 0 then p = p + (12 * state.two) end
- if state.black ~= 0 then p = p + (2 * state.black) end
- if state.onetosix ~= 0 then p = p + (3 * state.onetosix) end
- elseif winningNumber == 3 then
- if state.three ~= 0 then p = p + (12 * state.three) end
- if state.red ~= 0 then p = p + (2 * state.red) end
- if state.onetosix ~= 0 then p = p + (3 * state.onetosix) end
- elseif winningNumber == 4 then
- if state.four ~= 0 then p = p + (12 * state.four) end
- if state.black ~= 0 then p = p + (2 * state.black) end
- if state.onetosix ~= 0 then p = p + (3 * state.onetosix) end
- if state.fourtonine ~= 0 then p = p + (3 * state.fourtonine) end
- elseif winningNumber == 5 then
- if state.five ~= 0 then p = p + (12 * state.five) end
- if state.red ~= 0 then p = p + (2 * state.red) end
- if state.onetosix ~= 0 then p = p + (3 * state.onetosix) end
- if state.fourtonine ~= 0 then p = p + (3 * state.fourtonine) end
- elseif winningNumber == 6 then
- if state.six ~= 0 then p = p + (12 * state.six) end
- if state.black ~= 0 then p = p + (2 * state.black) end
- if state.onetosix ~= 0 then p = p + (3 * state.onetosix) end
- if state.fourtonine ~= 0 then p = p + (3 * state.fourtonine) end
- elseif winningNumber == 7 then
- if state.seven ~= 0 then p = p + (12 * state.seven) end
- if state.red ~= 0 then p = p + (2 * state.red) end
- if state.fourtonine ~= 0 then p = p + (3 * state.fourtonine) end
- if state.seventotwelve ~= 0 then p = p + (3 * state.seventotwelve) end
- elseif winningNumber == 8 then
- if state.eight ~= 0 then p = p + (12 * state.eight) end
- if state.black ~= 0 then p = p + (2 * state.black) end
- if state.fourtonine ~= 0 then p = p + (3 * state.fourtonine) end
- if state.seventotwelve ~= 0 then p = p + (3 * state.seventotwelve) end
- elseif winningNumber == 9 then
- if state.nine ~= 0 then p = p + (12 * state.nine) end
- if state.red ~= 0 then p = p + (2 * state.red) end
- if state.fourtonine ~= 0 then p = p + (3 * state.fourtonine) end
- if state.seventotwelve ~= 0 then p = p + (3 * state.seventotwelve) end
- elseif winningNumber == 10 then
- if state.ten ~= 0 then p = p + (12 * state.ten) end
- if state.black ~= 0 then p = p + (2 * state.black) end
- if state.seventotwelve ~= 0 then p = p + (3 * state.seventotwelve) end
- elseif winningNumber == 11 then
- if state.eleven ~= 0 then p = p + (12 * state.eleven) end
- if state.red ~= 0 then p = p + (2 * state.red) end
- if state.seventotwelve ~= 0 then p = p + (3 * state.seventotwelve) end
- elseif winningNumber == 12 then
- if state.twelve ~= 0 then p = p + (12 * state.twelve) end
- if state.black ~= 0 then p = p + (2 * state.black) end
- if state.seventotwelve ~= 0 then p = p + (3 * state.seventotwelve) end
- end
- balance = balance + p
- end
- function checkRedstoneSignalOn()
- while not redstone.getInput("back") do sleep(0.1) end
- end
- function checkRedstoneSignalOff()
- while redstone.getInput("back") do sleep(0.1) end
- end
- function main()
- init()
- while true do
- if loggedIn then
- renderBoard()
- if not redstone.getInput("back") or winningNumber ~= nil then
- if winningNumber ~= nil then
- old.write(winningNumber)
- calculateWinnings()
- winningNumber = nil
- state = {
- red = 0,
- black = 0,
- onetosix = 0,
- fourtonine = 0,
- seventotwelve = 0,
- one = 0,
- two = 0,
- three = 0,
- four = 0,
- five = 0,
- six = 0,
- seven = 0,
- eight = 0,
- nine = 0,
- ten = 0,
- eleven = 0,
- twelve = 0,
- zero = 0
- }
- checkRedstoneSignalOff()
- renderBoard()
- end
- parallel.waitForAny(clickHandler, checkRedstoneSignalOn)
- else
- local i,m,p = rednet.receive()
- winningNumber = tonumber(m)
- end
- else
- term.setBackgroundColor(colors.green)
- term.clear()
- if disk.isPresent("front") then
- local n = fs.open("/disk/n.dat", "r")
- local b = fs.open("/disk/b.dat", "r")
- if n and b then
- name = n.readLine()
- balance = math.floor(tonumber(b.readLine()))
- else
- print("ERROR")
- end
- n.close()
- b.close()
- loggedIn = true
- sleep(2)
- end
- end
- sleep(0.1)
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment