Solved

Hangman Game

Posted on 2004-09-01
10
387 Views
Last Modified: 2013-12-24
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

0
Comment
Question by:Angela123
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
10 Comments
 
LVL 20

Expert Comment

by:MediaMacros
ID: 11951630
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
 

Author Comment

by:Angela123
ID: 11952490
I want the clue to appear when a new word to guess appears.  I only want to have one clue for each word.
0
 
LVL 20

Expert Comment

by:MediaMacros
ID: 11952560
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
WordPress Tutorial 1: Installation & Setup

WordPress is a very popular option for running your web site and can be used to get your content online quickly for the world to see. This guide will walk you through installing the WordPress server software and the initial setup process.

 

Author Comment

by:Angela123
ID: 11953568
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
 
LVL 20

Expert Comment

by:MediaMacros
ID: 11953787
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
 

Author Comment

by:Angela123
ID: 11962518
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
 
LVL 20

Expert Comment

by:MediaMacros
ID: 11962597
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
 

Author Comment

by:Angela123
ID: 11963830
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
 
LVL 20

Accepted Solution

by:
MediaMacros earned 125 total points
ID: 11963956
--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
 

Author Comment

by:Angela123
ID: 11964610
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

Featured Post

 Database Backup and Recovery Best Practices

Join Percona’s, Architect, Manjot Singh as he presents Database Backup and Recovery Best Practices (with a Focus on MySQL) on Thursday, July 27, 2017 at 11:00 am PDT / 2:00 pm EDT (UTC-7). In the case of a failure, do you know how long it will take to restore your database?

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Turn A Profile Picture Into A Cartoon Using Photoshop And Illustrator This tutorial will teach you how to make a cartoon style image out of a regular picture. I have tried to keep the tutorial as simple as possible. I used Adobe CS4 for this tuto…
Objective of This Article In 1990’s, when I was a budding software professional, I had a lot of confusion about which stream or technology, I had to choose to build my career. In those days, I had lot of confusion like whether to choose System so…
The purpose of this video is to demonstrate how to create a Printer Friendly PDF on a WordPress Page. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome Screenshot” Google Chrome Extension, and SmallPDF.com Log…
The purpose of this video is to demonstrate how to reset a WordPress password if you are locked out and cannot reset the password. A typical use would be if you cannot access the email to which WordPress would send the password recovery email to…

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question