PDA

View Full Version : 2 Problems In Hangman Game


WamRaven
02-23-2004, 08:07 AM
Trying to get these 2 things to happen...

-- The number of guesses remaining is indicated in a status box (10 total)

-- When a blank letter is clicked on, no hangman parts appear (when you click on a letter, the IMG of the letter disappears to a black spot, but you can still click the black spot (as it is an IMG too)

you won't be able run the program yourself as it includes many images.. but any help would be greatly appreciated


<html>
<head>
<title>Hangman</title>
<font face="Times New Roman">

<script language="javascript">

function randomnumber(lowest,highest) {
numget = 0
while ((numget < lowest) || (numget > highest) || isNaN(numget)) {
now = new Date()
numget = Math.abs(Math.sin(now.getTime()))
numget = parseInt(numget * (highest))
}
return numget
}


var wordList=new Array("PUCK","STICK","ICE","CANADA","SHOOT","OFFSIDE")

var wordChoice=randomnumber(1,7)
var word=wordList[wordChoice-1]
var numberofletters=0
var numLett=0
var misses=0

var drawman=new Array("head.jpg","body.jpg","right-arm.jpg","left-arm.jpg","right-leg.jpg","left-leg.jpg","right-hand.jpg","left-hand.jpg","right-foot.jpg","complete.jpg")
function hangHim(){

if (misses<10){
document.images[0].src=drawman[misses]
}
misses=misses+1
/* switch(misses){
case 1: document.images[0].src="head.jpg"
case 2: document.images[0].src="body.jpg"
case 3: document.images[0].src="right-arm.jpg"
case 4: document.images[0].src="left-arm.jpg"
case 5: document.images[0].src="right-leg.jpg"
case 6: document.images[0].src="left-leg.jpg"
case 7: document.images[0].src="right-hand.jpg"
case 8: document.images[0].src="left-hand.jpg"
case 9: document.images[0].src="right-foot.jpg"
case 10:document.images[0].src="complete.jpg" */

if (misses==10){
window.open('lose.html', 'lose', 'width=225,height=120', 'location=no', 'menubar=no', 'status=no', 'toolbar=no', 'scrollbars=no', 'resizable=no')
}

}

var numLett=0
function testLetter(lett){
var spot
var found=0
var graphic
var ii


for (ii=0; ii<word.length; ii++){
if (word.charAt(ii)==lett){
spot=document.images.length-word.length+ii
document.images[spot].src=word.charAt(ii)+".gif"
numLett++
found=1
}
}
if (found==0)
hangHim()

if (numLett == numberofletters){
window.open('correct.html', 'correct', 'width=225,height=120', 'location=no', 'menubar=no', 'status=no', 'toolbar=no', 'scrollbars=no', 'resizable=no')
}
}

</script>
</head>


<body bgcolor="black" onLoad="document.guessBox.reset()">
<center><h1><font color="red"><b><u>HOCKEY HANGMAN</b></u></font></h1></center>
<center><h2>Level: Easy</h2></center>

<TABLE border=0><TR>
<TD rowspan=2 ALIGN="center">
<img src="start.jpg" name="hangman" width=200>
</TD>

<TD ALIGN="center" VALIGN="center">

<a href="#" onClick="A.src='blank.jpg'; testLetter('A')"> <img src="A.gif" name="A" border=0></a>
<a href="#" onClick="B.src='blank.jpg'; testLetter('B')"> <img src="B.gif" name="B" border=0></a>
<a href="#" onClick="C.src='blank.jpg'; testLetter('C')"> <img src="C.gif" name="C" border=0></a>
<a href="#" onClick="D.src='blank.jpg'; testLetter('D')"> <img src="D.gif" name="D" border=0></a>
<a href="#" onClick="E.src='blank.jpg'; testLetter('E')"> <img src="E.gif" name="E" border=0></a>
<a href="#" onClick="F.src='blank.jpg'; testLetter('F')"> <img src="F.gif" name="F" border=0></a>
<a href="#" onClick="G.src='blank.jpg'; testLetter('G')"> <img src="G.gif" name="G" border=0></a>
<a href="#" onClick="H.src='blank.jpg'; testLetter('H')"> <img src="H.gif" name="H" border=0></a>
<a href="#" onClick="I.src='blank.jpg'; testLetter('I')"> <img src="I.gif" name="I" border=0></a>
<a href="#" onClick="J.src='blank.jpg'; testLetter('J')"> <img src="J.gif" name="J" border=0></a>
<a href="#" onClick="K.src='blank.jpg'; testLetter('K')"> <img src="K.gif" name="K" border=0></a>
<a href="#" onClick="L.src='blank.jpg'; testLetter('L')"> <img src="L.gif" name="L" border=0></a>
<a href="#" onClick="M.src='blank.jpg'; testLetter('M')"> <img src="M.gif" name="M" border=0></a>
<a href="#" onClick="N.src='blank.jpg'; testLetter('N')"> <img src="N.gif" name="N" border=0></a>
<a href="#" onClick="O.src='blank.jpg'; testLetter('O')"> <img src="O.gif" name="O" border=0></a>
<a href="#" onClick="P.src='blank.jpg'; testLetter('P')"> <img src="P.gif" name="P" border=0></a>
<a href="#" onClick="Q.src='blank.jpg'; testLetter('Q')"> <img src="Q.gif" name="Q" border=0></a>
<a href="#" onClick="R.src='blank.jpg'; testLetter('R')"> <img src="R.gif" name="R" border=0></a>
<a href="#" onClick="S.src='blank.jpg'; testLetter('S')"> <img src="S.gif" name="S" border=0></a>
<a href="#" onClick="T.src='blank.jpg'; testLetter('T')"> <img src="T.gif" name="T" border=0></a>
<a href="#" onClick="U.src='blank.jpg'; testLetter('U')"> <img src="U.gif" name="U" border=0></a>
<a href="#" onClick="V.src='blank.jpg'; testLetter('V')"> <img src="V.gif" name="V" border=0></a>
<a href="#" onClick="W.src='blank.jpg'; testLetter('W')"> <img src="W.gif" name="W" border=0></a>
<a href="#" onClick="X.src='blank.jpg'; testLetter('X')"> <img src="X.gif" name="X" border=0></a>
<a href="#" onClick="Y.src='blank.jpg'; testLetter('Y')"> <img src="Y.gif" name="Y" border=0></a>
<a href="#" onClick="Z.src='blank.jpg'; testLetter('Z')"> <img src="Z.gif" name="Z" border=0></a>

</TD></TR>
<TR><TD width=50% align="center">

<script language="javascript">

for (var count = 0 ; count < word.length ; count++){
if (word.charAt (count) == " "){
document.write ("<img src='blank.JPG'>")
count++
}
if (word.charAt (count) == "-"){
document.write ("<img src='dash.gif'>")
}
else{
document.write ("<img src='space.gif'>")
numberofletters++
}
}

</script>

<!-- FIX THIS ... GUESS BOX ... NOT WORKING !-->

<b>

<form name="guessBox">
<font face="Times New Roman" color=blue size="3">
GUESS: <input type="text" name="guess" size=25>

<input type="button" name="check" value="AM I RIGHT?" onClick="if (document.guessBox.guess.value.toUpperCase()==word||
document.guessBox.guess.value==word){

window.open('correct.html', 'correct', 'width=225,height=120', 'location=no', 'menubar=no', 'status=no', 'toolbar=no', 'scrollbars=no', 'resizable=no')

}
else{
window.open('wrong.html', 'correct', 'width=280,height=120', 'location=no', 'menubar=no', 'status=no', 'toolbar=no', 'scrollbars=no', 'resizable=no'); hangHim();}">



</FORM>
</form>

<form name="refreshbutton">
<input type="button" name="refresh" size="15" value="REFRESH" onClick="window.location.reload()">
</form>

<form>
<input type="button" value="Close" onClick="window.close()">
</form>

</TD></TR>
</TABLE>
</body>
</html>

ucm
02-25-2004, 04:26 AM
on the first problem, at the VERY END of the hangHim() function, put:
document.guessBox.guess.value=(10-misses).toString();

on the second prob, change:
testLetter('A')">
to:
testLetter('A',this.src)">
and the ***ntion's top part to:
function testLetter(lett,lettObj){
if(lettObj.src != "blank.jpg"){
...your code here...
...your code here...
...your code here...
...your code here...
...your code here...
...your code here...
...your code here...
...your code here...
...your code here...
}//the if
}//the function


you should reply to this thread with a link to this game when you upload it to your site ;)

WamRaven
02-25-2004, 09:25 AM
tyvm for your help, the first solution worked perfectly.. the second problem is still not working.. not sure if I'm putting in the code you gave me right.. I knew this part would give me the most problems

ucm
02-25-2004, 08:33 PM
post what you've got now where only the sencond issue isn't working and i'll take another crack at it ;)

WamRaven
02-26-2004, 09:41 AM
<html>
<head>
<title>Hangman</title>
<font face="Times New Roman">

<script language="javascript">

function randomnumber(lowest,highest) {
numget = 0
while ((numget < lowest) || (numget > highest) || isNaN(numget)) {
now = new Date()
numget = Math.abs(Math.sin(now.getTime()))
numget = parseInt(numget * (highest))
}
return numget
}


var wordList=new Array("PUCK","STICK","ICE","CANADA","SHOOT","OFFSIDE")

var wordChoice=randomnumber(1,7)
var word=wordList[wordChoice-1]
var numberofletters=0
var numLett=0
var misses=0

var drawman=new Array("head.jpg","body.jpg","right-arm.jpg","left-arm.jpg","right-leg.jpg","left-leg.jpg","right-hand.jpg","left-hand.jpg","right-foot.jpg","complete.jpg")
function hangHim(){document.guessBox.guess.value=(9-misses).toString();

if (misses<10){
document.images[0].src=drawman[misses]
}
misses=misses+1
/* switch(misses){
case 1: document.images[0].src="head.jpg"
case 2: document.images[0].src="body.jpg"
case 3: document.images[0].src="right-arm.jpg"
case 4: document.images[0].src="left-arm.jpg"
case 5: document.images[0].src="right-leg.jpg"
case 6: document.images[0].src="left-leg.jpg"
case 7: document.images[0].src="right-hand.jpg"
case 8: document.images[0].src="left-hand.jpg"
case 9: document.images[0].src="right-foot.jpg"
case 10:document.images[0].src="complete.jpg" */

if (misses==10){
window.open('lose.html', 'lose', 'width=225,height=120', 'location=no', 'menubar=no', 'status=no', 'toolbar=no', 'scrollbars=no', 'resizable=no')
}

}

var numLett=0
function testLetter(lett){
var spot
var found=0
var graphic
var ii


for (ii=0; ii<word.length; ii++){
if (word.charAt(ii)==lett){
spot=document.images.length-word.length+ii
document.images[spot].src=word.charAt(ii)+".gif"
numLett++
found=1
}
}
if (found==0)
hangHim()

if (numLett == numberofletters){
window.open('correct.html', 'correct', 'width=225,height=120', 'location=no', 'menubar=no', 'status=no', 'toolbar=no', 'scrollbars=no', 'resizable=no')
}
}

</script>
</head>


<body bgcolor="black" onLoad="document.guessBox.reset()">
<center><h1><font color="red"><b><u>HOCKEY HANGMAN</b></u></font></h1></center>
<center><h2>Level: Easy</h2></center>

<TABLE border=0><TR>
<TD rowspan=2 ALIGN="center">
<img src="start.jpg" name="hangman" width=200>
</TD>

<TD ALIGN="center" VALIGN="center">

<a href="#" onClick="A.src='blank.jpg'; testLetter('A')"> <img src="A.gif" name="A" border=0></a>
<a href="#" onClick="B.src='blank.jpg'; testLetter('B')"> <img src="B.gif" name="B" border=0></a>
<a href="#" onClick="C.src='blank.jpg'; testLetter('C')"> <img src="C.gif" name="C" border=0></a>
<a href="#" onClick="D.src='blank.jpg'; testLetter('D')"> <img src="D.gif" name="D" border=0></a>
<a href="#" onClick="E.src='blank.jpg'; testLetter('E')"> <img src="E.gif" name="E" border=0></a>
<a href="#" onClick="F.src='blank.jpg'; testLetter('F')"> <img src="F.gif" name="F" border=0></a>
<a href="#" onClick="G.src='blank.jpg'; testLetter('G')"> <img src="G.gif" name="G" border=0></a>
<a href="#" onClick="H.src='blank.jpg'; testLetter('H')"> <img src="H.gif" name="H" border=0></a>
<a href="#" onClick="I.src='blank.jpg'; testLetter('I')"> <img src="I.gif" name="I" border=0></a>
<a href="#" onClick="J.src='blank.jpg'; testLetter('J')"> <img src="J.gif" name="J" border=0></a>
<a href="#" onClick="K.src='blank.jpg'; testLetter('K')"> <img src="K.gif" name="K" border=0></a>
<a href="#" onClick="L.src='blank.jpg'; testLetter('L')"> <img src="L.gif" name="L" border=0></a>
<a href="#" onClick="M.src='blank.jpg'; testLetter('M')"> <img src="M.gif" name="M" border=0></a>
<a href="#" onClick="N.src='blank.jpg'; testLetter('N')"> <img src="N.gif" name="N" border=0></a>
<a href="#" onClick="O.src='blank.jpg'; testLetter('O')"> <img src="O.gif" name="O" border=0></a>
<a href="#" onClick="P.src='blank.jpg'; testLetter('P')"> <img src="P.gif" name="P" border=0></a>
<a href="#" onClick="Q.src='blank.jpg'; testLetter('Q')"> <img src="Q.gif" name="Q" border=0></a>
<a href="#" onClick="R.src='blank.jpg'; testLetter('R')"> <img src="R.gif" name="R" border=0></a>
<a href="#" onClick="S.src='blank.jpg'; testLetter('S')"> <img src="S.gif" name="S" border=0></a>
<a href="#" onClick="T.src='blank.jpg'; testLetter('T')"> <img src="T.gif" name="T" border=0></a>
<a href="#" onClick="U.src='blank.jpg'; testLetter('U')"> <img src="U.gif" name="U" border=0></a>
<a href="#" onClick="V.src='blank.jpg'; testLetter('V')"> <img src="V.gif" name="V" border=0></a>
<a href="#" onClick="W.src='blank.jpg'; testLetter('W')"> <img src="W.gif" name="W" border=0></a>
<a href="#" onClick="X.src='blank.jpg'; testLetter('X')"> <img src="X.gif" name="X" border=0></a>
<a href="#" onClick="Y.src='blank.jpg'; testLetter('Y')"> <img src="Y.gif" name="Y" border=0></a>
<a href="#" onClick="Z.src='blank.jpg'; testLetter('Z')"> <img src="Z.gif" name="Z" border=0></a>

</TD></TR>
<TR><TD width=50% align="center">

<script language="javascript">

for (var count = 0 ; count < word.length ; count++){
if (word.charAt (count) == " "){
document.write ("<img src='blank.JPG'>")
count++
}
if (word.charAt (count) == "-"){
document.write ("<img src='dash.gif'>")
}
else{
document.write ("<img src='space.gif'>")
numberofletters++
}
}

</script>

<!-- FIX THIS ... GUESS BOX ... NOT WORKING !-->

<b>

<form name="guessBox">
<font face="Times New Roman" color=blue size="3">
GUESS: <input type="text" name="guess" size=25>


<input type="button" name="check" value="AM I RIGHT?" onClick="if (document.guessBox.guess.value.toUpperCase()==word||
document.guessBox.guess.value==word){

window.open('correct.html', 'correct', 'width=225,height=120', 'location=no', 'menubar=no', 'status=no', 'toolbar=no', 'scrollbars=no', 'resizable=no')

}
else{
window.open('wrong.html', 'correct', 'width=280,height=120', 'location=no', 'menubar=no', 'status=no', 'toolbar=no', 'scrollbars=no', 'resizable=no'); hangHim();}">



</FORM>
</form>

<form name="refreshbutton">
<input type="button" name="refresh" size="15" value="REFRESH" onClick="window.location.reload()">
</form>

<form>
<input type="button" value="Close" onClick="window.close()">
</form>

</TD></TR>
</TABLE>
</body>
</html>

WamRaven
02-26-2004, 09:47 AM
I have just put up a working copy for you to see my blank letter problem in action.. click a letter, if it is wrong, click the blank spot left by it and it still registers

http://aa.1asphost.com/FWHL2/hangmaneasy.html

Willy Duitt
02-26-2004, 12:26 PM
Cannot find server or DNS Error

agent002
02-26-2004, 12:30 PM
Originally posted by Willy Duitt
Cannot find server or DNS Error
I can :confused:

Willy Duitt
02-26-2004, 01:08 PM
Hmmm;

I just tried it again and still get an error.
Maybe you can't get there from here.... =:O

.....Willy

ucm
02-28-2004, 02:46 AM
Originally posted by Willy Duitt
Hmmm;

I just tried it again and still get an error.
Maybe you can't get there from here.... =:O

.....Willy

same here, i tried opera 7, mozilla 1.5 and ie6 :(

WamRaven
03-01-2004, 08:01 AM
hmm guess no one can solve it.. if the page doesn't work a zipped package of the game, pics, everything is available here

http://www.angelfire.com/on4/fwhlfiles/Hangman.zip

I had some other problems I needed help with too.. but didn't want to ask a lot of you guys.. but here is one..

-----------------------------
A clue is given when only three guesses are left.