-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathepanel.lua
More file actions
128 lines (112 loc) · 4.01 KB
/
epanel.lua
File metadata and controls
128 lines (112 loc) · 4.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
-- Zmienna dla pięter specjalnych
local specialFloors = {10, 11, 12} -- Przykładowe specjalne piętra
-- Funkcja rysująca przycisk
function drawButton(x, y, label)
term.setBackgroundColor(colors.gray)
term.setTextColor(colors.white)
term.setCursorPos(x, y)
term.write("[" .. label .. "]")
end
-- Funkcja rysująca panel
function drawPanel(input, message)
-- Czyszczenie ekranu
term.clear()
-- Wyświetlacz
term.setBackgroundColor(colors.gray)
term.setTextColor(colors.white)
term.setCursorPos(2, 2)
term.clearLine()
term.setCursorPos(2, 2)
term.write("Floor: " .. input)
if message then
term.setCursorPos(2, 4)
term.write(message)
end
-- Przyciski
local buttons = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 9},
{"*", 0, "-"}
}
for row = 1, #buttons do
for col = 1, #buttons[row] do
drawButton(2 + (col - 1) * 4, 5 + row * 2, tostring(buttons[row][col]))
end
end
end
-- Funkcja do walidacji numeru piętra
function isValidFloor(floor)
if floor == "" or floor == "-" or floor:find("%-%-") or floor:find("%-$") or floor:find("^%-.*%-") then
return false
end
local numFloor = tonumber(floor)
return numFloor ~= nil
end
-- Funkcja główna
function main()
local input = "" -- Zmienna dla numeru piętra
local message = nil
local lastInteraction = os.clock()
while true do
drawPanel(input, message)
-- Oczekiwanie na zdarzenie
local event, side, x, y = os.pullEvent("monitor_touch")
-- Aktualizacja czasu ostatniej interakcji
lastInteraction = os.clock()
-- Obsługa przycisków
if x >= 2 and x <= 4 then
if y == 5 then input = input .. "1"
elseif y == 7 then input = input .. "4"
elseif y == 9 then input = input .. "7"
elseif y == 11 then input = input .. "*" end
elseif x >= 6 and x <= 8 then
if y == 5 then input = input .. "2"
elseif y == 7 then input = input .. "5"
elseif y == 9 then input = input .. "8"
elseif y == 11 then input = input .. "0" end
elseif x >= 10 and x <= 12 then
if y == 5 then input = input .. "3"
elseif y == 7 then input = input .. "6"
elseif y == 9 then input = input .. "9" end
elseif x >= 14 and x <= 16 then
if y == 11 and input == "" then
input = "-"
end
end
-- Sprawdzenie poprawności numeru piętra
if not isValidFloor(input) then
input = ""
message = "Invalid floor"
end
-- Sprawdzenie, czy minęły 3 sekundy od ostatniej interakcji
if os.clock() - lastInteraction > 3 then
if isValidFloor(input) then
local numFloor = tonumber(input)
if numFloor == nil then
message = "??"
elseif specialFloors[numFloor] then
message = "(( ))"
-- Kolejne 3 sekundy na włożenie karty
local startWait = os.clock()
while os.clock() - startWait < 3 do
local event, side, x, y = os.pullEvent("monitor_touch")
lastInteraction = os.clock() -- Aktualizacja ostatniej interakcji
end
if os.clock() - startWait >= 3 then
message = "??"
end
else
-- Przykładowe działanie po wprowadzeniu numeru piętra
message = "Calling elevator to floor " .. input
end
else
-- Losowanie litery od A do F
local letter = string.char(math.random(65, 70))
message = "Directing to elevator " .. letter
end
input = "" -- Resetowanie wprowadzonego numeru piętra
end
end
end
main()