Hangman Game facing an issue

Certified Senior Developer

Hi all,

Hangman is a guessing game for two or more players. One player thinks of a word, phrase, or sentence and draws a dash for each letter. The other player then guesses letters once a time. If the guess is correct, the player who made the puzzle writes the letter over the corresponding dashes. if the guess is wrong, the player who made the puzzle draws a part of the hangman. The goal is to guess the word before the character is hung.

So, Please suggest how to design that game I tried facing an issue

a!localVariables(
local!wordList: {"python", "hangman", "programming", "computer", "code"},
local!guessedLetters: {},
local!attemptsLeft: 6,
local!currentDisplay: "",
local!gameOver: false,
local!winMessage: "Congratulations! You guessed the word: ",
local!loseMessage: "Sorry, you ran out of attempts. The word was: ",
local!wordToGuess: if(isnull(local!wordToGuess), rndindex(local!wordList), local!wordToGuess),
a!sectionLayout(
label: "Hangman Game",
contents: {
a!paragraph(
text: "Welcome to Hangman!"
),
a!paragraph(
text: if(
not(local!gameOver),
concat("Current word: ", local!currentDisplay),
if(
length(local!wordToGuess) > 0,
if(
local!attemptsLeft = 0,
concat(local!loseMessage, local!wordToGuess),
concat(local!winMessage, local!wordToGuess)
),
""
)
)
),
a!paragraph(
text: if(
not(local!gameOver),
concat("Attempts left: ", local!attemptsLeft),
""
)
),
a!textField(
label: "Enter a letter:",
instructions: "Type a single letter and press Enter.",
value: "",
saveInto: local!guessedLetters,
validations: {
message: "Invalid input. Please enter a single letter.",
rule: and(
not(isnull(local!guessedLetters)),
not(isnull(local!guessedLetters[1])),
not(isletter(local!guessedLetters[1]))
)
}
),
a!buttonWidget(
label: "Guess",
saveInto: {
local!currentDisplay,
local!attemptsLeft,
local!gameOver
},
value: if(
and(
not(local!gameOver),
contains(local!wordToGuess, "_")
),
a!forEach(
items: split(local!wordToGuess, ""),
expression: if(
contains(local!guessedLetters, fv!item),
fv!item,
"_"
)
),
""
),
validations: {
a!validation(
message: "Please enter a letter before guessing.",
rule: length(local!guessedLetters) > 0
)
}
)
}
),
)


Thank You In Advance

  Discussion posts and replies are publicly visible