Skip to main content
medap0001
January 11, 2024
Solved

Hangman Game facing an issue

  • January 11, 2024
  • 6 replies
  • 0 views

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

    Best answer by harshitb6843

    You can use CHatGPT in such cases to understand the login and then create them on Appian. Much faster and more precise. 

    6 replies

    stefanhelzle0001
    January 11, 2024

    What is the issue you are facing?

    jonesprakashs0001
    January 11, 2024

    Hi [mention:a843dc22968a4246b14acd1a2e8a672e:e9ed411860ed4f2ba0265705b8793d05] ,

    Next time to insert the code, make sure to use the below available option which helps in better readability

    Also, it's clearly mentioned that the error is with local!wordToGuess. You can't call the same local variable at the time of defining it initially. Also what is rndindex here?

    harshitb6843
    January 11, 2024

    You can use CHatGPT in such cases to understand the login and then create them on Appian. Much faster and more precise. 

    medap0001
    medap0001Author
    January 12, 2024

    Can you help me with that code please

    konduruc733182
    January 12, 2024

    Hello medap0001,

    You need to tell what exactly is your requirement (I know you have mentioned it above but what is your expectation of the interface in Appian) and what Harshit is suggesting is you to try using chatGPT for getting a proper logic. You can build your code based on the logic you get from ChatGPT. I also recommend write down the points/steps in a sequential order as a story and start building your code. 

    Just curious which version of Appian are you currently using?