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")
|
||||
|
||||
attachscreen(18, 19, 0x3C)
|
||||
|
||||
cls()
|
||||
console("Welcome to pendu!")
|
||||
console("by Lorem Impsum Corp.")
|
||||
|
@ -11,15 +13,6 @@ console("Connecting...")
|
|||
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)
|
||||
|
@ -32,29 +25,45 @@ lives = 10
|
|||
word = ""
|
||||
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
|
||||
|
||||
function draw_ui()
|
||||
cls()
|
||||
if playing then
|
||||
draw_ascii(lives)
|
||||
console("mot a deviner: " .. word)
|
||||
console("lettres essayees: " .. letters_played)
|
||||
console("tentatives: " .. lives)
|
||||
console("mot a deviner: ")
|
||||
console(get_public_word())
|
||||
console("lettres essayees: ")
|
||||
console(letters_played)
|
||||
return
|
||||
end
|
||||
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
|
||||
console("Le mot etait " .. word .. ", dommage !")
|
||||
console("Le mot etait :")
|
||||
console(word)
|
||||
console("\ndommage !")
|
||||
end
|
||||
console("en attente d'une proposition de mot...")
|
||||
console("En attente d'une")
|
||||
console("proposition de mot...")
|
||||
end
|
||||
|
||||
function is_won()
|
||||
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
|
||||
end
|
||||
end
|
||||
|
@ -63,7 +72,7 @@ end
|
|||
|
||||
function was_already_played(l)
|
||||
for i=1, #letters_played do
|
||||
if letters_played[i] == l then
|
||||
if letters_played:sub(i, i) == l then
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
@ -72,7 +81,7 @@ end
|
|||
|
||||
function is_in_word(l)
|
||||
for i=1, #word do
|
||||
if word[i] == l then
|
||||
if word:sub(i, i) == l then
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
@ -128,7 +137,8 @@ function handle_letter(len, message, topic_len, topic_name)
|
|||
return
|
||||
end
|
||||
draw_ui()
|
||||
console(message .. " ne fait pas partie du mot...")
|
||||
console(message .. " ne fait pas partie")
|
||||
console("du mot...")
|
||||
return
|
||||
end
|
||||
if not is_won() then
|
||||
|
@ -143,3 +153,9 @@ function handle_letter(len, message, topic_len, topic_name)
|
|||
end
|
||||
|
||||
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