Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Settings
- backgroundColor = 8192
- stepRate = 600
- maxWin = 10000
- bet = 100
- -- Globals
- step = 1
- cashOutPoint = 0
- inPlay = false
- crashed = false
- cashedOut = false
- buttonLabel = 'CRASH'
- -- Init
- rednet.open('bottom')
- database = rednet.lookup("C_ACC", 'database')
- sound = peripheral.wrap("right")
- database = rednet.lookup("C_ACC", 'database')
- monitor = peripheral.wrap("top")
- monitor.setTextScale(0.5)
- wX,wY = term.getSize()
- old = term.redirect(monitor)
- mX,mY = term.getSize()
- term.setBackgroundColor(backgroundColor)
- term.clear()
- term.setCursorPos(1,1)
- account = nil
- width, height = term.getSize()
- function GetAccount(pin)
- rednet.send(database, textutils.serialise({'account', pin}), 'C_ACC')
- sender,message,distance = rednet.receive('C_ACC')
- account = textutils.unserialise(message)
- if account ~= nil then
- return account
- else
- return nil
- end
- end
- function GetCrashPoint()
- rand = math.random(1000)-1
- crash = (1000-(rand/50))/(1000-rand)
- crash = math.floor(crash * 100) / 100
- if rand%20 == 0 then
- return 1
- end
- return crash
- end
- function Step()
- f = 1/stepRate
- step = step + f*(step^2+0.5)
- end
- -- Game rendering
- function RedrawMonitor(label, borderCol)
- borderCol = borderCol or '8'
- -- Cashout button
- for i=0, 5 do
- term.setCursorPos(1,mY-i)
- term.blit(string.rep(' ', mX),string.rep('f', mX),string.rep(borderCol, mX))
- end
- -- Button text
- term.setCursorPos((mX/2)-(#label/2),mY-2)
- term.blit(label,string.rep('f', #label),string.rep(borderCol, #label))
- term.setCursorPos(1,1)
- end
- function Payout()
- return bet*cashOutPoint
- end
- function CashoutCheck()
- while true do
- event, button, x, y = os.pullEvent("monitor_touch")
- if inPlay and crashed == false and cashedOut == false then
- if y >= mY - 4 then
- cashOutPoint = step
- cashedOut = true
- winnings = Payout()
- buttonLabel = 'YOU WIN: '..winnings..' CREDITS'
- rednet.send(database, textutils.serialise({'add', pin, winnings}), 'C_ACC')
- end
- end
- end
- end
- -- Game logic
- function PlayMonitor()
- while true do
- -- Reset
- step = 1
- inPlay = false
- crashed = false
- cashedOut = false
- -- Login and play loop
- while true do
- while account == nil do
- RedrawMonitor('---Login on terminal to play---', 'e')
- sleep(0.5)
- RedrawMonitor('---CRASH---', 'e')
- sleep(0.5)
- end
- RedrawMonitor('Right click to play. '..bet..' credits', '5')
- event, button, x, y = os.pullEvent("monitor_touch")
- if account ~= nil then
- rednet.send(database, textutils.serialise({'add', pin, -bet}), 'C_ACC')
- sender,message,distance = rednet.receive('C_ACC')
- -- Player has enough credit to play
- if textutils.unserialise(message) == true then
- break
- end
- RedrawMonitor('Not enough credits to play', '8')
- sleep(1.5)
- end
- end
- -- Start game
- buttonLabel = 'CASH OUT'
- inPlay = true
- crashPoint = GetCrashPoint()
- while crashed == false do
- piss = piss+1
- buttonBG = '5'
- RedrawMonitor(buttonLabel, '5')
- Step()
- if step >= crashPoint then
- inPlay = false
- crashed = true
- if cashedOut == false then
- buttonLabel = 'CRASHED'
- end
- end
- sleep(0.1)
- end
- RedrawMonitor(buttonLabel)
- sleep(1.5)
- end
- end
- function PlayScreen()
- login = window.create(old,1,1, wX,wY)
- while true do
- login.setBackgroundColor(2048)
- login.clear()
- login.setCursorPos(1,1)
- login.write("Enter pin: ")
- pin = ''
- input = ''
- account = nil
- for i=1, 4 do
- event, input = os.pullEvent("char")
- pin = pin..input
- login.write('*')
- end
- pin = pin
- login.clear()
- login.setCursorPos(1,1)
- login.write('Logging in...')
- account = GetAccount(pin)
- if account ~= nil then
- login.clear()
- login.setCursorPos(1,1)
- login.write('Welcome '..account[1])
- login.setCursorPos(1,2)
- login.write("Exit this screen to play!")
- login.setCursorPos(1,3)
- login.write("Press any key to log out")
- os.pullEvent("char")
- else
- login.clear()
- login.setCursorPos(1,1)
- login.write('Invalid pin!')
- sleep(1)
- end
- end
- end
- parallel.waitForAll(PlayMonitor, PlayScreen, CashoutCheck)
Add Comment
Please, Sign In to add comment