By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,988 Members | 1,350 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,988 IT Pros & Developers. It's quick & easy.

CAN ANYONE HELP A DAMSEL IN DISTRESS??????????

P: n/a
Calling all programmers for helllllllllllllllppppp!!! i am currently
doing a uni degree and our lecturers have set us the task of making a
game in JavaScript.

i chose to do a hangman game and have completed the actual game. I
have recently been in hospital as I am disabled and so have not been in
the lessons where my lecturers have been teaching us how to create
scoring and incorporating different difficulty levels into the game.

it is now the holiday and my assignment is due in when we go back after
the spring break. i have created my game however i was wondering if you
would be able to help me and perhaps advise me how i may go about
adding scoring and levels to my game.

This would be greatly appreciated if you were able to do so. Please
email back as soon as possible, your help would make a huge difference.
From Jude

here is the main code so far:

This is the main code which is in the left frame
<html>
<head>
<title> HANGMAN GAME GUESSES </title>
<script language = "JavaScript">
var words = new Array(); // HOLDS ALL THE WORDS
var numberOfWords = 31; // TOTAL NUMBER OF WORDS (UPDATE WHEN ADDING
NEW)
// INDEX EACH WORD
words[0] = "COMPUTER";
words[1] = "MONITOR";
words[2] = "LAMINATOR";
words[3] = "SCANNER";
words[4] = "KEYBOARD";
words[5] = "PRINTER";
words[6] = "WEBCAM";
words[7] = "SPEAKERS";
words[8] = "FAX";
words[9] = "MODEM";
words[10] = "MICROPHONE";

words[11] = "FIREWORKS";
words[12] = "ILLUSTRATOR";
words[13] = "PREMIERE";
words[14] = "PHOTOSHOP";
words[15] = "SOUNDFORGE";
words[16] = "DIRECTOR";
words[17] = "DREAMWEAVER";
words[18] = "FLASH";
words[19] = "FREEHAND";
words[20] = "LIGHTWAVE";

words[21] = "JAVASCRIPT";
words[22] = "JAVA";
words[23] = "PHP";
words[24] = "HTML";
words[25] = "LINUX";
words[26] = "XHTML";
words[27] = "DHTML";
words[28] = "EIFFEL";
words[29] = "PASCAL";
words[30] = "DELPHINE";



var guessesSoFar = ""; // LETTERS GUESSED SO FAR
var misses = 0; // WRONG GUESSES SO FAR (SIX WILL HANG THE MAN)
var theWord = ""; // THE WORD THE PLAYER IS TRYING TO GUESS
var wordLength = 0; // THE LENGTH OF THE WORD
var newGame = "False"; // TRUE IF THE PLAYER HAS PRESSED THE NEW GAME
BUTTON
var guessedWord = ""; // USED WHEN PLAYER TRIES TO GUESS THE WHOLE WORD
AT ONCE

var letters = new Array(); // HOLDS EACH LETTER OF THE WORD
var status = new Array(); // EACH LETTER IS EITHER UNKNOWN OR FOUND

// RAND CREATES A RANDOM NUMBER FROM ZERO TO (N - 1)
function rand(n) {
var now = new Date();
var seed = now.getTime() % 0xffffffff;
seed = (0x015a435 * seed) % 0x7fffffff;
return (seed >> 16) % n;
}

// PICKWORD PICKS A WORD, AT RANDOM, FROM THE LIST OF WORDS
// PICKWORD ALSO RESETS THE GAME, I.E. SETTING THE STATUS OF ALL
LETTERS TO UNKNOWN
function pickWord () {
newGame = "True";
theWord = words[rand(numberOfWords)];
wordLength = theWord.length;
misses = 0;
guessesSoFar = "";
for (var i = 0; i < wordLength; i++) {
letters[i] = theWord.charAt(i);
status[i] = "unknown";
}
parent.right1.document.theMan.src="gallows.gif";
printWord();
}

// PRINTS THE WORD TO THE TOP FRAME (HIDING ANY LETTERS THAT HAVE NOT
BEEN GUESSED)
function printWord() {
guessedWord = "";
parent.top1.document.write("<html><head></head><body><center><h1><font
face=Verdana color='#666666'>");
for (i = 0; i < wordLength; i++) {
if (status[i] == "unknown") {
parent.top1.document.write("_ ")
} else {
guessedWord = guessedWord + letters[i];
parent.top1.document.write(letters[i] + " ")
}
}
parent.top1.document.write("</h1></p>");
parent.top1.document.write("<b><h2><font face=Verdana
color='#666666'>Guesses so far: " + guessesSoFar + "</FONT><p>");
parent.top1.document.write("<font face=Verdana color='#666666'>Misses
so far: " + misses + "</h2></FONT><b>");
if (guessedWord == theWord) {
parent.top1.document.write("<p><h1><font face=Verdana
color='#666666'>YOU WIN!!!</FONT></h1>");
parent.right1.document.theMan.src="EXCELLENT.gif";
newGame = "False"
}
if (misses > 5) { parent.top1.document.write("<p><h1><font
face='Verdana'color='#666666'>YOU LOSE!!!</FONT></h1>") }
parent.top1.document.write("</center></body></html>");
parent.top1.document.close();
}

// WHEN THE PLAYER CLICKS ON A LETTER BUTTON, THIS FUNCTION IS RUN.
// IT CHECKS THE PLAYER'S CHOICE AGAINST THE LIST OF ALL LETTERS IN
// THE WORD. IF THE GUESS IS WRONG, THE HANGMAN IMAGE MUST BE CHANGED.
function guessLetter(guess) {
if (newGame == "False") {
alert("Click NEW GAME to start playing!");
} else {
var gotOne = "False";
for (var i = 0; i < wordLength; i++) {
if (letters[i] == guess) {
status[i] = "found";
gotOne = "True";
}
}
guessesSoFar = guessesSoFar + guess + " ";
if (gotOne == "False") {
misses = misses + 1
if (misses == 1) { parent.right1.document.theMan.src="head.gif" }
if (misses == 2) { parent.right1.document.theMan.src="body.gif" }
if (misses == 3) { parent.right1.document.theMan.src="leftarm.gif" }
if (misses == 4) { parent.right1.document.theMan.src="rightarm.gif"
}
if (misses == 5) { parent.right1.document.theMan.src="leftleg.gif" }
if (misses > 5) {
parent.right1.document.theMan.src="hanged.gif";
newGame = "False"
}
}
printWord();
}
}

// IF THE PLAYER TRIES TO GUESS THE WHOLE WORD, THIS FUNCTION TESTS THE
GUESS AGAINST
// THE ACTUAL WORD.
function guessWord (){
theGuess = document.guesses.wholeWord.value;
theGuess = theGuess.toUpperCase();
if (theGuess == theWord) {
parent.top1.document.write("<html><head></head><body><center><h1><font
face=Verdana color='#666666'>");
parent.top1.document.write("<b><h2>Guesses so far: " + guessesSoFar +
"<p>");
parent.top1.document.write("Misses so far: " + misses + "</h2><b>");
parent.top1.document.write("<p><h1>YOU WIN!!!</h1>");
parent.right1.document.theMan.src="EXCELLENT.gif"
parent.top1.document.write("</center></body></html>");
parent.top1.document.close();
newGame = "False"
} else {
alert("You have guessed incorrectly. Please try again! It is your
duty to save Mr Incredible!");
}
}
</script>

</head>
<body bgcolor = "CC6699" link = "black" vlink = "black" alink =
"black">
<b><font face="Verdana" color="#FFCCFF">Click a letter to guess it. To
guess a whole word, type it in the box provided, then click
OK.</font>
<form name = "guesses">
<center>
<input type = button value = "NEW GAME" onclick = "pickWord()"><p>
<input type = button value = " A " onclick = "guessLetter('A')">
<input type = button value = " B " onclick = "guessLetter('B')">
<input type = button value = " C " onclick = "guessLetter('C')">
<input type = button value = " D " onclick = "guessLetter('D')">
<input type = button value = " E " onclick = "guessLetter('E')">
<input type = button value = " F " onclick = "guessLetter('F')">
<input type = button value = " G " onclick = "guessLetter('G')">
<input type = button value = " H " onclick = "guessLetter('H')">
<input type = button value = " I " onclick = "guessLetter('I')">
<input type = button value = " J " onclick = "guessLetter('J')">
<input type = button value = " K " onclick = "guessLetter('K')">
<input type = button value = " L " onclick = "guessLetter('L')">
<input type = button value = " M " onclick = "guessLetter('M')">
<input type = button value = " N " onclick = "guessLetter('N')">
<input type = button value = " O " onclick = "guessLetter('O')">
<input type = button value = " P " onclick = "guessLetter('P')">
<input type = button value = " Q " onclick = "guessLetter('Q')">
<input type = button value = " R " onclick = "guessLetter('R')">
<input type = button value = " S " onclick = "guessLetter('S')">
<input type = button value = " T " onclick = "guessLetter('T')">
<input type = button value = " U " onclick = "guessLetter('U')">
<input type = button value = " V " onclick = "guessLetter('V')">
<input type = button value = " W " onclick = "guessLetter('W')">
<input type = button value = " X " onclick = "guessLetter('X')">
<input type = button value = " Y " onclick = "guessLetter('Y')">
<input type = button value = " Z " onclick = "guessLetter('Z')">
<p>
<font color="#FFCCFF" face="Verdana">
Whole Word </font> <input type = text name = "wholeWord">
<input type = button value = " OK " onclick = "guessWord()">
<input type = button value = "I GIVE UP" onclick =
"javascript:alert('The word is ' + theWord + '.')"><p>
<img src = "head.gif" width = 1 height = 1>
<img src = "body.gif" width = 1 height = 1>
<img src = "leftarm.gif" width = 1 height = 1>
<img src = "rightarm.gif" width = 1 height = 1>
<img src = "leftleg.gif" width = 1 height = 1>
<img src = "hanged.gif" width = 1 height = 1>
<img src = "EXCELLENT.gif" width = 1 height = 1>
<center>
</form>
</body>
</html>

Jul 23 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a

ra********@hotmail.com wrote:
I have recently been in hospital as I am disabled and so have not been in the lessons where my lecturers have been teaching us how to create
scoring and incorporating different difficulty levels into the game.


Talk to your lecturers, they would certainly give you an extension on
the due date of your assignment when you tell them that you have been
in hospital.

Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.