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("VALGRAVEGLIA S.R.L. - MATERIALI ALL'INGROSSO") |
109 | + | titolo("HIGHLAND LUMBER - VENDITA LEGNAMI") |
110 | -- startx, starty, endx, endy | |
111 | drawFilledBox(3, 5, 15, 7, colors.lightGray) | |
112 | term.setCursorPos(4, 6) | |
113 | colore(colors.black) | |
114 | sfondo(colors.lightGray) | |
115 | term.write("Argilla") | |
116 | ||
117 | while true do | |
118 | drawFilledBox(18, 5, 50, 17, colors.yellow) | |
119 | term.setCursorPos(19, 6) | |
120 | colore(colors.black) | |
121 | sfondo(colors.yellow) | |
122 | term.write("ISTRUZIONI - LEGGERE:") | |
123 | term.setCursorPos(19, 8) | |
124 | term.write("1. Posizionare il vagone sotto") | |
125 | term.setCursorPos(19, 9) | |
126 | term.write(" l'erogatore appropriato") | |
127 | term.setCursorPos(19, 10) | |
128 | term.write("2. Controllare che la spia") | |
129 | term.setCursorPos(19, 11) | |
130 | term.write(" «presenza vagone» sia accesa") | |
131 | term.setCursorPos(19, 12) | |
132 | term.write("3. Selezionare su questo PC") | |
133 | term.setCursorPos(19, 13) | |
134 | term.write(" il prodotto desiderato") | |
135 | term.setCursorPos(19, 14) | |
136 | term.write("4. Attendere l'erogazione") | |
137 | term.setCursorPos(19, 15) | |
138 | term.write("5. Non appena l'operazione sarà") | |
139 | term.setCursorPos(19, 16) | |
140 | term.write(" terminata liberare l'area") | |
141 | ||
142 | local event, par1, x, y = os.pullEvent("mouse_click") | |
143 | if event == "mouse_click" and x >= 3 and x <= 15 and y >= 5 and y <= 7 then | |
144 | cavo1 = colors.magenta | |
145 | cavo2 = colors.lime | |
146 | cavo3 = colors.lightGray | |
147 | - | prezzo = 20 |
147 | + | prezzo = 25 |
148 | - | materiale = "Argilla" |
148 | + | materiale = "Legname di quercia" |
149 | break | |
150 | end | |
151 | sleep(1) | |
152 | end | |
153 | clear() | |
154 | ||
155 | if colors.test(redstone.getBundledInput("back"), cavo3) == true then | |
156 | materialeNonDisponibile() | |
157 | end | |
158 | ||
159 | while true do | |
160 | titolo("Vendita di un vagone di " .. materiale) | |
161 | ||
162 | term.setCursorPos(3, 5) | |
163 | print("Si sta per acquistare un vagone di " .. materiale) | |
164 | print("\n Il prezzo è di " .. prezzo .. " IC") | |
165 | colore(colors.white) | |
166 | print("\n\n Inserire la carta per procedere\n con l'acquisto") | |
167 | ||
168 | drawFilledBox(15, 14, 36, 16, colors.red) | |
169 | term.setCursorPos(22, 15) | |
170 | colore(colors.white) | |
171 | term.write("Annulla") | |
172 | ||
173 | m = peripheral.wrap("bottom") -- magcard | |
174 | m.setInsertCardLight(true) | |
175 | ||
176 | event, par1, x, y = os.pullEvent() | |
177 | if event == "mouse_click" and x >= 15 and x <= 36 and y >= 14 and y <= 16 then | |
178 | m.setInsertCardLight(false) | |
179 | os.reboot() | |
180 | elseif event == "mag_swipe" then | |
181 | m.setInsertCardLight(false) | |
182 | break | |
183 | end | |
184 | end | |
185 | ||
186 | if par1 == nil then cartaVuota() end | |
187 | ||
188 | tab = textutils.unserialize(par1) | |
189 | ||
190 | if type(tab) ~= "table" then cartaNonValida() end | |
191 | ||
192 | if tab.t ~= "cc" then cartaNonValida() end | |
193 | ||
194 | if tab.e ~= "BN" then cartaNonValida() end | |
195 | ||
196 | credito = tonumber(tab.v) | |
197 | ||
198 | if prezzo > credito then | |
199 | creditoInsufficiente() | |
200 | end | |
201 | ||
202 | clear() | |
203 | titolo("Conferma pagamento") | |
204 | ||
205 | print("\n\nInserire nuovamente la carta per confermare il pagamento") | |
206 | ||
207 | tabr = {} | |
208 | ||
209 | tabr.t = tab.t | |
210 | tabr.e = tab.e | |
211 | tabr.p = tab.p | |
212 | tabr.v = tostring(credito - prezzo) | |
213 | ||
214 | ncr = textutils.serialize(tabr) | |
215 | m.setInsertCardLight(true) | |
216 | m.beginWrite(ncr,"BN Credit") | |
217 | os.pullEvent("mag_write_done") | |
218 | m.setInsertCardLight(false) | |
219 | ||
220 | clear() | |
221 | titolo("Erogazione in corso") | |
222 | ||
223 | print("\n\nErogazione " .. materiale .. " in corso...") | |
224 | ||
225 | redstone.setBundledOutput("back", cavo1) | |
226 | sleep(1) | |
227 | redstone.setBundledOutput("back", 0) | |
228 | ||
229 | erogazione = false | |
230 | ||
231 | while erogazione == false do | |
232 | erogazione = colors.test(redstone.getBundledInput("back"), cavo2) | |
233 | sleep(1) | |
234 | end | |
235 | os.reboot() |