Hangman Game

I am making a game of hangman and have adapted the following code that I found on a web site. what I want to do is have a clue come up to help people solve the word. How and where would I incorporate it in this code?

-Words-
Ice
Glacier
Highlands
River
Sea
Climate
Wildlife
Animals
Settlers
Carvings
Eustatic
Isostatic
Iceberg
Earth


 --Hangman Letters--
property myLetter, spriteNum, used

global gHangmanWord

on beginSprite me
  used = 0
  myLetter = sprite(spriteNum).member.name.char[1]
end

on mouseEnter me
  if used = 0 then
    sprite(spriteNum).member = member(myLetter & "-Y")
  end if
end

on mouseLeave me
  if used = 0 then
    sprite(spriteNum).member = member(myLetter & "-W")
  else
    sprite(spriteNum).member = member(myLetter & "-B")
  end if
end

on mouseUp me
  if used = 0 then
    used = true
    if gHangmanWord contains myLetter then      
      sendAllSprites(#showLetter, myLetter)
      returnList = []
      sendAllSprites(#checkWin, returnList)
      if returnList.getOne(0) = 0 then
        go "hangmanwin"
      end if
     
    else
      sendAllSprites(#hangMe)
      sendAllSprites(#checkLoss)
    end if
    sprite(spriteNum).member = member(myLetter & "-b")
  end if
end


--Gallows--
property spriteNum, hangWrong

global gHangmanWord

on hangMe me
  hangWrong = hangWrong + 1
  sprite(spriteNum).member = "hang" & hangWrong
end

on beginSprite me
  hangWrong = 0
  sprite(spriteNum).member = "hang" & hangWrong
end

on checkLoss me
  if hangWrong >= 6 then
    sendAllSprites(#showLoss)
    go "hangmanLoss"
  end if  
end

--Letters--
property spriteNum, myLetter, showing

on showLetter me, whatLetter
  if myLetter = whatLetter then
    showing = true
    sprite(spriteNum).member = member(myLetter)
  end if
end

on checkWin me, winList
  winList.add(showing)
end

on assignLetter me, letterList
  sprite(spriteNum).member = member("dash")
  if letterList.count > 0 then
    myLetter = letterList[1]
    deleteAt(letterList, 1)
    showing = 0
    sprite(spriteNum).blend = 100
  else
    showing = 1
    myLetter = "empty"
    sprite(spriteNum).member = member("empty")
  end if
end

on beginSprite me
  sprite(spriteNum).blend = 0
end

on showLoss me
  sprite(spriteNum).member = member(myLetter)
end


--Prepare Hangman--
global gHangmanWord

on exitFrame me
  gHangmanWord = getHangmanWord()
  letterList = []
  repeat with x = 1 to gHangmanWord.char.count
    letterList.add(gHangmanWord.char[x])
  end repeat
  sendAllSprites(#assignLetter, letterList)    
end

on getHangmanWord
  pickText = member("hangmanWords").text
  howManyLines = pickText.line.count
  repeat with x = howManyLines down to 1
    if pickText.line[x] = "" then delete pickText.line[x]
  end repeat
  thisOne = random(howManyLines)
  return pickText.line[thisOne]
end

--Play again--
on mouseUp
  go "hangman"
end


--Hold on frame--
on exitFrame
  go to the frame
end

Angela123Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
MediaMacrosConnect With a Mentor Commented:
--Prepare Hangman--
global gHangmanWord

on exitFrame me
  gHangmanWord = getHangmanWord()
  showClue()
  letterList = []
  repeat with x = 1 to gHangmanWord.char.count
    letterList.add(gHangmanWord.char[x])
  end repeat
  sendAllSprites(#assignLetter, letterList)    
end

Also make sure the words in the list are the same case as the words in the text field.  "ice" and "Ice" will nt match in the list as properties are case sensitive. :)
0
 
MediaMacrosCommented:
It all depends on how you want to do the clue.  The easiest way might be to make a different color version of one each letter then on "clue" check the unused letters and swap that one letter to make it show the different version.

on the letter..

on giveClue me
  if gHangmanWord contains myLetter then
   sprite(spriteNum).member = member(myLetter & "-C")
   return 1
  end if
end

call it like this..

sendAllSprites(#giveClue)
0
 
Angela123Author Commented:
I want the clue to appear when a new word to guess appears.  I only want to have one clue for each word.
0
2018 Annual Membership Survey

Here at Experts Exchange, we strive to give members the best experience. Help us improve the site by taking this survey today! (Bonus: Be entered to win a great tech prize for participating!)

 
MediaMacrosCommented:
Like a text field?  You can make a ist to associate teh words with a clue.  Pull the item from the list and put them in the field...

on showCLue
  clueList = ["Ice" : "It's cold]
  member("clue").text = clueList[gHangmanWord]
end
0
 
Angela123Author Commented:
yes, that sounds like what I want to do. Do I put the above code on the blank text field? Do I create a new list with the clues or add them along with my word list?
I tried this out but was gettng an error message saying - variable used before assigned a value.
0
 
MediaMacrosCommented:
I would make a text field, and place it on screen.  Then make a list of words and clues so that once the word is chosen you call that handler so that it fills in the member named "clue"
0
 
Angela123Author Commented:
I still cant get this to work. I put a text box on screen where I want the clue to appear. I created a seperate list of clues and have a seperate word list. Where should I place this code:

on showCLue
  clueList = ["Ice" : "It's cold]
  member("clue").text = clueList[gHangmanWord]
end

as I think I am putting it in the wrong place.  On the above code do I write the second clue as

  clueList = ["Ice" : "It's cold, "Glacier" : "xxxx" ]
 
0
 
MediaMacrosCommented:
That can go in a movie script and yes, you add the other words to the list as well.  Then, in the hangman game when you pick a new word call this function...

showCLue()
0
 
Angela123Author Commented:
I still cant get the clue to appear in the text field. I dont know why, I have followed your advice as above. Can I just go over the points, sorry for this im probably doing something really stupid:

1.  word list:  Ice
                    Sea
2. Clue list: Its cold
                 Another name for the ocean
3. Blank text box on screen called clue
4. I could put the code  
           on showCLue
            clueList = ["Ice" : "Its cold, "Sea" : "Another name for the ocean"]
             member("clue").text = clueList[gHangmanWord]
             end
   
           in the prepare hangman script as above?
5.  showClue() goes in ??
0
 
Angela123Author Commented:
Finally got it working, I had all the code and it was the cases of the words that was causing the problems lol. Thanks so much 4 all ur help.
0
All Courses

From novice to tech pro — start learning today.