SHOW:
|
|
- or go back to the newest paste.
| 1 | local maxw, maxh = term.getSize() | |
| 2 | ||
| 3 | function cartaNonValida() | |
| 4 | clearRed() | |
| 5 | print("Carta non valida o corrotta.")
| |
| 6 | print("")
| |
| 7 | print("Premere un tasto per uscire")
| |
| 8 | os.pullEvent("key")
| |
| 9 | os.reboot() | |
| 10 | end | |
| 11 | ||
| 12 | function cartaVuota() | |
| 13 | clearRed() | |
| 14 | print("Carta smagnetizzata o vuota.")
| |
| 15 | print("")
| |
| 16 | print("Premere un tasto per uscire")
| |
| 17 | os.pullEvent("key")
| |
| 18 | os.reboot() | |
| 19 | end | |
| 20 | ||
| 21 | function creditoInsufficiente() | |
| 22 | clearRed() | |
| 23 | print("Credito insufficiente.")
| |
| 24 | print("")
| |
| 25 | print("Premere un tasto per uscire")
| |
| 26 | os.pullEvent("key")
| |
| 27 | os.reboot() | |
| 28 | end | |
| 29 | ||
| 30 | function materialeNonDisponibile() | |
| 31 | clearRed() | |
| 32 | print("Materiale esaurito.")
| |
| 33 | print("")
| |
| 34 | print("Premere un tasto per uscire")
| |
| 35 | os.pullEvent("key")
| |
| 36 | os.reboot() | |
| 37 | end | |
| 38 | ||
| 39 | -- IMPLEMENTAZIONE DEL DRAWFILLEDBOX | |
| 40 | local function drawPixelInternal(xPos, yPos) | |
| 41 | term.setCursorPos(xPos, yPos) | |
| 42 | term.write(" ")
| |
| 43 | end | |
| 44 | ||
| 45 | local tColourLookup = {}
| |
| 46 | for n = 1, 16 do | |
| 47 | tColourLookup[string.byte("0123456789abcdef", n, n)] = 2 ^ (n - 1)
| |
| 48 | end | |
| 49 | ||
| 50 | function drawFilledBox(startX, startY, endX, endY, nColour) | |
| 51 | if type(startX) ~= "number" or type(startX) ~= "number" or type(endX) ~= | |
| 52 | "number" or type(endY) ~= "number" or | |
| 53 | (nColour ~= nil and type(nColour) ~= "number") then | |
| 54 | error("Expected startX, startY, endX, endY, colour", 2)
| |
| 55 | end | |
| 56 | ||
| 57 | startX = math.floor(startX) | |
| 58 | startY = math.floor(startY) | |
| 59 | endX = math.floor(endX) | |
| 60 | endY = math.floor(endY) | |
| 61 | ||
| 62 | if nColour then term.setBackgroundColor(nColour) end | |
| 63 | if startX == endX and startY == endY then | |
| 64 | drawPixelInternal(startX, startY) | |
| 65 | return | |
| 66 | end | |
| 67 | ||
| 68 | local minX = math.min(startX, endX) | |
| 69 | if minX == startX then | |
| 70 | minY = startY | |
| 71 | maxX = endX | |
| 72 | maxY = endY | |
| 73 | else | |
| 74 | minY = endY | |
| 75 | maxX = startX | |
| 76 | maxY = startY | |
| 77 | end | |
| 78 | ||
| 79 | for x = minX, maxX do for y = minY, maxY do drawPixelInternal(x, y) end end | |
| 80 | end | |
| 81 | ||
| 82 | function clear() | |
| 83 | sfondo(colors.lightBlue) | |
| 84 | term.clear() | |
| 85 | term.setCursorPos(1, 1) | |
| 86 | end | |
| 87 | ||
| 88 | function clearRed() | |
| 89 | sfondo(colors.red) | |
| 90 | term.clear() | |
| 91 | term.setCursorPos(1, 1) | |
| 92 | end | |
| 93 | ||
| 94 | ||
| 95 | function colore(sfumatura) term.setTextColour(sfumatura) end | |
| 96 | ||
| 97 | function sfondo(sfumaturaSfondo) term.setBackgroundColour(sfumaturaSfondo) end | |
| 98 | ||
| 99 | function titolo(testo) | |
| 100 | drawFilledBox(1, 1, maxw, 1, colors.yellow) | |
| 101 | term.setCursorPos((maxw - #testo) / 2, 1) | |
| 102 | colore(colors.black) | |
| 103 | term.write(testo) | |
| 104 | sfondo(colors.lightBlue) | |
| 105 | end | |
| 106 | ||
| 107 | clear() | |
| 108 | ||
| 109 | - | titolo("KARABASHMED MATERIALI ALL'INGROSSO")
|
| 109 | + | titolo("HIGHLAND QUARRIES MATERIALI ALL'INGROSSO")
|
| 110 | -- startx, starty, endx, endy | |
| 111 | - | drawFilledBox(3, 5, 15, 7, colors.black) |
| 111 | + | drawFilledBox(3, 5, 15, 7, colors.yellow) |
| 112 | - | drawFilledBox(3, 10, 15, 12, colors.lightGray) |
| 112 | + | drawFilledBox(3, 10, 15, 12, colors.cyan) |
| 113 | - | drawFilledBox(3, 15, 15, 17, colors.orange) |
| 113 | + | drawFilledBox(3, 15, 15, 17, colors.red) |
| 114 | term.setCursorPos(4, 6) | |
| 115 | colore(colors.black) | |
| 116 | - | sfondo(colors.black) |
| 116 | + | sfondo(colors.yellow) |
| 117 | - | term.write("Carbone")
|
| 117 | + | term.write("Tufo")
|
| 118 | ||
| 119 | term.setCursorPos(4, 11) | |
| 120 | colore(colors.black) | |
| 121 | - | sfondo(colors.lightGray) |
| 121 | + | sfondo(colors.cyan) |
| 122 | - | term.write("Ferro")
|
| 122 | + | term.write("Peridotite")
|
| 123 | ||
| 124 | term.setCursorPos(4, 16) | |
| 125 | colore(colors.white) | |
| 126 | - | sfondo(colors.orange) |
| 126 | + | sfondo(colors.red) |
| 127 | - | term.write("Rame")
|
| 127 | + | term.write("Diaspro")
|
| 128 | ||
| 129 | while true do | |
| 130 | drawFilledBox(18, 5, 50, 17, colors.yellow) | |
| 131 | term.setCursorPos(19, 6) | |
| 132 | colore(colors.black) | |
| 133 | sfondo(colors.yellow) | |
| 134 | term.write("ISTRUZIONI - LEGGERE:")
| |
| 135 | term.setCursorPos(19, 8) | |
| 136 | term.write("1. Posizionare il vagone sotto")
| |
| 137 | term.setCursorPos(19, 9) | |
| 138 | term.write(" l'erogatore appropriato")
| |
| 139 | term.setCursorPos(19, 10) | |
| 140 | term.write("2. Controllare che la spia")
| |
| 141 | term.setCursorPos(19, 11) | |
| 142 | term.write(" «presenza vagone» sia accesa")
| |
| 143 | term.setCursorPos(19, 12) | |
| 144 | term.write("3. Selezionare su questo PC")
| |
| 145 | term.setCursorPos(19, 13) | |
| 146 | term.write(" il prodotto desiderato")
| |
| 147 | term.setCursorPos(19, 14) | |
| 148 | term.write("4. Attendere l'erogazione")
| |
| 149 | term.setCursorPos(19, 15) | |
| 150 | term.write("5. Non appena l'operazione sarà")
| |
| 151 | term.setCursorPos(19, 16) | |
| 152 | term.write(" terminata liberare l'area")
| |
| 153 | ||
| 154 | local event, par1, x, y = os.pullEvent("mouse_click")
| |
| 155 | if event == "mouse_click" and x >= 3 and x <= 15 and y >= 5 and y <= 7 then | |
| 156 | cavo1 = colors.white | |
| 157 | cavo2 = colors.lightBlue | |
| 158 | cavo3 = colors.pink | |
| 159 | - | prezzo = 25 |
| 159 | + | prezzo = 106 |
| 160 | - | materiale = "Carbone" |
| 160 | + | materiale = "Tufo" |
| 161 | break | |
| 162 | elseif event == "mouse_click" and x >= 3 and x <= 15 and y >= 10 and y <= 12 then | |
| 163 | cavo1 = colors.orange | |
| 164 | cavo2 = colors.yellow | |
| 165 | cavo3 = colors.gray | |
| 166 | - | prezzo = 512 |
| 166 | + | prezzo = 150 |
| 167 | - | materiale = "Ferro" |
| 167 | + | materiale = "Peridotite" |
| 168 | break | |
| 169 | elseif event == "mouse_click" and x >= 3 and x <= 15 and y >= 15 and y <= 17 then | |
| 170 | cavo1 = colors.magenta | |
| 171 | cavo2 = colors.lime | |
| 172 | cavo3 = colors.lightGray | |
| 173 | - | prezzo = 490 |
| 173 | + | prezzo = 70 |
| 174 | - | materiale = "Rame" |
| 174 | + | materiale = "Diaspro" |
| 175 | break | |
| 176 | end | |
| 177 | sleep(1) | |
| 178 | end | |
| 179 | clear() | |
| 180 | ||
| 181 | if colors.test(redstone.getBundledInput("back"), cavo3) == true then
| |
| 182 | materialeNonDisponibile() | |
| 183 | end | |
| 184 | ||
| 185 | while true do | |
| 186 | titolo("Vendita di un vagone di " .. materiale)
| |
| 187 | ||
| 188 | term.setCursorPos(3, 5) | |
| 189 | print("Si sta per acquistare un vagone di " .. materiale)
| |
| 190 | print("\n Il prezzo è di " .. prezzo .. " IC")
| |
| 191 | colore(colors.white) | |
| 192 | print("\n\n Inserire la carta per procedere\n con l'acquisto")
| |
| 193 | ||
| 194 | drawFilledBox(15, 14, 36, 16, colors.red) | |
| 195 | term.setCursorPos(22, 15) | |
| 196 | colore(colors.white) | |
| 197 | term.write("Annulla")
| |
| 198 | ||
| 199 | m = peripheral.wrap("bottom") -- magcard
| |
| 200 | m.setInsertCardLight(true) | |
| 201 | ||
| 202 | event, par1, x, y = os.pullEvent() | |
| 203 | if event == "mouse_click" and x >= 15 and x <= 36 and y >= 14 and y <= 16 then | |
| 204 | m.setInsertCardLight(false) | |
| 205 | os.reboot() | |
| 206 | elseif event == "mag_swipe" then | |
| 207 | m.setInsertCardLight(false) | |
| 208 | break | |
| 209 | end | |
| 210 | end | |
| 211 | ||
| 212 | if par1 == nil then cartaVuota() end | |
| 213 | ||
| 214 | tab = textutils.unserialize(par1) | |
| 215 | ||
| 216 | if type(tab) ~= "table" then cartaNonValida() end | |
| 217 | ||
| 218 | if tab.t ~= "cc" then cartaNonValida() end | |
| 219 | ||
| 220 | if tab.e ~= "BN" then cartaNonValida() end | |
| 221 | ||
| 222 | credito = tonumber(tab.v) | |
| 223 | ||
| 224 | if prezzo > credito then | |
| 225 | creditoInsufficiente() | |
| 226 | end | |
| 227 | ||
| 228 | clear() | |
| 229 | titolo("Conferma pagamento")
| |
| 230 | ||
| 231 | print("\n\nInserire nuovamente la carta per confermare il pagamento")
| |
| 232 | ||
| 233 | tabr = {}
| |
| 234 | ||
| 235 | tabr.t = tab.t | |
| 236 | tabr.e = tab.e | |
| 237 | tabr.p = tab.p | |
| 238 | tabr.v = tostring(credito - prezzo) | |
| 239 | ||
| 240 | ncr = textutils.serialize(tabr) | |
| 241 | m.setInsertCardLight(true) | |
| 242 | m.beginWrite(ncr,"BN Credit") | |
| 243 | os.pullEvent("mag_write_done")
| |
| 244 | m.setInsertCardLight(false) | |
| 245 | ||
| 246 | clear() | |
| 247 | titolo("Erogazione in corso")
| |
| 248 | ||
| 249 | print("\n\nErogazione " .. materiale .. " in corso...")
| |
| 250 | ||
| 251 | redstone.setBundledOutput("back", cavo1)
| |
| 252 | sleep(1) | |
| 253 | redstone.setBundledOutput("back", 0)
| |
| 254 | ||
| 255 | erogazione = false | |
| 256 | ||
| 257 | while erogazione == false do | |
| 258 | erogazione = colors.test(redstone.getBundledInput("back"), cavo2)
| |
| 259 | sleep(1) | |
| 260 | end | |
| 261 | os.reboot() |