remove illegal caracters and allow restarting the program without reboot in case of connection issues
This commit is contained in:
parent
522893b2c5
commit
40ddc3196b
1 changed files with 26 additions and 16 deletions
|
@ -1,19 +1,29 @@
|
||||||
dofile("screen.lua")
|
dofile("screen.lua")
|
||||||
|
|
||||||
-- connecte l'écran sur les pins 18 et 19
|
dofile("mqtt_config.lua")
|
||||||
attachscreen(18, 19, 0x3C)
|
|
||||||
|
|
||||||
-- connecte la bande de led sur le pin 21
|
|
||||||
neo = neopixel.attach(neopixel.WS2812B, pio.GPIO21, 8)
|
|
||||||
|
|
||||||
cls()
|
cls()
|
||||||
console("Welcome to pendu!")
|
console("Welcome to pendu!")
|
||||||
console("by Lorem Impsum Corp.")
|
console("by Lorem Impsum Corp.")
|
||||||
|
|
||||||
dofile("mqtt_config.lua")
|
|
||||||
|
|
||||||
client = mqtt.client(client_name, "mqtt.leizour.fr", 8883, true)
|
client = mqtt.client(client_name, "mqtt.leizour.fr", 8883, true)
|
||||||
|
console("Connecting...")
|
||||||
client:connect("student", password)
|
client:connect("student", password)
|
||||||
|
console("Connected !")
|
||||||
|
|
||||||
|
try (
|
||||||
|
function ()
|
||||||
|
-- connecte l'écran sur les pins 18 et 19
|
||||||
|
attachscreen(18, 19, 0x3C)
|
||||||
|
end,
|
||||||
|
function () end,
|
||||||
|
function () end
|
||||||
|
)
|
||||||
|
|
||||||
|
if neo ~= nil then
|
||||||
|
-- connecte la bande de led sur le pin 21
|
||||||
|
neo = neopixel.attach(neopixel.WS2812B, pio.GPIO21, 8)
|
||||||
|
end
|
||||||
|
|
||||||
playing = false
|
playing = false
|
||||||
won = false
|
won = false
|
||||||
|
@ -30,14 +40,14 @@ function draw_ui()
|
||||||
cls()
|
cls()
|
||||||
if playing then
|
if playing then
|
||||||
draw_ascii(lives)
|
draw_ascii(lives)
|
||||||
console("mot à deviner: " .. word)
|
console("mot a deviner: " .. word)
|
||||||
console("lettres essayées: " .. letters_played)
|
console("lettres essayees: " .. letters_played)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if won then
|
if won then
|
||||||
console("Le mot " .. word .. " a été deviné à " .. lives .. " erreurs prêt !")
|
console("Le mot " .. word .. " a ete devine a " .. lives .. " erreurs prêt !")
|
||||||
else
|
else
|
||||||
console("Le mot était " .. word .. ", dommage !")
|
console("Le mot etait " .. word .. ", dommage !")
|
||||||
end
|
end
|
||||||
console("en attente d'une proposition de mot...")
|
console("en attente d'une proposition de mot...")
|
||||||
end
|
end
|
||||||
|
@ -78,7 +88,7 @@ function broadcast_state()
|
||||||
end
|
end
|
||||||
|
|
||||||
function handle_state_query(len, message, topic_len, topic_name)
|
function handle_state_query(len, message, topic_len, topic_name)
|
||||||
if topic_name != "pendu/gamestate" or message != "query" then
|
if topic_name ~= "pendu/gamestate" or message ~= "query" then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
broadcast_state()
|
broadcast_state()
|
||||||
|
@ -87,7 +97,7 @@ end
|
||||||
client:subscribe("pendu/gamestate", mqtt.QOS0, handle_state_query)
|
client:subscribe("pendu/gamestate", mqtt.QOS0, handle_state_query)
|
||||||
|
|
||||||
function handle_word_suggestion(len, message, topic_len, topic_name)
|
function handle_word_suggestion(len, message, topic_len, topic_name)
|
||||||
if topic_name != "pendu/word" or playing then
|
if topic_name ~= "pendu/word" or playing then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
word = message
|
word = message
|
||||||
|
@ -100,12 +110,12 @@ end
|
||||||
client:subscribe("pendu/word", mqtt.QOS0, handle_word_suggestion)
|
client:subscribe("pendu/word", mqtt.QOS0, handle_word_suggestion)
|
||||||
|
|
||||||
function handle_letter(len, message, topic_len, topic_name)
|
function handle_letter(len, message, topic_len, topic_name)
|
||||||
if topic_name != "pendu/letter" or not playing then
|
if topic_name ~= "pendu/letter" or not playing then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if was_already_played(message) then
|
if was_already_played(message) then
|
||||||
draw_ui()
|
draw_ui()
|
||||||
console(message .. " a déjà été joué.")
|
console(message .. " a deja ete joue.")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
letters_played = letters_played .. message
|
letters_played = letters_played .. message
|
||||||
|
@ -123,7 +133,7 @@ function handle_letter(len, message, topic_len, topic_name)
|
||||||
end
|
end
|
||||||
if not is_won() then
|
if not is_won() then
|
||||||
draw_ui()
|
draw_ui()
|
||||||
console(message .. " trouvé ! Bien joué !")
|
console(message .. " trouve ! Bien joue !")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
won = true
|
won = true
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue