Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local maxw, maxh = term.getSize()
- function cartaNonValida()
- clearRed()
- print("Carta non valida o corrotta.")
- print("")
- print("Premere un tasto per uscire")
- os.pullEvent("key")
- os.reboot()
- end
- function cartaVuota()
- clearRed()
- print("Carta smagnetizzata o vuota.")
- print("")
- print("Premere un tasto per uscire")
- os.pullEvent("key")
- os.reboot()
- end
- function creditoInsufficiente()
- clearRed()
- print("Credito insufficiente.")
- print("")
- print("Premere un tasto per uscire")
- os.pullEvent("key")
- os.reboot()
- end
- function materialeNonDisponibile()
- clearRed()
- print("Materiale esaurito.")
- print("")
- print("Premere un tasto per uscire")
- os.pullEvent("key")
- os.reboot()
- end
- -- 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.lightBlue)
- term.clear()
- term.setCursorPos(1, 1)
- end
- function clearRed()
- sfondo(colors.red)
- term.clear()
- term.setCursorPos(1, 1)
- 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.lightBlue)
- end
- clear()
- titolo("HIGHLAND LUMBER - VENDITA LEGNAMI")
- -- startx, starty, endx, endy
- drawFilledBox(3, 5, 15, 7, colors.lightGray)
- term.setCursorPos(4, 6)
- colore(colors.black)
- sfondo(colors.lightGray)
- term.write("Argilla")
- while true do
- drawFilledBox(18, 5, 50, 17, colors.yellow)
- term.setCursorPos(19, 6)
- colore(colors.black)
- sfondo(colors.yellow)
- term.write("ISTRUZIONI - LEGGERE:")
- term.setCursorPos(19, 8)
- term.write("1. Posizionare il vagone sotto")
- term.setCursorPos(19, 9)
- term.write(" l'erogatore appropriato")
- term.setCursorPos(19, 10)
- term.write("2. Controllare che la spia")
- term.setCursorPos(19, 11)
- term.write(" «presenza vagone» sia accesa")
- term.setCursorPos(19, 12)
- term.write("3. Selezionare su questo PC")
- term.setCursorPos(19, 13)
- term.write(" il prodotto desiderato")
- term.setCursorPos(19, 14)
- term.write("4. Attendere l'erogazione")
- term.setCursorPos(19, 15)
- term.write("5. Non appena l'operazione sarà")
- term.setCursorPos(19, 16)
- term.write(" terminata liberare l'area")
- local event, par1, x, y = os.pullEvent("mouse_click")
- if event == "mouse_click" and x >= 3 and x <= 15 and y >= 5 and y <= 7 then
- cavo1 = colors.magenta
- cavo2 = colors.lime
- cavo3 = colors.lightGray
- prezzo = 25
- materiale = "Legname di quercia"
- break
- end
- sleep(1)
- end
- clear()
- if colors.test(redstone.getBundledInput("back"), cavo3) == true then
- materialeNonDisponibile()
- end
- while true do
- titolo("Vendita di un vagone di " .. materiale)
- term.setCursorPos(3, 5)
- print("Si sta per acquistare un vagone di " .. materiale)
- print("\n Il prezzo è di " .. prezzo .. " IC")
- colore(colors.white)
- print("\n\n Inserire la carta per procedere\n con l'acquisto")
- drawFilledBox(15, 14, 36, 16, colors.red)
- term.setCursorPos(22, 15)
- colore(colors.white)
- term.write("Annulla")
- m = peripheral.wrap("bottom") -- magcard
- m.setInsertCardLight(true)
- event, par1, x, y = os.pullEvent()
- if event == "mouse_click" and x >= 15 and x <= 36 and y >= 14 and y <= 16 then
- m.setInsertCardLight(false)
- os.reboot()
- elseif event == "mag_swipe" then
- m.setInsertCardLight(false)
- break
- end
- end
- if par1 == nil then cartaVuota() end
- tab = textutils.unserialize(par1)
- if type(tab) ~= "table" then cartaNonValida() end
- if tab.t ~= "cc" then cartaNonValida() end
- if tab.e ~= "BN" then cartaNonValida() end
- credito = tonumber(tab.v)
- if prezzo > credito then
- creditoInsufficiente()
- end
- clear()
- titolo("Conferma pagamento")
- print("\n\nInserire nuovamente la carta per confermare il pagamento")
- tabr = {}
- tabr.t = tab.t
- tabr.e = tab.e
- tabr.p = tab.p
- tabr.v = tostring(credito - prezzo)
- ncr = textutils.serialize(tabr)
- m.setInsertCardLight(true)
- m.beginWrite(ncr,"BN Credit")
- os.pullEvent("mag_write_done")
- m.setInsertCardLight(false)
- clear()
- titolo("Erogazione in corso")
- print("\n\nErogazione " .. materiale .. " in corso...")
- redstone.setBundledOutput("back", cavo1)
- sleep(1)
- redstone.setBundledOutput("back", 0)
- erogazione = false
- while erogazione == false do
- erogazione = colors.test(redstone.getBundledInput("back"), cavo2)
- sleep(1)
- end
- os.reboot()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement