
<!---//hide script from old browsers

// Javascript Hangman.  
  //    Version 1.4  1-31-99
//
  //    Copyright (C) 1998,1999  G. William Busby
    //  All rights reserved
  //    This script can only be be reproduced following written permission by 
    //  G. William Busby, and as long as this message remains intact.
     // E-mail: William.Busby@nau.edu */

var version;

var browserName = navigator.appName;
var browserVer = parseInt (navigator.appVersion);
        if (browserName == "Netscape" && browserVer >= 4) {
                 version = "Netscp4";
                }
        else if (browserName == "Microsoft Internet Explorer" && browserVer >= 4) {
                 version = "Explor4";
                }
        else {
                alert ("This game requires Netscape Navigator 4+ or Internet Explorer 4+.");
                location.href = "Games.htm";
                }

var GuessWord = "";
var Letter = "";
var GuessDisplay;
var LettersGuessed = "";
var NumGuessed = 0;
var Won;
var NumWon = 0;
var NumLost = 0;
var HangFrame;
var num = 0;
var NumWords = 24;

//  Word List - I hope your not looking up the answers here, it would take all the fun out of playing.
//  Well, just in case you are, I've slightly encoded the word list to deter you.
var Words = new Array (NumWords);
Words[0] = "bqzolo";
Words[1] = "bwckvqbknce";
Words[2] = "vlbwilvh";
Words[3] = "kvlqkglck";
Words[4] = "jntto";
Words[5] = "rqbklvnq";
Words[6] = "ncplbknwc";
Words[7] = "fwvgqck";
Words[8] = "qbknil";
Words[9] = "ohgjkwgo";
Words[10] = "kloko";
Words[11] = "khjlo";
Words[12] = "tzceo";
Words[13] = "rwclo";
Words[14] = "ohoklgo";
Words[15] = "qcngqto";
Words[16] = "bwckvwt";
Words[17] = "nggzcnkh";
Words[18] = "okqelo";
Words[19] = "kzrlvbtl";
Words[20] = "ojzkzg";
Words[21] = "svqh";
Words[22] = "rwincl";
Words[23] = "thgjyqknb";
Words[24] = "gvkr";

function StartUp () {
        var temp;
        GuessDisplay = "";
        LettersGuessed = "";
        HangFrame = 1;

        temp = Words[num];

        GuessWord = Decrypt (temp);

        var x = 0;
        while (x < GuessWord.length) {
                if (version == "Netscp4") {
                        GuessDisplay += "-";
                        }
                else if (version == "Explor4") {
                        GuessDisplay += "*";
                        }
                x++;
                }

        document.hangman.pic.src = "graphics/icons/hanging1.jpg";
        document.hangman.wordbox.value = GuessDisplay;
        document.hangman.lettersbox.value = LettersGuessed;
        document.hangman.messagebox.value = "";
        document.hangman.won.value = NumWon;
        document.hangman.lost.value = NumLost;
        num +=1;
        }

function MakeGuess (Letter) {
        var temp = "";
        document.hangman.messagebox.value = "";

        if (HangFrame == 10) 
                alert ("Game Over.  Use 'Next Word' Button to Select a New Word.");

        if (LettersGuessed.indexOf (Letter) != -1)
                document.hangman.messagebox.value = "The " + Letter + " has already been guessed.";

        else {
                LettersGuessed += Letter;
                document.hangman.lettersbox.value = LettersGuessed;

                if (GuessWord.indexOf (Letter) == -1) {
                        HangFrame += 1;
                        document.hangman.pic.src = "graphics/icons/hanging" + HangFrame + ".jpg";
                        if (HangFrame == 7) 
                                GameOver (0);
                        }
                else {
                        for (var x=0; x < GuessWord.length; x++) {
                                if (GuessWord.charAt (x) == Letter) {
                                        temp = GuessDisplay.substring (0, x) + Letter + GuessDisplay.substring (x +1, GuessDisplay.length);
                                        GuessDisplay = temp;
                                        }
                                }

                        NumGuessed += 1;
                        if (GuessDisplay == GuessWord)
                                GameOver (1);
                
                        document.hangman.wordbox.value = GuessDisplay;
                        }
                }
        }


function GameOver (Won) {
        if (Won == 1) {
                NumWon += 1;
                HangFrame = 10;
                document.hangman.won.value = NumWon;
                document.hangman.messagebox.value = "Congratulations!  You've guessed the word!!!";
                }
        else {
                NumLost = NumLost + 1;
                HangFrame = 10;
                document.hangman.lost.value = NumLost;
                document.hangman.messagebox.value = "Oh No! You've hung him!!!";
                document.hangman.wordbox.value = GuessWord;
                }
        }

function NewGame () {
        LettersGuessed = "";
        HangFrame = 1;
        NumGuessed = 0;
        StartUp ();
        }

function Check () {
        if (num == 25) {
                alert ("Thank you for playing Hangman.");
                location.href = "Games.htm";
                }
        else
                NewGame ();
        }

function Decrypt (temp) {
        var newword = "";

        for (var x=0; x < temp.length; x++) {
                switch (temp.charAt (x)) {
                        case "a":
                                newword = newword.substring (0, x) + "j" + temp.substring (x +1, temp.length);
                                break;
                        case "b":
                                newword = newword.substring (0, x) + "c" + temp.substring (x +1, temp.length);
                                break;
                        case "c":
                                newword = newword.substring (0, x) + "n" + temp.substring (x +1, temp.length);
                                break;
                        case "d":
                                newword = newword.substring (0, x) + "q" + temp.substring (x +1, temp.length);
                                break;
                        case "e":
                                newword = newword.substring (0, x) + "g" + temp.substring (x +1, temp.length);
                                break;
                        case "f":
                                newword = newword.substring (0, x) + "d" + temp.substring (x +1, temp.length);
                                break;
                        case "g":
                                newword = newword.substring (0, x) + "m" + temp.substring (x +1, temp.length);
                                break;
                        case "h":
                                newword = newword.substring (0, x) + "y" + temp.substring (x +1, temp.length);
                                break;
                        case "i":
                                newword = newword.substring (0, x) + "v" + temp.substring (x +1, temp.length);
                                break;
                        case "j":
                                newword = newword.substring (0, x) + "p" + temp.substring (x +1, temp.length);
                                break;
                        case "k":
                                newword = newword.substring (0, x) + "t" + temp.substring (x +1, temp.length);
                                break;
                        case "l":
                                newword = newword.substring (0, x) + "e" + temp.substring (x +1, temp.length);
                                break;
                        case "m":
                                newword = newword.substring (0, x) + "z" + temp.substring (x +1, temp.length);
                                break;
                        case "n":
                                newword = newword.substring (0, x) + "i" + temp.substring (x +1, temp.length);
                                break;
                        case "o":
                                newword = newword.substring (0, x) + "s" + temp.substring (x +1, temp.length);
                                break;
                        case "p":
                                newword = newword.substring (0, x) + "f" + temp.substring (x +1, temp.length);
                                break;
                        case "q":
                                newword = newword.substring (0, x) + "a" + temp.substring (x +1, temp.length);
                                break;
                        case "r": 
                                newword = newword.substring (0, x) + "b" + temp.substring (x +1, temp.length);
                                break;
                        case "s":
                                newword = newword.substring (0, x) + "x" + temp.substring (x +1, temp.length);
                                break;
                        case "t":
                                newword = newword.substring (0, x) + "l" + temp.substring (x +1, temp.length);
                                break;
                        case "u":
                                newword = newword.substring (0, x) + "w" + temp.substring (x +1, temp.length);
                                break;
                        case "v":
                                newword = newword.substring (0, x) + "r" + temp.substring (x +1, temp.length);
                                break;
                        case "w":
                                newword = newword.substring (0, x) + "o" + temp.substring (x +1, temp.length);
                                break;
                        case "x":
                                newword = newword.substring (0, x) + "k" + temp.substring (x +1, temp.length);
                                break;
                        case "y":
                                newword = newword.substring (0, x) + "h" + temp.substring (x +1, temp.length);
                                break;
                        case "z":
                                newword = newword.substring (0, x) + "u" + temp.substring (x +1, temp.length);
                                break;
                        }
                }
        return newword;
        }

//--> end hiding contents



