added even more
This commit is contained in:
parent
b7c32efdbc
commit
2c04b39f3c
1 changed files with 51 additions and 3 deletions
|
@ -17,6 +17,7 @@ client:connect("student", password)
|
||||||
|
|
||||||
playing = false
|
playing = false
|
||||||
won = false
|
won = false
|
||||||
|
lives = 10
|
||||||
|
|
||||||
word = ""
|
word = ""
|
||||||
letters_played = ""
|
letters_played = ""
|
||||||
|
@ -34,8 +35,31 @@ function draw_ui()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function update_victory()
|
function is_won()
|
||||||
|
for i=1, #word do
|
||||||
|
if not was_already_played(word[i]) then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
function was_already_played(l)
|
||||||
|
for i=1, #letters_played do
|
||||||
|
if letters_played[i] == l then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
function is_in_word(l)
|
||||||
|
for i=1, #word do
|
||||||
|
if word[i] == l then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
function broadcast_state()
|
function broadcast_state()
|
||||||
|
@ -71,9 +95,33 @@ 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
|
||||||
|
draw_ui()
|
||||||
|
console(message .. " a déjà été joué.")
|
||||||
|
return
|
||||||
|
end
|
||||||
letters_played = letters_played .. message
|
letters_played = letters_played .. message
|
||||||
update_victory()
|
if not is_in_word(message) then
|
||||||
|
lives = lives - 1
|
||||||
|
if lives == 0 then
|
||||||
|
playing = false
|
||||||
|
broadcast_state()
|
||||||
|
draw_ui()
|
||||||
|
return
|
||||||
|
end
|
||||||
|
draw_ui()
|
||||||
|
console(message .. " ne fait pas partie du mot...")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if not is_won() then
|
||||||
|
draw_ui()
|
||||||
|
console(message .. " trouvé ! Bien joué !")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
won = true
|
||||||
|
playing = false
|
||||||
|
broadcast_state()
|
||||||
draw_ui()
|
draw_ui()
|
||||||
end
|
end
|
||||||
|
|
||||||
client:subscribe("pendu/letter", mqtt.QOS0, handle_letter)
|
client:subscribe("pendu/letter", mqtt.QOS0, handle_letter)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue