Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 6th, 2005, 8:35 PM   #1
rainbowii7
Newbie
 
Join Date: Apr 2005
Posts: 1
Rep Power: 0 rainbowii7 is on a distinguished road
Red face can anyone help a damsel in distress????

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>


Last edited by big_k105; Apr 8th, 2005 at 10:20 AM.
rainbowii7 is offline   Reply With Quote
Old Apr 7th, 2005, 3:05 PM   #2
Cerulean
Professional Programmer
 
Cerulean's Avatar
 
Join Date: Apr 2005
Location: London, England
Posts: 459
Rep Power: 4 Cerulean is on a distinguished road
Quite a beast. Consider wrapping your code in [ code ] tags (sans the space).
As for scoring/levels, just keep track of these levels in cookies or the like. For scoring (keeping track of data persistently) you can communicate with a server-side script via XmlHTTPRequest.
Good luck

Last edited by Cerulean; Apr 7th, 2005 at 3:11 PM.
Cerulean is offline   Reply With Quote
Old Apr 8th, 2005, 2:39 AM   #3
Berto
Programming Guru
 
Join Date: Aug 2004
Posts: 1,022
Rep Power: 5 Berto is on a distinguished road
Send a message via AIM to Berto Send a message via MSN to Berto
ug javascript nasty language.
Berto is offline   Reply With Quote
Old Apr 8th, 2005, 7:30 AM   #4
Cerulean
Professional Programmer
 
Cerulean's Avatar
 
Join Date: Apr 2005
Location: London, England
Posts: 459
Rep Power: 4 Cerulean is on a distinguished road
Berto, at least be constructive or humourous if you're going to post anything.
Cerulean is offline   Reply With Quote
Old Apr 8th, 2005, 7:31 PM   #5
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 8 Ooble is on a distinguished road
It's alright - Bertie's a special case.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Apr 9th, 2005, 4:35 AM   #6
Cerulean
Professional Programmer
 
Cerulean's Avatar
 
Join Date: Apr 2005
Location: London, England
Posts: 459
Rep Power: 4 Cerulean is on a distinguished road
Hrm ok
Cerulean is offline   Reply With Quote
Old Apr 9th, 2005, 8:14 AM   #7
tempest
Programming Guru
 
tempest's Avatar
 
Join Date: Oct 2004
Posts: 1,041
Rep Power: 5 tempest is on a distinguished road
Send a message via ICQ to tempest Send a message via AIM to tempest Send a message via Yahoo to tempest
It all depends on how you want to score it and such...
__________________

tempest is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:47 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC