Link to home
Start Free TrialLog in
Avatar of Angela123
Angela123

asked on

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

Avatar of MediaMacros
MediaMacros

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)
Avatar of Angela123

ASKER

I want the clue to appear when a new word to guess appears.  I only want to have one clue for each word.
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
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.
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"
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" ]
 
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()
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 ??
ASKER CERTIFIED SOLUTION
Avatar of MediaMacros
MediaMacros

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.