[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 282
  • Last Modified:

Hangman w. umlauts

I have picked up Rick Glusic's fun Hangman script but i'm having difficulties getting it to work like i want.
First i would like to add the Swedish umlauts: ÅÄÖ, if this is possible.
Secondly i would like to add a small gif for every wrong guess, overwriting the previous one. You know: hang1.gif, hang2.gif etc..
Third i want the script to show a "You lost"-message after 14 wrong guesses.
Fourth, any other small, fun javascript games like this one would be gratefully recieved.

<HTML>
<HEAD><TITLE>Hängsnaran</TITLE></HEAD>
<BODY>


<center>
<table border=8 bgcolor=white width=60% cellspacing=0>
<tr><td>
<center>
<h2>Hängsnaran!</h2><br>
<b><h3><font color=red>Ämnet:</font>  
IFK:s främsta a-landslagsmän genom tiderna<BR>samt a-truppen 1998</h3></b>
<hr><br>

<SCRIPT LANGUAGE="JavaScript">

<!-- Original:  Rick Glusick -->

<!-- This script and many more are available online from -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
function getCookie (name) {
var dcookie = document.cookie;
var cname = name + "=";
var clen = dcookie.length;
var cbegin = 0;
while (cbegin < clen) {
var vbegin = cbegin + cname.length;
if (dcookie.substring(cbegin, vbegin) == cname) {
var vend = dcookie.indexOf (";", vbegin);
if (vend == -1) vend = clen;
return unescape(dcookie.substring(vbegin, vend));
}
cbegin = dcookie.indexOf(" ", cbegin) + 1;
if (cbegin == 0) break;
}
return null;
}
function setCookie (name, value, expires) {
if (!expires) expires = new Date();
document.cookie = name + "=" + escape (value) + "; expires=" + expires.toGMTString() +  "; path=/";
}
function delCookie (name) {
var expireNow = new Date();
document.cookie = name + "=" + "; expires=Thu, 01-Jan-70 00:00:01 GMT" +  "; path=/";
}
var Alphabet = new initAlphaArray()
var NumOfWords = 42;
var SaveData = "";
var ImageNum = "";
var LettersSelected = "";
var RandomWord = "";
var DisplayWord = "";
var position = 0;
var word = new WordList();
var expdate = new Date();
var RandomNumber = (expdate.getSeconds())%NumOfWords;
function initAlphaArray() {
this.length = 26
this[0] = "A"
this[1] = "B"
this[2] = "C"
this[3] = "D"
this[4] = "E"
this[5] = "F"
this[6] = "G"
this[7] = "H"
this[8] = "I"
this[9] = "J"
this[10] = "K"
this[11] = "L"
this[12] = "M"
this[13] = "N"
this[14] = "O"
this[15] = "P"
this[16] = "Q"
this[17] = "R"
this[18] = "S"
this[19] = "T"
this[20] = "U"
this[21] = "V"
this[22] = "W"
this[23] = "X"
this[24] = "Y"
this[25] = "Z"

}
function WordList() {
this.length = NumOfWords;
this[0] = "THOMAS RAVELLI";
this[1] = "STIG FREDRIKSSON";
this[2] = "STEFAN REHN";
this[3] = "GUNNAR GREN";
this[4] = "GLENN HYSEN";
this[5] = "ARNE NYBERG";
this[6] = "ERNST ANDERSSON";
this[7] = "BENGT BERNDTSSON";
this[8] = "VALDUS LUND";
this[9] = "TORD HOLMGREN";
this[10] = "TOMMY HOLMGREN";
this[11] = "ANDERS RYDBERG";
this[12] = "MIKAEL NILSSON";
this[13] = "HERBERT CARLSSON";
this[14] = "ERIC HJELM";
this[15] = "HENNING SVENSSON";
this[16] = "JESPER BLOMQVIST";
this[17] = "PETER LARSSON";
this[18] = "FILIP JOHANSSON";
this[19] = "OWE OHLSSON";
this[20] = "ANDREAS ANDERSSON";
this[21] = "FRITZ BERG";
this[22] = "MAGNUS ERLINGMARK";
this[23] = "DICK LAST";
this[24] = "MAGNUS PEHRSSON";
this[25] = "PETER ERIKSSON";
this[26] = "JOAKIM PERSSON";
this[27] = "JANNE SAARINEN";
this[28] = "JIMMY SVENSSON";
this[29] = "MIKAEL MARTINSSON";
this[30] = "STEFAN PETTERSSON";
this[31] = "ROBERT ANDERSSON";
this[32] = "EMMANUEL TETTEH";
this[33] = "PATRIC ANDERSSON";
this[34] = "ANDREAS HERMANSSON";
this[35] = "ALEXANDER PETRAS";
this[36] = "STEFAN LANDBERG";
this[37] = "SEBASTIAN HENRIKSSON";
this[38] = "MIKAEL NILSSON";
this[39] = "TEDDY LUCIC";
this[40] = "OLOF MAGNUSSON";
this[41] = "JONAS OLSSON";
}
function availableLetters(i) {
if (LettersSelected.charAt(i)==Alphabet[i])
document.write('<TD ALIGN=CENTER VALIGN=CENTER WIDTH=20 HEIGHT=12>' +
'<B><A HREF="javascript:LoadNextPage('+i+',\''+Alphabet[i]+
'\')">'+Alphabet[i]+'</A></B></TD>');
else
document.write('<TD ALIGN=CENTER VALIGN=CENTER WIDTH=20 HEIGHT=12> </TD>');
}
function LoadNextPage(selected,letter) {
var j=0;
var HoldLettersSelected = LettersSelected;
LettersSelected = "";
if (selected == 0) {
for (j=1; j<=25; j++) {
LettersSelected += HoldLettersSelected.charAt(j);
}
LettersSelected = "^" + LettersSelected;
}
else if (selected == 25) {
for (j=0; j<=24; j++) {
LettersSelected += HoldLettersSelected.charAt(j);
}
LettersSelected += "^";
}
else {
for (j=0; j<selected; j++)
{
LettersSelected += HoldLettersSelected.charAt(j);
}
LettersSelected += "^";
for (j=selected+1; j<=25; j++) {
LettersSelected += HoldLettersSelected.charAt(j);
   }
}


SaveData = ImageNum + LettersSelected + RandomWord + "*";
setCookie("_HangMan2", SaveData, expdate);
history.go(0);
}

// Sets a cookie that will expire in 10 days

expdate.setTime (expdate.getTime() + (1000*60*60*24*10));
if(getCookie("_HangMan2") == null)
{
ImageNum = "A";
LettersSelected = "ABCDEFGHIJKLMNOPQRSTUVWXYZ;";
RandomWord = word[RandomNumber];
SaveData = ImageNum + LettersSelected + RandomWord + "*";
setCookie("_HangMan2", SaveData, expdate);
}
else {
SaveData = getCookie("_HangMan2");
ImageNum = SaveData.charAt(0);
for (position=1; position<=26; position++) {
LettersSelected += SaveData.charAt(position);
}
for (position=27; position<SaveData.indexOf("*"); position++) {
RandomWord += SaveData.charAt(position);
   }
}
DisplayWord = "";
for (i=0; i<RandomWord.length; i++) {
if (RandomWord.charAt(i) == ' ') {
DisplayWord += " ";
}
else {
MatchFound = false;
for (j=0; j<=25; j++) {
if ((LettersSelected.charAt(j) == "^") && (RandomWord.charAt(i) == Alphabet[j])) {
DisplayWord += RandomWord.charAt(i);
MatchFound = true;
   }
}
if (!MatchFound) DisplayWord += "-";
   }
}
if (ImageNum == "J") {
document.write('<font color=red size=4>Du f&ouml;rlorade!<br>Svar:  "' + RandomWord + '"</font>');
}
else if (RandomWord == DisplayWord) {
document.write('<font color=red size=8>Du vann!</font>');
}
else {
document.write('<table>');
document.write('<tr>');
for (i=0; i<13; i++) availableLetters(i);
document.write('</tr>');
document.write('<tr>');
for (i=13; i<26; i++) availableLetters(i);
document.write('</tr>');
document.write('</table>');
}
document.write('<br>');
document.write('<br>');
document.write('<font size=9><tt>');
document.write(DisplayWord);
document.write('</tt></font>');
document.write('<form>');
document.write('<input type="button" VALUE="Spela igen"'+
'onClick="delCookie(\'_HangMan2\');history.go(0);">');
document.write('</form>');
document.write('</center>');
// End -->
</SCRIPT>
</CENTER></td></tr>
</table>
</center>

<!-- Script Size:  6.31 KB  -->
<DIV ALIGN="CENTER"><FONT FACE="Arial, Helvetica, sans-serif"><B><!-- Script Size:  6.31 KB  -->
  Prova också ämnena <A HREF="hangman.html">Amerikanska Presidenter</A>
  och <A HREF="hangman3.html">Bilmärken</A> </B></FONT> </DIV>
</BODY>
</HTML>

Preferrably i would like a runnable script rather than getting instructions how to do it.

Best,
Fischier
0
fischier
Asked:
fischier
  • 16
  • 13
  • 6
  • +2
1 Solution
 
fischierAuthor Commented:
Edited text of question
0
 
Michel PlungjanIT ExpertCommented:
I could write you one, but you never returned to me on
http://www.experts-exchange.com/topics/comp/lang/javascript/Q.10059610
so I think will pass on this one.

Michel
0
 
fischierAuthor Commented:
Sorry, i thought i had... and looking at it, it looks like i did award you the points? Didn't I? Sorry I'm a bit confused.
Hope I've not offended You in any way...
Fischier
(AKA Algabatz on the CGI Area)

Hur kommer det sig att du pratar svenska?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
jbirkCommented:
I Don't really have time to redo a hangman game to add those functionialities, but you asked about other small fun games.  I suggest going to:
http://javascript.internet.com/games/
There's a bunch of little games there to play with.
I've also programmed a few from scratch myself, as I love programming games.
I'm currently working on a nice version of othello, and I also programmed an image shuffle game, where the image is divided into pieces (with the bottom right piece missing), and shuffled up.  Then you have to move the pieces around until you get back to the correct image.  If you're interested in either of these games, just ask, and I'll give you there urls.

Good luck!
-Josh
0
 
fischierAuthor Commented:
Sorry, i thought i had... and looking at it, it looks like i did award you the points? Didn't I? Sorry I'm a bit confused.
Hope I've not offended You in any way...
Fischier
(AKA Algabatz on the CGI Area)

Hur kommer det sig att du pratar svenska?
0
 
Michel PlungjanIT ExpertCommented:
An answered question eventually (after 3 weeks without comments) gets autograded with grade C. I get a lot of those. I answer a question and it gets ignored... I am not offended, just a little annoyed when that happens...

I actually did play around with your script. It is quite some work since the script is not really well structured and the Alphabet is used in several variables accessed by hardcoded value (26, 25, 27, 24) where Alphabet.length would be more appropriate...

If it isn't answered in the meantime, I will try to have an answer tomorrow.

Michel

PS: Jag är dansk och pratar bättre svenska end jag skriver det ;-)
0
 
fischierAuthor Commented:
Sorry, i thought i had... and looking at it, it looks like i did award you the points? Didn't I? Sorry I'm a bit confused.
Hope I've not offended You in any way...
Fischier
(AKA Algabatz on the CGI Area)

Hur kommer det sig att du pratar svenska?
0
 
fischierAuthor Commented:
And one shouldn't press Reload too often...
Sorry Michel, i didn't realize that. I thought things stayed the same until something was done about it. I should have known better.
Jobbar du som programmerare i Danmark eller har Silicon Valley kidnappat dig? Själv är jag nybörjare i scriptsaker men jobbar på Göteborgs-Postens Internetupplaga, därav all underliga frågor...
Since it's evidently a harder question than i anticipated, im increasing the points to 300.
Tony
0
 
Michel PlungjanIT ExpertCommented:
I will look tomorrow morning.

Nähä jag jobber på europäiska patent kontoret (om du vil se nogot som jag har hjälpat at göra, titta på http://www.dips.prv.se/)

Hejdå,

Michel
0
 
GrdvCommented:
hmm, intressant...
Well, the script is far from what I can call a good way to do this... if you wait a day or two I will have a completely new script... about ten times better than that one... :)
doesn't matter if you wait, I'll do it anyway, in the meantime... you could check out my homepage to get a JS Snake... my latest creation.... it's a game... of a kind you probably know... some years ago, it was included with the MS-DOS qbasic program and was called Nibbles, and the it have appeared under lots of names, this is the first online version though... I think... :)
if you're interested let me know and you'll have the url...

//Grdv

::Jag pratar svenska därför att jag vill, så enkelt var det::
0
 
jbirkCommented:
I'd don't know if he is interested, but I AM!  I love games, and that's one basic program which I really enjoyed...
If you don't want to post it here, you can send it to:
jbirk@kent.edu
Thanks,
-Josh
0
 
GrdvCommented:
well, doesn't really matter....
my work need public... :)
well goto:
http://home1.swipnet.se/~w-10109/msh/
and there you'll find my unfinished scripting page... :)
click on new scripts or whatever it says...

//Grdv
0
 
jbirkCommented:
I went to see your site Grdv.  I have to say, it's quite nice!  I like the design of the pages.
There are some broken links, but I'm sure you know that.
I went and played your game.  I wanted to get the key stroke characters to work, and I couldn't seem to, so I implemented a short script to tell me what the character codes were for the keys I hit, and noticed that neither Netscape nor IE support the keys F1-F12, Print Screen, Num Lock, Pause, Del, Home, Pgup, PgDn, End, Ins, Caps Lock, or the arrow keys!  That seemed like an awful lot for them to leave out!  Especially the arrow keys.  That really sucks that it doesn't report an event to JavaScript :(  So then I just figured out where my num lock was and where it's keys where.  I have a laptop whose keys are all smashed together, making num lock use impractical at best -- the keys are all mixed in with the normal keys, like 4,5,6 are u,i,o and * is 0.  Go figure.
Well, anyway, nice job on the game!!
The only thing I would change is making the images slightly bigger.  On my screen (everything is a little smaller on the tightly nit laptop screens) it's almost microscopic, but the game play and speed is really good!  I bet it would be 10 times as slow in Java...

fischier, sorry for interrupting your question like this...

-Josh
0
 
Michel PlungjanIT ExpertCommented:
And Fishier: I have looked and I agree with Grdv - it is not the most efficient way of playing and the lack of reuse makes it quite hard to modify... I will try too (time permitting) for the heck of it and we can see what it looks like afterwards...

Michel
0
 
fischierAuthor Commented:
Hej Gustav, Snake är verkligen ett fantastiskt script. Kan jag använda det på Göteborgs-Postens sida för gratisspel?

Hej Michel, jag lyckades faktiskt hitta min farbrors gräsklipparpatent! En otrolig informationskälla jag inte hade en aning om att den fanns!

Sorry for the Swedish folks. Rather interesting how many Swedish and Russian experts there are...

Josh, i find it immensly interesting., Learning all the time. Keep interrupting, by all means!

/Fischier
0
 
GrdvCommented:
tja, det går väl för sig, så länge det står vem som har gjort det...
förutsatt att det också kommer med en länk, där det står "Grim Reaper Designs"...
ifall du inte vill lägga till den kan jag göra det... :)
well, and for those who speak english rather than swedish... I'm not completely finished with my script... I'm making it browser detect so that even IE3 can support the game...
as IE3 doesn't support dynamic images... so it'll be a check for IE3, which actually is going to do a complete page reload, but not in this way with cookies...
you know, even IE3 supports the use of frames...
will probably be ready tomorrow or the day after...

//Grdv
0
 
fischierAuthor Commented:
Thanks GRDV, i'll hold on until it's finished then.
Any other tips of cool Javascript games would be gratefully recieved.
/Fischier
0
 
jbirkCommented:
Well, the Othello game I'm writing is pretty cool, but I'm still working out some quirks in the AI for the computer players. (there's a link to another othello game below, but mine is better :)  When that's done, I can tell you if you want.
Also the other game I mentioned can be found at:
http://aegis.mcs.kent.edu/~jbirk/Family/BabyBook/easy.html?week-3-7--3-13
The only problem is that it won't be easy to copy, since I programmed a bunch of cgi scripts to allow for a high score table.  But the script itself would be copyable if I provided the text (it's a document entirely dynamically generated, so view source won't work very well...)

Here are some urls to other javascript games:
http://www.high.demon.nl/
http://inls.ucsd.edu/y/JS/ttt.html
http://irt.org/games/all.htm
http://www.geocities.com/Yosemite/Rapids/1479/nibbles.html (another nibbles game but nearly as good as grdv's)

You're not going to find too many more JavaScript games.  Java games are much more common.  You could go to a search engine, and search on Java Games.  Yahoo! Games has some pretty cool Java game applications as well.

Have fun!
-Josh
0
 
martinagCommented:
Michel, jag trodde du var holländare. Nå iaf det verkar som om svenskan är näst störst här på EE efter engelskan... :-)

Martin
0
 
Michel PlungjanIT ExpertCommented:
Jag är dansk! :-)

Michel

0
 
jbirkCommented:
Man, I'm going to have to start learning sweedish :)
Seems like everyone in the JavaScript area speaks it...
-Josh
0
 
GrdvCommented:
Josh, thanks for the comments on the script...
it's actually supposed to be very configurable... in the init sequence you specify all the images and the length and the speed and so on.. so about the images thing, I will not do anything... but on the other hand, the keys... I've added a new function customize keys... which enables the user to set their own keys...

//Grdv
0
 
jbirkCommented:
That's a great idea about the customize keys Grdv.  In fact that was one of things that I though about as a possible solution (a little while after my posted comment).  It's still a bummer the normal arrow keys can't be used :(
So you say the size of the images will also be customizable?  Wow, that's a lot of control for the user!  Will you store the preferences in a cookie, or will the user have to go through the init sequence every time (or will a simple bookmark with command lines keep the preferences)?
Keep up the good work!
-Josh
0
 
GrdvCommented:
Josh:
as it is for this moment... the webmaster of the site, or you might say the on implementing the script... desides which images to be used and so on... don't know, I might add cookies in a while...
for the question:
It might take a while, as I recently bumped into some problems... I tried to write the whole script first and then debug, just to try if I could... go so many errors I couldn't easily correct it... will do a step by step now... but it might take a while as I have to restart...

//Grdv
0
 
GrdvCommented:
Hmm, me again... am I the only fanatic here?? :)
well, now I've come up with my first working (i think) version of an object programmed hangman show... it's quite nice... :)
so, tomorrow I'll fix the rest of the stuff... IE3 compability and, the new word function... that'll be almost the same thing but...
well, at least I hope someone likes it... :)

//Grdv
0
 
GrdvCommented:
hmm... maybe not fanatic... but out of my mind... how could I forget to put the link here??

anyway, here it is:
http://home1.swipnet.se/~w-10109/hangman/

//Grdv
0
 
GrdvCommented:
is this what you were looking for fischier? just trying to get some response on all my comments...

//Grdv
0
 
GrdvCommented:
pardon me, but nobody seems to care about the things I do here... feels rather unpleasant... but what the ....
so, now I have another version, you might say it's a complete one, you may also say it's not... because everything is changing all the time... as my JS Snake for example that recently was improved... well, now I think I'm way off track... so back to the question:
now, you should be able to find a complete version of the page on this address:

      http://home1.swipnet.se/~w-10109/hangman/ 

altough it's supposed to be customized by the one hosting the game, in the file:

      http://home1.swipnet.se/~w-10109/hangman/nload.html

you can find this line, where all the settings are specified... they are all hardcoded, or whatever you say when it's HTML, can't be set dynamicly... not at the moment...
so here's the settings:
(parent.hHang is the object in the main frame which will contain all information and so on, instead of the cookies in the older version, this is mainly used for IE3 and the possability to restart without loading the whole file once again...
new parent.makeHangman is the way of initialize a new custom object in JavaScript and that's exactly what the Hangman show is, an object.)
parent.hHang=new parent.makeHangman(
      "hHang",    //the name of the object to pass to functions
      "ABCDEFGHIJKLMNOPQRSTUVWXYZÅÄÖ",  //the letters you want to be allowed
      new Array("1.gif","2.gif","3.gif","4.gif","5.gif","6.gif","7.gif","8.gif","9.gif","ded.gif",35,40),
      /* array with the images for the ordinary hangman procedure, followed by the specified          height&width */
      new Array("BANAN","ANNANAS","TOMAT","ÖLBÄGARE") //array with the answers
);

this was what I had to say this time.... and remember... 42 is the answer, but what in the world is the question?

//Grdv
0
 
fischierAuthor Commented:
Sorry for the slow reply. I haven't tried to config. it, but it looks just right. I would prefer not using a popup, if possible, two clicks for every letter seems bit much, but if this can't be done i will award you the points. I will increase the points to 400 and if anyone else comes up with an answer i will then split it. So every which way, you've earned yourself 200 points, Grdv!
/Fischier
0
 
fischierAuthor Commented:
Well that didn't make much sense did it?
In short fix it and i'll set up another 200 for the author.
/Fischier
0
 
GrdvCommented:
> I would prefer not using a popup, if possible, two clicks for every letter seems bit much

hmm, sorry, but I don't understand what you're trying to say... where are you clicking twice..., do you want me to do it as on your old page, where you clicked every letter?...

//Grdv
0
 
fischierAuthor Commented:
Well first i have to click "add letter" and actually writing it and then then click "OK", that's three actions. I'd prefer it like the old version where i only had to click a letter to get rolling...
/F
0
 
GrdvCommented:
okay, I'll see what I can do... maybe not today... but in a little while...

//Grdv
0
 
GrdvCommented:
okay... now I'm pissed... not because of you, because of my computer...
I've written this text three times now, and every single time, when I've pressed the submit button, the damn Netscape.... well enough about that...

once again.... have redone, and the line ine nload.html is changed:

function makeHangman(name, aAlpha, bodytag, imgnames, answers){
the changes are:
bodytag=a bodytag, to make it possible to change background and text color easily...
imgnames=an array, consisting of:
1-X: image names, the number of them also specifies the amount of allowed guesses...
X+1:Height of those images
X+2:Width  of those images
X+3:an image tag, to make it possible to change all the attributes of the top img, you can even make it a link if you want... if you don't want any image at all, then leave it ""

that's all from me for now... I think... :)
no... wait check it out at the same adress as before...

//Grdv
0
 
fischierAuthor Commented:
Well, thick-as-a-brick Fischier is back... i don't get it. Is there only two doc's index.html and nload.html? How do i change the number of guesses? Also there seems to be a problem with the use of two words, since the space is treated by the script as a letter. Is there a way to except the space?
/Fischier
0
 
GrdvCommented:
hmm, oops... didn't think about those spaces...
I'll have a look at that and see what I can do, other than that..
to change the number of possible guesses, just place that number of image names in that array as I described in my last comment... or at least I think I wrote that.. :)
hmm... what else... not much I think... I'll be back real soon with a correct version... and thanks for pointing that obvious error out to me..
//Grdv
0
 
GrdvCommented:
sorry for you having to wait, have had problems reaching the server as the www.experts-exchange.com didn't work and today I realised I could use just
experts-exchange.com....
well, the script has been ready for a few days now, and it's in the same location as before...
did you get that about the pages, and if you want it to look better, change the textcolor to the same as the backgroundcolor, so that you don't see the first page with
'Överföring Avbruten' written all over it... :)
that's that I think... :)
//Grdv
0
 
fischierAuthor Commented:
Hej igen GRDV, har varit bortrest, därav dröjsmålet. Jag har pillat litet med ditt script men jag får inte alert:en för rätt svar att fungera..
/F
0
 
GrdvCommented:
hmm... vad är det du har ändrat... om du vill att jag skall titta på det, skicka det till gustav@mbox310.swipnet.se
annars... så ligger den officiellt upplagd på min hemsida...
//Grdv
0
 
GrdvCommented:
still having problems fischier???
0
 
fischierAuthor Commented:
Only to get enough time to straighten this out. Bare with me... I'll be back.
/F
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 16
  • 13
  • 6
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now