IT'S ALIIIIIIIIIIIVE!
This commit is contained in:
parent
40ddc3196b
commit
a2b0006d11
1 changed files with 37 additions and 21 deletions
|
@ -2,6 +2,8 @@ dofile("screen.lua")
|
||||||
|
|
||||||
dofile("mqtt_config.lua")
|
dofile("mqtt_config.lua")
|
||||||
|
|
||||||
|
attachscreen(18, 19, 0x3C)
|
||||||
|
|
||||||
cls()
|
cls()
|
||||||
console("Welcome to pendu!")
|
console("Welcome to pendu!")
|
||||||
console("by Lorem Impsum Corp.")
|
console("by Lorem Impsum Corp.")
|
||||||
|
@ -11,15 +13,6 @@ console("Connecting...")
|
||||||
client:connect("student", password)
|
client:connect("student", password)
|
||||||
console("Connected !")
|
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
|
if neo ~= nil then
|
||||||
-- connecte la bande de led sur le pin 21
|
-- connecte la bande de led sur le pin 21
|
||||||
neo = neopixel.attach(neopixel.WS2812B, pio.GPIO21, 8)
|
neo = neopixel.attach(neopixel.WS2812B, pio.GPIO21, 8)
|
||||||
|
@ -32,29 +25,45 @@ lives = 10
|
||||||
word = ""
|
word = ""
|
||||||
letters_played = ""
|
letters_played = ""
|
||||||
|
|
||||||
function draw_ascii(lives)
|
function get_public_word()
|
||||||
|
r = ""
|
||||||
|
for i=1, #word do
|
||||||
|
if was_already_played(word:sub(i, i)) then
|
||||||
|
r = r .. word:sub(i, i)
|
||||||
|
else
|
||||||
|
r = r .. "_"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return r
|
||||||
end
|
end
|
||||||
|
|
||||||
function draw_ui()
|
function draw_ui()
|
||||||
cls()
|
cls()
|
||||||
if playing then
|
if playing then
|
||||||
draw_ascii(lives)
|
console("tentatives: " .. lives)
|
||||||
console("mot a deviner: " .. word)
|
console("mot a deviner: ")
|
||||||
console("lettres essayees: " .. letters_played)
|
console(get_public_word())
|
||||||
|
console("lettres essayees: ")
|
||||||
|
console(letters_played)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if won then
|
if won then
|
||||||
console("Le mot " .. word .. " a ete devine a " .. lives .. " erreurs prêt !")
|
console("Le mot etait :")
|
||||||
|
console(word)
|
||||||
|
console("Il a ete devine avec")
|
||||||
|
console((10 - lives) .. " erreurs !")
|
||||||
else
|
else
|
||||||
console("Le mot etait " .. word .. ", dommage !")
|
console("Le mot etait :")
|
||||||
|
console(word)
|
||||||
|
console("\ndommage !")
|
||||||
end
|
end
|
||||||
console("en attente d'une proposition de mot...")
|
console("En attente d'une")
|
||||||
|
console("proposition de mot...")
|
||||||
end
|
end
|
||||||
|
|
||||||
function is_won()
|
function is_won()
|
||||||
for i=1, #word do
|
for i=1, #word do
|
||||||
if not was_already_played(word[i]) then
|
if not was_already_played(word:sub(i, i)) then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -63,7 +72,7 @@ end
|
||||||
|
|
||||||
function was_already_played(l)
|
function was_already_played(l)
|
||||||
for i=1, #letters_played do
|
for i=1, #letters_played do
|
||||||
if letters_played[i] == l then
|
if letters_played:sub(i, i) == l then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -72,7 +81,7 @@ end
|
||||||
|
|
||||||
function is_in_word(l)
|
function is_in_word(l)
|
||||||
for i=1, #word do
|
for i=1, #word do
|
||||||
if word[i] == l then
|
if word:sub(i, i) == l then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -128,7 +137,8 @@ function handle_letter(len, message, topic_len, topic_name)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
draw_ui()
|
draw_ui()
|
||||||
console(message .. " ne fait pas partie du mot...")
|
console(message .. " ne fait pas partie")
|
||||||
|
console("du mot...")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if not is_won() then
|
if not is_won() then
|
||||||
|
@ -143,3 +153,9 @@ function handle_letter(len, message, topic_len, topic_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
client:subscribe("pendu/letter", mqtt.QOS0, handle_letter)
|
client:subscribe("pendu/letter", mqtt.QOS0, handle_letter)
|
||||||
|
|
||||||
|
cls()
|
||||||
|
console("En attente d'une")
|
||||||
|
console("proposition de mot...")
|
||||||
|
|
||||||
|
--------------------------------------------------------------------
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue