Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local maxw, maxh = term.getSize()
- -- IMPLEMENTAZIONE DEL DRAWFILLEDBOX
- local function drawPixelInternal(xPos, yPos)
- term.setCursorPos(xPos, yPos)
- term.write(" ")
- end
- local tColourLookup = {}
- for n = 1, 16 do
- tColourLookup[string.byte("0123456789abcdef", n, n)] = 2 ^ (n - 1)
- end
- function drawFilledBox(startX, startY, endX, endY, nColour)
- if type(startX) ~= "number" or type(startX) ~= "number" or type(endX) ~=
- "number" or type(endY) ~= "number" or
- (nColour ~= nil and type(nColour) ~= "number") then
- error("Expected startX, startY, endX, endY, colour", 2)
- end
- startX = math.floor(startX)
- startY = math.floor(startY)
- endX = math.floor(endX)
- endY = math.floor(endY)
- if nColour then term.setBackgroundColor(nColour) end
- if startX == endX and startY == endY then
- drawPixelInternal(startX, startY)
- return
- end
- local minX = math.min(startX, endX)
- if minX == startX then
- minY = startY
- maxX = endX
- maxY = endY
- else
- minY = endY
- maxX = startX
- maxY = startY
- end
- for x = minX, maxX do for y = minY, maxY do drawPixelInternal(x, y) end end
- end
- function clear()
- sfondo(colors.blue)
- term.clear()
- term.setCursorPos(1, 1)
- end
- function fineColore() term.setTextColour(colours.white) end
- function fineSfondo() term.setBackgroundColour(colours.black) end
- function colore(sfumatura) term.setTextColour(sfumatura) end
- function sfondo(sfumaturaSfondo) term.setBackgroundColour(sfumaturaSfondo) end
- function titolo(testo)
- drawFilledBox(1, 1, maxw, 1, colors.yellow)
- term.setCursorPos((maxw - #testo) / 2, 1)
- colore(colors.black)
- term.write(testo)
- sfondo(colors.blue)
- end
- function errore(errore)
- sfondo(colors.red)
- colore(colors.white)
- term.clear()
- term.setCursorPos(1, 1)
- titolo("Errore irreversibile")
- term.setCursorPos(1, 3)
- sfondo(colors.red)
- colore(colors.white)
- print(errore)
- print("\n\n\nAttendere qualche secondo...")
- os.sleep(5)
- os.reboot()
- end
- function compra_biglietto()
- clear()
- titolo("Lotteria di New Radeon")
- drawFilledBox(3, 3, maxw - 3, 5, colors.lime);
- term.setCursorPos(6, 4)
- term.write("Montepremi attuale: " .. verifica_ini.montepremi .. " IC")
- term.setCursorPos(1, 10)
- term.setBackgroundColor(colors.blue)
- term.setTextColor(colors.white)
- print(
- "Sfiora il sensore sottostante per comprare un biglietto ed aggiungere 20 IC al montepremi!\n\nCosto di un biglietto: 5 IC\nPagamento con Nebraska Pay.")
- __, b = os.pullEvent("player")
- sir_biglietto = textutils.unserialize(
- http.get(
- "http://172.16.20.220/luanet/servlets/lotterianr/?richiesta=esiste_giocatore&giocatore=" ..
- b).readAll())
- if sir_biglietto.stato == "KO" then errore(sir_biglietto.errore) end
- sfondo(colours.blue)
- term.clear()
- term.setCursorPos(1, 1)
- titolo("Paga con Nebraska Pay")
- sfondo(colours.blue)
- colore(colors.white)
- print(
- "\n\nInserire i propri dati. Premere Enter per confermare i dati inseriti. \nSe i dati sono corretti, il campo diventerà verde. Se sono errati, il programma chiederà di reinserirli nuovamente.")
- -- nomeutente
- term.setCursorPos(1, 9)
- term.write("Nome utente:")
- term.setCursorPos(15, 9)
- fineColore()
- utenteAccettato = false
- conteggioErrori = 0
- while utenteAccettato == false do
- utente = read()
- checkuser = http.get(
- "http://172.16.20.220/luanet/servlets/nebraskapay.php?auth=no&richiesta=verifica&utente=" ..
- utente).readAll()
- tabcheckuser = textutils.unserialize(checkuser)
- if tabcheckuser.stato == "OK" then
- term.setCursorPos(15, 9)
- colore(colours.lime)
- term.write(utente)
- fineColore()
- utenteAccettato = true
- else
- term.setCursorPos(15, 9)
- colore(colours.red)
- term.write("Utente errato! ")
- sleep(2)
- term.setCursorPos(15, 9)
- fineColore()
- term.write(" ")
- term.setCursorPos(15, 9)
- conteggioErrori = conteggioErrori + 1
- if conteggioErrori > 2 then
- term.setCursorPos(15, 9)
- colore(colours.red)
- errore("Troppi tentativi di immissione errati ")
- end
- end
- end
- colore(colours.white)
- term.setCursorPos(1, 11)
- term.write("Password:")
- term.setCursorPos(15, 11)
- conteggioErrori = 0
- passAccettata = false
- while passAccettata == false do
- fineColore()
- password = read("#")
- colore(colours.black)
- checkuser = http.get(
- "http://172.16.20.220/luanet/servlets/nebraskapay.php?auth=" ..
- password .. "&richiesta=addebito&valore=0&utente=" ..
- utente).readAll()
- risposta = textutils.unserialize(checkuser)
- if risposta.stato == "OK" then
- term.setCursorPos(15, 11)
- colore(colours.lime)
- term.write("############## ")
- fineColore()
- passAccettata = true
- else
- term.setCursorPos(15, 11)
- colore(colours.red)
- term.write("Password errata! ")
- conteggioErrori = conteggioErrori + 1
- sleep(2)
- term.setCursorPos(15, 11)
- term.write(" ")
- term.setCursorPos(15, 11)
- if conteggioErrori > 2 then
- term.setCursorPos(15, 11)
- colore(colours.red)
- errore("Troppi tentativi di immissione errati")
- end
- end
- end
- -- Mostra saldo
- term.clear()
- term.clear()
- term.setCursorPos(1, 1)
- titolo("Paga con Nebraska Pay")
- sfondo(colours.blue)
- colore(colors.white)
- print("\n\nSaldo disponibile: " .. risposta.saldo .. " IC")
- importo = 5
- if tonumber(risposta.saldo) >= tonumber(importo) then
- importoAccettato = true
- else
- errore("Disponibilità insufficiente!")
- end
- term.setCursorPos(1, 3)
- term.write("Invio di ")
- term.write(importo)
- term.write(" IC a favore di ")
- term.write("Comune di New Radeon")
- print("\n\nConfermare l'operazione?")
- colore(colors.yellow)
- print("\n\nInvia il denaro Annulla")
- while true do
- event, key, x, y = os.pullEvent()
- if event == "mouse_click" and x < 16 and y == 8 then
- inviaDenaro = http.get(
- "http://172.16.20.220/luanet/servlets/nebraskapay.php?auth=" ..
- password .. "&utente=" .. utente ..
- "&richiesta=trasferimento&valore=" .. importo ..
- "&beneficiario=ComuneNR").readAll()
- risultatoInvio = textutils.unserialize(inviaDenaro)
- if risultatoInvio.stato == "OK" then
- colore(colors.white)
- break
- else
- clear()
- errore("Errore durante il pagamento")
- end
- elseif event == "mouse_click" and x > 18 and y == 8 then
- errore("Pagamento annullato dall'utente.")
- end
- end
- sir_biglietto = textutils.unserialize(
- http.get(
- "http://172.16.20.220/luanet/servlets/lotterianr/?richiesta=nuovo_biglietto&giocatore=" ..
- b).readAll())
- if sir_biglietto.stato == "OK" then
- clear()
- titolo("Lotteria di New Radeon")
- term.setCursorPos(1, 3)
- colore(colors.white)
- print("Grazie per l'acquisto!\n\n")
- print("Questo è il numero del tuo biglietto: " .. sir_biglietto.numero)
- print(
- "\nNon temere di dimenticarlo, se vincerai riceverai un'email!")
- print("\nBuona fortuna!")
- os.sleep(5)
- os.reboot()
- else
- errore(sir_biglietto.errore)
- end
- end
- function prendi_premio()
- winner = textutils.unserialize(http.get(
- "http://172.16.20.220/luanet/servlets/lotterianr/?richiesta=verifica_vincita")
- .readAll())
- clear()
- titolo("Lotteria di New Radeon")
- drawFilledBox(3, 3, maxw - 3, 5, colors.lime);
- term.setCursorPos(6, 4)
- term.write("Vincitore: " .. winner.numero .. " - " .. winner.giocatore .. " - " .. verifica_ini.montepremi .. " IC")
- term.setCursorPos(1, 7)
- term.setBackgroundColor(colors.blue)
- term.setTextColor(colors.white)
- print(
- "Sfiora il sensore sottostante per ritirare la tua vincita!")
- __, b = os.pullEvent("player")
- if b == winner.giocatore then
- sfondo(colours.blue)
- term.clear()
- term.setCursorPos(1, 1)
- titolo("Ritira la vincita con Nebraska Pay")
- sfondo(colours.blue)
- colore(colors.white)
- print(
- "\n\nInserire l'utente nPay per ritirare la vincita. Premere Enter per confermare i dati inseriti. \nSe i dati sono corretti, il campo diventerà verde. Se sono errati, il programma chiederà di reinserirli nuovamente.")
- -- nomeutente
- term.setCursorPos(1, 9)
- term.write("Nome utente:")
- term.setCursorPos(15, 9)
- fineColore()
- utenteAccettato = false
- conteggioErrori = 0
- while utenteAccettato == false do
- utente = read()
- checkuser = http.get(
- "http://172.16.20.220/luanet/servlets/nebraskapay.php?auth=no&richiesta=verifica&utente=" ..
- utente).readAll()
- tabcheckuser = textutils.unserialize(checkuser)
- if tabcheckuser.stato == "OK" then
- term.setCursorPos(15, 9)
- colore(colours.lime)
- term.write(utente)
- fineColore()
- utenteAccettato = true
- else
- term.setCursorPos(15, 9)
- colore(colours.red)
- term.write("Utente errato! ")
- sleep(2)
- term.setCursorPos(15, 9)
- fineColore()
- term.write(" ")
- term.setCursorPos(15, 9)
- conteggioErrori = conteggioErrori + 1
- if conteggioErrori > 2 then
- term.setCursorPos(15, 9)
- colore(colours.red)
- errore("Troppi tentativi di immissione errati ")
- end
- end
- end
- sir_biglietto = textutils.unserialize(
- http.get(
- "http://172.16.20.220/luanet/servlets/lotterianr/?richiesta=paga_vincitore&npay=".. utente .."&giocatore=" .. winner.giocatore).readAll())
- if sir_biglietto.stato == "KO" then errore(sir_biglietto.errore) end
- sfondo(colours.blue)
- term.clear()
- term.setCursorPos(1, 1)
- titolo("Ritira la vincita con Nebraska Pay")
- sfondo(colours.blue)
- colore(colors.white)
- print("\n\n\nIl montepremi di ".. verifica_ini.montepremi .." IC è stato accreditato con successo sul conto '" .. utente .. "'.\n\nBuona giornata!")
- os.sleep(5)
- os.reboot()
- else
- errore("Non sei il vincitore - non fare il furbo.")
- os.sleep(5)
- os.reboot()
- end
- end
- verifica_ini = textutils.unserialize(http.get(
- "http://172.16.20.220/luanet/servlets/lotterianr/?richiesta=verifica_stato")
- .readAll())
- if verifica_ini.stato == "NA" then
- compra_biglietto()
- elseif verifica_ini.stato == "EA" then
- prendi_premio()
- else
- errore("Errore fatale del server di gioco")
- os.sleep(5)
- os.reboot()
- end
Add Comment
Please, Sign In to add comment