How to add new features to my Hangman game?2019 Community Moderator ElectionHow can I Remove .DS_Store files from a Git repository?Hidden Features of XcodeHow to check for an active Internet connection on iOS or macOS?How to start PostgreSQL server on Mac OS X?How do I install pip on macOS or OS X?How to set or change the default Java (JDK) version on OS X?How to install Java 8 on Macnvm keeps “forgetting” node in new terminal sessionProcessing incoming messages in Applescript via mail rule in Maverickshow to add a play again feature to javascript game

A Cautionary Suggestion

Employee lack of ownership

Interplanetary conflict, some disease destroys the ability to understand or appreciate music

Are ETF trackers fundamentally better than individual stocks?

How to deal with taxi scam when on vacation?

Is it true that good novels will automatically sell themselves on Amazon (and so on) and there is no need for one to waste time promoting?

Are there verbs that are neither telic, or atelic?

How to write cleanly even if my character uses expletive language?

Why would a flight no longer considered airworthy be redirected like this?

Official degrees of earth’s rotation per day

Most cost effective thermostat setting: consistent temperature vs. lowest temperature possible

Why did it take so long to abandon sail after steamships were demonstrated?

Why doesn't the EU now just force the UK to choose between referendum and no-deal?

Professor being mistaken for a grad student

What do Xenomorphs eat in the Alien series?

Sailing the cryptic seas

Dice rolling probability game

Should we release the security issues we found in our product as CVE or we can just update those on weekly release notes?

What approach do we need to follow for projects without a test environment?

Did Ender ever learn that he killed Stilson and/or Bonzo?

If curse and magic is two sides of the same coin, why the former is forbidden?

Do I need to be arrogant to get ahead?

How to explain that I do not want to visit a country due to personal safety concern?

Gantt Chart like rectangles with log scale



How to add new features to my Hangman game?



2019 Community Moderator ElectionHow can I Remove .DS_Store files from a Git repository?Hidden Features of XcodeHow to check for an active Internet connection on iOS or macOS?How to start PostgreSQL server on Mac OS X?How do I install pip on macOS or OS X?How to set or change the default Java (JDK) version on OS X?How to install Java 8 on Macnvm keeps “forgetting” node in new terminal sessionProcessing incoming messages in Applescript via mail rule in Maverickshow to add a play again feature to javascript game










0















I am working on a game, Hangman. I have the code down, I just want to display the word if you lose. How can I do that?



hangman's init()--by Londres on Stack Overflow

script hangman
property stdin : missing value
property stdout : missing value
property dict : missing value

on init()
--starting up the game
set stdin to parent's hangmanStdin's alloc()'s init()
set stdout to parent's hangmanStdout's alloc()'s init()
set dict to parent's hangmanDictionary's alloc()'s init()
my mainLoop()
end init

on mainLoop()
repeat --endless
set option to stdin's getOptions("Lobby", "What would you like to do?", "New Game", "Quit")
if option is "New Game" then
set difficulty to stdin's getOptions("New Game", "Choose your difficulty", "Normal", "Easy", "Hard")
--replace this line with an automatic word generator
set x to parent's hangmanGame's alloc()'s initWithWordAndDifficulty(dict's getWord(), difficulty)

if x's startgame() is false then
return
else
stdout's printf("You've scored " & x's score & " points.")
end if
--game is over so clear it
set x to missing value
else
exit repeat
end if
end repeat
end mainLoop

on shouldTerminate()
return true
end shouldTerminate


on alloc()
copy me to x
return x
end alloc
end script

script hangmanGame
property parent : hangman

property wordToGuess : missing value
property maxFaults : missing value
property usedChars : missing value
property faults : missing value
property score : 0

on initWithWordAndDifficulty(theWord, theDifficulty)
if theDifficulty = "Hard" then
set my maxFaults to 5
else if theDifficulty = "Normal" then
set my maxFaults to 8
else --easy or any other value will be handled as easy
set my maxFaults to 12
end if
set my wordToGuess to theWord
set my usedChars to
set my faults to 0
set my score to 0
return me
end initWithWordAndDifficulty

on startgame()
repeat --endless
set __prompt to "Faults Left: " & maxFaults - faults & return & "The Word: " & my makeHiddenField()
set c to parent's stdin's getChar(__prompt)
if c = false then
return false
end if
--first check if getChar did give us any result
if length of c is not 0 then
--check if teh character is valid
if c is in "abcdefghijklmnopqrstuvwxyz" then
--check if we already checked this before
if c is not in my usedChars then
set end of my usedChars to c
--check if player guessed wrong character
if c is not in wordToGuess then
set faults to faults + 1
end if
end if
end if
end if
--check if player guessed all characters of word
if my wordGuessed() then
set my score to ((25 * (26 / (length of my usedChars))) as integer)
return true
end if
--check if player reached the max faults he's allowed to make
if my faults = my maxFaults then
return 0
end if
end repeat
end startgame

on wordGuessed()
repeat with aChar in every text item of my wordToGuess
if aChar is not in my usedChars then
return false
end if
end repeat
return true
end wordGuessed

on makeHiddenField()
set characterArray to
repeat with aChar in every text item of my wordToGuess
if aChar is in my usedChars then
set end of characterArray to aChar as string
else
set end of characterArray to "_"
end if
end repeat
set AppleScript's text item delimiters to space
set hiddenField to characterArray as string
set AppleScript's text item delimiters to ""
return hiddenField
end makeHiddenField
end script

script hangmanDictionary
property parent : hangman
property wordsPlayed : missing value
property allWords : missing value

on init()
set wordsPlayed to
--try to get more words from a file for example
set allWords to "Hangman", "Police", "Officer", "Desktop", "Pencil", "Window", "Language", "Wealthy", "Trauma", "Spell", "Rival", "Tactical", "Thin", "Salty", "Bluish", "Falcon", "Distilery", "Ballistics", "Fumbling", "Limitless", "South", "Humble", "Foreign", "Affliction", "Retreat", "Agreeable", "Poisoner", "Flirt", "Fearsome", "Deepwater", "Bottom", "Twisted", "Morsel", "Filament", "Winter", "Contempt", "Drimys", "Grease", "Awesome", "Compulsive", "Crayon", "Prayer", "Blonde", "Backbone", "Dreamland", "Ballet", "Continuous", "Aerobatic", "Hideous", "Harmonic", "Lottery", "Encrypt", "Cable", "Aluminium", "Hunter", "National", "Hunter", "Mechanical", "Deadbeat", "Opposition", "Threat", "Decadent", "Gazelle", "Guild", "Authoritive", "Deliverance", "Severe", "Jerid", "Alarm", "Monochrome", "Cyanide", "External", "Potential", "Section", "Innocent", "Drifting", "Amnesia", "Domino", "Flimsy", "Flamethrowing", "Advocate", "Hirsute", "Brother", "Ephemeral", "Brutal", "Decade", "Drauma", "Dilemma", "Exquisite", "Glimmer", "Fugitive", "Digital", "Associate", "Ambivalent", "Ambulatory", "Apology", "Brawler", "Molecular", "Insurance", "Contractual", "Initial", "Calibration", "Heretical", "Disclosure", "Guerilla", "Dismember", "Minimal", "Altercation", "Eastern", "Integrate", "Femur", "Metallic", "Ambition", "Auxiliary", "Esoteric", "Converse", "Accepting", "Juvenile", "Efficacious", "Complex", "Imperil", "Division", "Onerous", "Astonish", "Scandalous", "Quaint", "Dominate", "Contrary", "Conspiracy", "Earthquake", "Embarrassment", "Exclude", "Ambiguous", "Captivate", "Compliance", "Migration", "Embryo", "Abandon", "Conservation", "Appreciate", "Applaud", "Pension", "Voyage", "Influence", "Consensus", "Incapable", "Economy", "Parameter", "Contrast", "Sensitive", "Meadow", "Chimney", "Familiar", "Serious", "Credibility", "Infrastructure", "Museum", "Relinquish", "Merit", "Coalition", "Retirement", "Transaction", "Official", "Composer", "Magnitude", "Committee", "Privilege", "Diamond", "Obligation", "Transition", "Jockey", "Reinforce", "Conflict", "Offensive", "Detective", "Effective", "Detector"
return me
end init

on getWord()
set randomNr to (random number from 1 to (length of (my allWords))) as integer
--you could do somethinh here when a word is used again
return item randomNr of my allWords as string
end getWord
end script

script hangmanStdin
property parent : hangman

on init()
return me
end init

on getChar(__prompt)
set x to display dialog __prompt buttons "Go", "Quit" default button "Go" default answer ""
if button returned of x = "Quit" then
return false
end if

if length of x's text returned = 0 then
return ""
end if

return character 1 of x's text returned
end getChar

on getOptions(__title, __message, __options)
return button returned of (display alert __title message __message buttons __options default button 1)
end getOptions
end script

script hangmanStdout
property parent : hangman

on init()
return me
end init

on printf(__message)
display dialog __message buttons "OK" default button 1
end printf
end script


How can I make it so if you lose the game, not only does it say the you got 0 points but also say the word that they missed. I'm trying my best to get this done. It's a project that I'm doing to get the basics of coding. Took me awhile.










share|improve this question
























  • What problem are you having with the first feature you want to implement?

    – halfer
    Mar 6 at 20:20











  • Looks like you need to check the results of startgame() for more than true/false. That is some strange looking AppleScript you have there (those alloc()'s are totally unnecessary, for example) - what language are you converting this from?

    – red_menace
    Mar 6 at 23:18











  • @halfer This was made AWHILE AGO and i cant seem to find a place to put the code i want to display the word that was missed.

    – Londres
    Mar 7 at 4:32











  • @halfer I have major respect for your accomplishments (I read your bio) I greatly appreciate the help. I just dabble in applescript and this was made a long time ago and i would just like to find a place in the script to put the code that I want, so it displays the word that was missed. If you can help me with this, I would greatly appreciate it.

    – Londres
    Mar 7 at 4:35
















0















I am working on a game, Hangman. I have the code down, I just want to display the word if you lose. How can I do that?



hangman's init()--by Londres on Stack Overflow

script hangman
property stdin : missing value
property stdout : missing value
property dict : missing value

on init()
--starting up the game
set stdin to parent's hangmanStdin's alloc()'s init()
set stdout to parent's hangmanStdout's alloc()'s init()
set dict to parent's hangmanDictionary's alloc()'s init()
my mainLoop()
end init

on mainLoop()
repeat --endless
set option to stdin's getOptions("Lobby", "What would you like to do?", "New Game", "Quit")
if option is "New Game" then
set difficulty to stdin's getOptions("New Game", "Choose your difficulty", "Normal", "Easy", "Hard")
--replace this line with an automatic word generator
set x to parent's hangmanGame's alloc()'s initWithWordAndDifficulty(dict's getWord(), difficulty)

if x's startgame() is false then
return
else
stdout's printf("You've scored " & x's score & " points.")
end if
--game is over so clear it
set x to missing value
else
exit repeat
end if
end repeat
end mainLoop

on shouldTerminate()
return true
end shouldTerminate


on alloc()
copy me to x
return x
end alloc
end script

script hangmanGame
property parent : hangman

property wordToGuess : missing value
property maxFaults : missing value
property usedChars : missing value
property faults : missing value
property score : 0

on initWithWordAndDifficulty(theWord, theDifficulty)
if theDifficulty = "Hard" then
set my maxFaults to 5
else if theDifficulty = "Normal" then
set my maxFaults to 8
else --easy or any other value will be handled as easy
set my maxFaults to 12
end if
set my wordToGuess to theWord
set my usedChars to
set my faults to 0
set my score to 0
return me
end initWithWordAndDifficulty

on startgame()
repeat --endless
set __prompt to "Faults Left: " & maxFaults - faults & return & "The Word: " & my makeHiddenField()
set c to parent's stdin's getChar(__prompt)
if c = false then
return false
end if
--first check if getChar did give us any result
if length of c is not 0 then
--check if teh character is valid
if c is in "abcdefghijklmnopqrstuvwxyz" then
--check if we already checked this before
if c is not in my usedChars then
set end of my usedChars to c
--check if player guessed wrong character
if c is not in wordToGuess then
set faults to faults + 1
end if
end if
end if
end if
--check if player guessed all characters of word
if my wordGuessed() then
set my score to ((25 * (26 / (length of my usedChars))) as integer)
return true
end if
--check if player reached the max faults he's allowed to make
if my faults = my maxFaults then
return 0
end if
end repeat
end startgame

on wordGuessed()
repeat with aChar in every text item of my wordToGuess
if aChar is not in my usedChars then
return false
end if
end repeat
return true
end wordGuessed

on makeHiddenField()
set characterArray to
repeat with aChar in every text item of my wordToGuess
if aChar is in my usedChars then
set end of characterArray to aChar as string
else
set end of characterArray to "_"
end if
end repeat
set AppleScript's text item delimiters to space
set hiddenField to characterArray as string
set AppleScript's text item delimiters to ""
return hiddenField
end makeHiddenField
end script

script hangmanDictionary
property parent : hangman
property wordsPlayed : missing value
property allWords : missing value

on init()
set wordsPlayed to
--try to get more words from a file for example
set allWords to "Hangman", "Police", "Officer", "Desktop", "Pencil", "Window", "Language", "Wealthy", "Trauma", "Spell", "Rival", "Tactical", "Thin", "Salty", "Bluish", "Falcon", "Distilery", "Ballistics", "Fumbling", "Limitless", "South", "Humble", "Foreign", "Affliction", "Retreat", "Agreeable", "Poisoner", "Flirt", "Fearsome", "Deepwater", "Bottom", "Twisted", "Morsel", "Filament", "Winter", "Contempt", "Drimys", "Grease", "Awesome", "Compulsive", "Crayon", "Prayer", "Blonde", "Backbone", "Dreamland", "Ballet", "Continuous", "Aerobatic", "Hideous", "Harmonic", "Lottery", "Encrypt", "Cable", "Aluminium", "Hunter", "National", "Hunter", "Mechanical", "Deadbeat", "Opposition", "Threat", "Decadent", "Gazelle", "Guild", "Authoritive", "Deliverance", "Severe", "Jerid", "Alarm", "Monochrome", "Cyanide", "External", "Potential", "Section", "Innocent", "Drifting", "Amnesia", "Domino", "Flimsy", "Flamethrowing", "Advocate", "Hirsute", "Brother", "Ephemeral", "Brutal", "Decade", "Drauma", "Dilemma", "Exquisite", "Glimmer", "Fugitive", "Digital", "Associate", "Ambivalent", "Ambulatory", "Apology", "Brawler", "Molecular", "Insurance", "Contractual", "Initial", "Calibration", "Heretical", "Disclosure", "Guerilla", "Dismember", "Minimal", "Altercation", "Eastern", "Integrate", "Femur", "Metallic", "Ambition", "Auxiliary", "Esoteric", "Converse", "Accepting", "Juvenile", "Efficacious", "Complex", "Imperil", "Division", "Onerous", "Astonish", "Scandalous", "Quaint", "Dominate", "Contrary", "Conspiracy", "Earthquake", "Embarrassment", "Exclude", "Ambiguous", "Captivate", "Compliance", "Migration", "Embryo", "Abandon", "Conservation", "Appreciate", "Applaud", "Pension", "Voyage", "Influence", "Consensus", "Incapable", "Economy", "Parameter", "Contrast", "Sensitive", "Meadow", "Chimney", "Familiar", "Serious", "Credibility", "Infrastructure", "Museum", "Relinquish", "Merit", "Coalition", "Retirement", "Transaction", "Official", "Composer", "Magnitude", "Committee", "Privilege", "Diamond", "Obligation", "Transition", "Jockey", "Reinforce", "Conflict", "Offensive", "Detective", "Effective", "Detector"
return me
end init

on getWord()
set randomNr to (random number from 1 to (length of (my allWords))) as integer
--you could do somethinh here when a word is used again
return item randomNr of my allWords as string
end getWord
end script

script hangmanStdin
property parent : hangman

on init()
return me
end init

on getChar(__prompt)
set x to display dialog __prompt buttons "Go", "Quit" default button "Go" default answer ""
if button returned of x = "Quit" then
return false
end if

if length of x's text returned = 0 then
return ""
end if

return character 1 of x's text returned
end getChar

on getOptions(__title, __message, __options)
return button returned of (display alert __title message __message buttons __options default button 1)
end getOptions
end script

script hangmanStdout
property parent : hangman

on init()
return me
end init

on printf(__message)
display dialog __message buttons "OK" default button 1
end printf
end script


How can I make it so if you lose the game, not only does it say the you got 0 points but also say the word that they missed. I'm trying my best to get this done. It's a project that I'm doing to get the basics of coding. Took me awhile.










share|improve this question
























  • What problem are you having with the first feature you want to implement?

    – halfer
    Mar 6 at 20:20











  • Looks like you need to check the results of startgame() for more than true/false. That is some strange looking AppleScript you have there (those alloc()'s are totally unnecessary, for example) - what language are you converting this from?

    – red_menace
    Mar 6 at 23:18











  • @halfer This was made AWHILE AGO and i cant seem to find a place to put the code i want to display the word that was missed.

    – Londres
    Mar 7 at 4:32











  • @halfer I have major respect for your accomplishments (I read your bio) I greatly appreciate the help. I just dabble in applescript and this was made a long time ago and i would just like to find a place in the script to put the code that I want, so it displays the word that was missed. If you can help me with this, I would greatly appreciate it.

    – Londres
    Mar 7 at 4:35














0












0








0








I am working on a game, Hangman. I have the code down, I just want to display the word if you lose. How can I do that?



hangman's init()--by Londres on Stack Overflow

script hangman
property stdin : missing value
property stdout : missing value
property dict : missing value

on init()
--starting up the game
set stdin to parent's hangmanStdin's alloc()'s init()
set stdout to parent's hangmanStdout's alloc()'s init()
set dict to parent's hangmanDictionary's alloc()'s init()
my mainLoop()
end init

on mainLoop()
repeat --endless
set option to stdin's getOptions("Lobby", "What would you like to do?", "New Game", "Quit")
if option is "New Game" then
set difficulty to stdin's getOptions("New Game", "Choose your difficulty", "Normal", "Easy", "Hard")
--replace this line with an automatic word generator
set x to parent's hangmanGame's alloc()'s initWithWordAndDifficulty(dict's getWord(), difficulty)

if x's startgame() is false then
return
else
stdout's printf("You've scored " & x's score & " points.")
end if
--game is over so clear it
set x to missing value
else
exit repeat
end if
end repeat
end mainLoop

on shouldTerminate()
return true
end shouldTerminate


on alloc()
copy me to x
return x
end alloc
end script

script hangmanGame
property parent : hangman

property wordToGuess : missing value
property maxFaults : missing value
property usedChars : missing value
property faults : missing value
property score : 0

on initWithWordAndDifficulty(theWord, theDifficulty)
if theDifficulty = "Hard" then
set my maxFaults to 5
else if theDifficulty = "Normal" then
set my maxFaults to 8
else --easy or any other value will be handled as easy
set my maxFaults to 12
end if
set my wordToGuess to theWord
set my usedChars to
set my faults to 0
set my score to 0
return me
end initWithWordAndDifficulty

on startgame()
repeat --endless
set __prompt to "Faults Left: " & maxFaults - faults & return & "The Word: " & my makeHiddenField()
set c to parent's stdin's getChar(__prompt)
if c = false then
return false
end if
--first check if getChar did give us any result
if length of c is not 0 then
--check if teh character is valid
if c is in "abcdefghijklmnopqrstuvwxyz" then
--check if we already checked this before
if c is not in my usedChars then
set end of my usedChars to c
--check if player guessed wrong character
if c is not in wordToGuess then
set faults to faults + 1
end if
end if
end if
end if
--check if player guessed all characters of word
if my wordGuessed() then
set my score to ((25 * (26 / (length of my usedChars))) as integer)
return true
end if
--check if player reached the max faults he's allowed to make
if my faults = my maxFaults then
return 0
end if
end repeat
end startgame

on wordGuessed()
repeat with aChar in every text item of my wordToGuess
if aChar is not in my usedChars then
return false
end if
end repeat
return true
end wordGuessed

on makeHiddenField()
set characterArray to
repeat with aChar in every text item of my wordToGuess
if aChar is in my usedChars then
set end of characterArray to aChar as string
else
set end of characterArray to "_"
end if
end repeat
set AppleScript's text item delimiters to space
set hiddenField to characterArray as string
set AppleScript's text item delimiters to ""
return hiddenField
end makeHiddenField
end script

script hangmanDictionary
property parent : hangman
property wordsPlayed : missing value
property allWords : missing value

on init()
set wordsPlayed to
--try to get more words from a file for example
set allWords to "Hangman", "Police", "Officer", "Desktop", "Pencil", "Window", "Language", "Wealthy", "Trauma", "Spell", "Rival", "Tactical", "Thin", "Salty", "Bluish", "Falcon", "Distilery", "Ballistics", "Fumbling", "Limitless", "South", "Humble", "Foreign", "Affliction", "Retreat", "Agreeable", "Poisoner", "Flirt", "Fearsome", "Deepwater", "Bottom", "Twisted", "Morsel", "Filament", "Winter", "Contempt", "Drimys", "Grease", "Awesome", "Compulsive", "Crayon", "Prayer", "Blonde", "Backbone", "Dreamland", "Ballet", "Continuous", "Aerobatic", "Hideous", "Harmonic", "Lottery", "Encrypt", "Cable", "Aluminium", "Hunter", "National", "Hunter", "Mechanical", "Deadbeat", "Opposition", "Threat", "Decadent", "Gazelle", "Guild", "Authoritive", "Deliverance", "Severe", "Jerid", "Alarm", "Monochrome", "Cyanide", "External", "Potential", "Section", "Innocent", "Drifting", "Amnesia", "Domino", "Flimsy", "Flamethrowing", "Advocate", "Hirsute", "Brother", "Ephemeral", "Brutal", "Decade", "Drauma", "Dilemma", "Exquisite", "Glimmer", "Fugitive", "Digital", "Associate", "Ambivalent", "Ambulatory", "Apology", "Brawler", "Molecular", "Insurance", "Contractual", "Initial", "Calibration", "Heretical", "Disclosure", "Guerilla", "Dismember", "Minimal", "Altercation", "Eastern", "Integrate", "Femur", "Metallic", "Ambition", "Auxiliary", "Esoteric", "Converse", "Accepting", "Juvenile", "Efficacious", "Complex", "Imperil", "Division", "Onerous", "Astonish", "Scandalous", "Quaint", "Dominate", "Contrary", "Conspiracy", "Earthquake", "Embarrassment", "Exclude", "Ambiguous", "Captivate", "Compliance", "Migration", "Embryo", "Abandon", "Conservation", "Appreciate", "Applaud", "Pension", "Voyage", "Influence", "Consensus", "Incapable", "Economy", "Parameter", "Contrast", "Sensitive", "Meadow", "Chimney", "Familiar", "Serious", "Credibility", "Infrastructure", "Museum", "Relinquish", "Merit", "Coalition", "Retirement", "Transaction", "Official", "Composer", "Magnitude", "Committee", "Privilege", "Diamond", "Obligation", "Transition", "Jockey", "Reinforce", "Conflict", "Offensive", "Detective", "Effective", "Detector"
return me
end init

on getWord()
set randomNr to (random number from 1 to (length of (my allWords))) as integer
--you could do somethinh here when a word is used again
return item randomNr of my allWords as string
end getWord
end script

script hangmanStdin
property parent : hangman

on init()
return me
end init

on getChar(__prompt)
set x to display dialog __prompt buttons "Go", "Quit" default button "Go" default answer ""
if button returned of x = "Quit" then
return false
end if

if length of x's text returned = 0 then
return ""
end if

return character 1 of x's text returned
end getChar

on getOptions(__title, __message, __options)
return button returned of (display alert __title message __message buttons __options default button 1)
end getOptions
end script

script hangmanStdout
property parent : hangman

on init()
return me
end init

on printf(__message)
display dialog __message buttons "OK" default button 1
end printf
end script


How can I make it so if you lose the game, not only does it say the you got 0 points but also say the word that they missed. I'm trying my best to get this done. It's a project that I'm doing to get the basics of coding. Took me awhile.










share|improve this question
















I am working on a game, Hangman. I have the code down, I just want to display the word if you lose. How can I do that?



hangman's init()--by Londres on Stack Overflow

script hangman
property stdin : missing value
property stdout : missing value
property dict : missing value

on init()
--starting up the game
set stdin to parent's hangmanStdin's alloc()'s init()
set stdout to parent's hangmanStdout's alloc()'s init()
set dict to parent's hangmanDictionary's alloc()'s init()
my mainLoop()
end init

on mainLoop()
repeat --endless
set option to stdin's getOptions("Lobby", "What would you like to do?", "New Game", "Quit")
if option is "New Game" then
set difficulty to stdin's getOptions("New Game", "Choose your difficulty", "Normal", "Easy", "Hard")
--replace this line with an automatic word generator
set x to parent's hangmanGame's alloc()'s initWithWordAndDifficulty(dict's getWord(), difficulty)

if x's startgame() is false then
return
else
stdout's printf("You've scored " & x's score & " points.")
end if
--game is over so clear it
set x to missing value
else
exit repeat
end if
end repeat
end mainLoop

on shouldTerminate()
return true
end shouldTerminate


on alloc()
copy me to x
return x
end alloc
end script

script hangmanGame
property parent : hangman

property wordToGuess : missing value
property maxFaults : missing value
property usedChars : missing value
property faults : missing value
property score : 0

on initWithWordAndDifficulty(theWord, theDifficulty)
if theDifficulty = "Hard" then
set my maxFaults to 5
else if theDifficulty = "Normal" then
set my maxFaults to 8
else --easy or any other value will be handled as easy
set my maxFaults to 12
end if
set my wordToGuess to theWord
set my usedChars to
set my faults to 0
set my score to 0
return me
end initWithWordAndDifficulty

on startgame()
repeat --endless
set __prompt to "Faults Left: " & maxFaults - faults & return & "The Word: " & my makeHiddenField()
set c to parent's stdin's getChar(__prompt)
if c = false then
return false
end if
--first check if getChar did give us any result
if length of c is not 0 then
--check if teh character is valid
if c is in "abcdefghijklmnopqrstuvwxyz" then
--check if we already checked this before
if c is not in my usedChars then
set end of my usedChars to c
--check if player guessed wrong character
if c is not in wordToGuess then
set faults to faults + 1
end if
end if
end if
end if
--check if player guessed all characters of word
if my wordGuessed() then
set my score to ((25 * (26 / (length of my usedChars))) as integer)
return true
end if
--check if player reached the max faults he's allowed to make
if my faults = my maxFaults then
return 0
end if
end repeat
end startgame

on wordGuessed()
repeat with aChar in every text item of my wordToGuess
if aChar is not in my usedChars then
return false
end if
end repeat
return true
end wordGuessed

on makeHiddenField()
set characterArray to
repeat with aChar in every text item of my wordToGuess
if aChar is in my usedChars then
set end of characterArray to aChar as string
else
set end of characterArray to "_"
end if
end repeat
set AppleScript's text item delimiters to space
set hiddenField to characterArray as string
set AppleScript's text item delimiters to ""
return hiddenField
end makeHiddenField
end script

script hangmanDictionary
property parent : hangman
property wordsPlayed : missing value
property allWords : missing value

on init()
set wordsPlayed to
--try to get more words from a file for example
set allWords to "Hangman", "Police", "Officer", "Desktop", "Pencil", "Window", "Language", "Wealthy", "Trauma", "Spell", "Rival", "Tactical", "Thin", "Salty", "Bluish", "Falcon", "Distilery", "Ballistics", "Fumbling", "Limitless", "South", "Humble", "Foreign", "Affliction", "Retreat", "Agreeable", "Poisoner", "Flirt", "Fearsome", "Deepwater", "Bottom", "Twisted", "Morsel", "Filament", "Winter", "Contempt", "Drimys", "Grease", "Awesome", "Compulsive", "Crayon", "Prayer", "Blonde", "Backbone", "Dreamland", "Ballet", "Continuous", "Aerobatic", "Hideous", "Harmonic", "Lottery", "Encrypt", "Cable", "Aluminium", "Hunter", "National", "Hunter", "Mechanical", "Deadbeat", "Opposition", "Threat", "Decadent", "Gazelle", "Guild", "Authoritive", "Deliverance", "Severe", "Jerid", "Alarm", "Monochrome", "Cyanide", "External", "Potential", "Section", "Innocent", "Drifting", "Amnesia", "Domino", "Flimsy", "Flamethrowing", "Advocate", "Hirsute", "Brother", "Ephemeral", "Brutal", "Decade", "Drauma", "Dilemma", "Exquisite", "Glimmer", "Fugitive", "Digital", "Associate", "Ambivalent", "Ambulatory", "Apology", "Brawler", "Molecular", "Insurance", "Contractual", "Initial", "Calibration", "Heretical", "Disclosure", "Guerilla", "Dismember", "Minimal", "Altercation", "Eastern", "Integrate", "Femur", "Metallic", "Ambition", "Auxiliary", "Esoteric", "Converse", "Accepting", "Juvenile", "Efficacious", "Complex", "Imperil", "Division", "Onerous", "Astonish", "Scandalous", "Quaint", "Dominate", "Contrary", "Conspiracy", "Earthquake", "Embarrassment", "Exclude", "Ambiguous", "Captivate", "Compliance", "Migration", "Embryo", "Abandon", "Conservation", "Appreciate", "Applaud", "Pension", "Voyage", "Influence", "Consensus", "Incapable", "Economy", "Parameter", "Contrast", "Sensitive", "Meadow", "Chimney", "Familiar", "Serious", "Credibility", "Infrastructure", "Museum", "Relinquish", "Merit", "Coalition", "Retirement", "Transaction", "Official", "Composer", "Magnitude", "Committee", "Privilege", "Diamond", "Obligation", "Transition", "Jockey", "Reinforce", "Conflict", "Offensive", "Detective", "Effective", "Detector"
return me
end init

on getWord()
set randomNr to (random number from 1 to (length of (my allWords))) as integer
--you could do somethinh here when a word is used again
return item randomNr of my allWords as string
end getWord
end script

script hangmanStdin
property parent : hangman

on init()
return me
end init

on getChar(__prompt)
set x to display dialog __prompt buttons "Go", "Quit" default button "Go" default answer ""
if button returned of x = "Quit" then
return false
end if

if length of x's text returned = 0 then
return ""
end if

return character 1 of x's text returned
end getChar

on getOptions(__title, __message, __options)
return button returned of (display alert __title message __message buttons __options default button 1)
end getOptions
end script

script hangmanStdout
property parent : hangman

on init()
return me
end init

on printf(__message)
display dialog __message buttons "OK" default button 1
end printf
end script


How can I make it so if you lose the game, not only does it say the you got 0 points but also say the word that they missed. I'm trying my best to get this done. It's a project that I'm doing to get the basics of coding. Took me awhile.







macos applescript 2d-games






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 6 at 20:20









halfer

14.7k759115




14.7k759115










asked Mar 6 at 19:58









LondresLondres

11




11












  • What problem are you having with the first feature you want to implement?

    – halfer
    Mar 6 at 20:20











  • Looks like you need to check the results of startgame() for more than true/false. That is some strange looking AppleScript you have there (those alloc()'s are totally unnecessary, for example) - what language are you converting this from?

    – red_menace
    Mar 6 at 23:18











  • @halfer This was made AWHILE AGO and i cant seem to find a place to put the code i want to display the word that was missed.

    – Londres
    Mar 7 at 4:32











  • @halfer I have major respect for your accomplishments (I read your bio) I greatly appreciate the help. I just dabble in applescript and this was made a long time ago and i would just like to find a place in the script to put the code that I want, so it displays the word that was missed. If you can help me with this, I would greatly appreciate it.

    – Londres
    Mar 7 at 4:35


















  • What problem are you having with the first feature you want to implement?

    – halfer
    Mar 6 at 20:20











  • Looks like you need to check the results of startgame() for more than true/false. That is some strange looking AppleScript you have there (those alloc()'s are totally unnecessary, for example) - what language are you converting this from?

    – red_menace
    Mar 6 at 23:18











  • @halfer This was made AWHILE AGO and i cant seem to find a place to put the code i want to display the word that was missed.

    – Londres
    Mar 7 at 4:32











  • @halfer I have major respect for your accomplishments (I read your bio) I greatly appreciate the help. I just dabble in applescript and this was made a long time ago and i would just like to find a place in the script to put the code that I want, so it displays the word that was missed. If you can help me with this, I would greatly appreciate it.

    – Londres
    Mar 7 at 4:35

















What problem are you having with the first feature you want to implement?

– halfer
Mar 6 at 20:20





What problem are you having with the first feature you want to implement?

– halfer
Mar 6 at 20:20













Looks like you need to check the results of startgame() for more than true/false. That is some strange looking AppleScript you have there (those alloc()'s are totally unnecessary, for example) - what language are you converting this from?

– red_menace
Mar 6 at 23:18





Looks like you need to check the results of startgame() for more than true/false. That is some strange looking AppleScript you have there (those alloc()'s are totally unnecessary, for example) - what language are you converting this from?

– red_menace
Mar 6 at 23:18













@halfer This was made AWHILE AGO and i cant seem to find a place to put the code i want to display the word that was missed.

– Londres
Mar 7 at 4:32





@halfer This was made AWHILE AGO and i cant seem to find a place to put the code i want to display the word that was missed.

– Londres
Mar 7 at 4:32













@halfer I have major respect for your accomplishments (I read your bio) I greatly appreciate the help. I just dabble in applescript and this was made a long time ago and i would just like to find a place in the script to put the code that I want, so it displays the word that was missed. If you can help me with this, I would greatly appreciate it.

– Londres
Mar 7 at 4:35






@halfer I have major respect for your accomplishments (I read your bio) I greatly appreciate the help. I just dabble in applescript and this was made a long time ago and i would just like to find a place in the script to put the code that I want, so it displays the word that was missed. If you can help me with this, I would greatly appreciate it.

– Londres
Mar 7 at 4:35













1 Answer
1






active

oldest

votes


















0














You are only checking the return result from hangmanGame’s startGame() handler for false or otherwise, but the handler returns 0 if all the faults are used. You could add an additional check in there, but the easiest way would probably be to add a dialog in the startGame() comparison, for example:



if my faults = my maxFaults then
display dialog "The word was " & quoted form of wordToGuess
return 0
end if





share|improve this answer






















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55031272%2fhow-to-add-new-features-to-my-hangman-game%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    You are only checking the return result from hangmanGame’s startGame() handler for false or otherwise, but the handler returns 0 if all the faults are used. You could add an additional check in there, but the easiest way would probably be to add a dialog in the startGame() comparison, for example:



    if my faults = my maxFaults then
    display dialog "The word was " & quoted form of wordToGuess
    return 0
    end if





    share|improve this answer



























      0














      You are only checking the return result from hangmanGame’s startGame() handler for false or otherwise, but the handler returns 0 if all the faults are used. You could add an additional check in there, but the easiest way would probably be to add a dialog in the startGame() comparison, for example:



      if my faults = my maxFaults then
      display dialog "The word was " & quoted form of wordToGuess
      return 0
      end if





      share|improve this answer

























        0












        0








        0







        You are only checking the return result from hangmanGame’s startGame() handler for false or otherwise, but the handler returns 0 if all the faults are used. You could add an additional check in there, but the easiest way would probably be to add a dialog in the startGame() comparison, for example:



        if my faults = my maxFaults then
        display dialog "The word was " & quoted form of wordToGuess
        return 0
        end if





        share|improve this answer













        You are only checking the return result from hangmanGame’s startGame() handler for false or otherwise, but the handler returns 0 if all the faults are used. You could add an additional check in there, but the easiest way would probably be to add a dialog in the startGame() comparison, for example:



        if my faults = my maxFaults then
        display dialog "The word was " & quoted form of wordToGuess
        return 0
        end if






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 7 at 15:28









        red_menacered_menace

        39519




        39519





























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55031272%2fhow-to-add-new-features-to-my-hangman-game%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

            Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

            Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved