Digit Invaders

[Total: 0    Average: 0/5]

This is a game of digit invaders.

Head Code:

<SCRIPT LANGUAGE="JavaScript1.1">
<!-- hide script from old browsers
//-------------------------------------------------------------------------------
// JavaScript Digit Invaders game.
// Written by Rick Glusick, April 1997. 
// Updated July 1997.
// Updated January 1999 - fixed a bug with Netscape 4.5...
//
// This code may be copied, used and modified as long as this banner
// is left intact and attached to this code.
//
// Email : glusick@dave-world.net
// Copyright 1997
//-------------------------------------------------------------------------------
var fullBrowserNameVer = navigator.userAgent;
var browserNameVersion = navigator.userAgent.substring(0,11);
var badGuys = "";
var badGuysTemp = "";
var goodGuy = "))==>";
var space = "  ";
var laser = "--";
var widthGame = 40;
var pause = 61;
var i = 0;
var wait = 0;
var score = 0;
var buttonPress = -1;



function checkBrowser() {
   if (browserNameVersion == "Mozilla/2.0") {
       alert('Sorry, this game requires Netscape Navigator 3.0 or above!');
   }
   else { 
       // The fonts in the text box is proportional in Netscape 3.0
       // and fixed in Netscape 4.0, at least on Windows 3.1.
       // This will adjust a couple variables if you are running 
       // Netscape 4.0.
       if (browserNameVersion == "Mozilla/4.0") {     
           space = " ";
           laser = "-";
       }
       game();
   }
}



function game() {
    var view = "";
    var spaceOut = "";
    var laserOut = "";
    var randNum=Math.floor(Math.random() * 10);
    var lenBadGuys = badGuys.length;
    if (wait == 10) {
        badGuys += randNum.toString(10);
        wait = 0;
    }
    else {
        wait += 1;
    }
    if (badGuys.charAt(0) == buttonPress.toString(10)) {
        score += 1;
        badGuysTemp = badGuys;
        badGuys = "";
        for (i=1; i<lenBadGuys; i++) {
           badGuys += badGuysTemp.charAt(i);
        }
        if (score%10 == 0 & pause > 10)
           pause -= 10;      
    }
    spaceOut = "";
    laserOut = "";
    for (i=1; i<=(widthGame-lenBadGuys); i++) {
       spaceOut += space;
       laserOut += laser;
    }
    if (buttonPress == -1)
      view = goodGuy + spaceOut + badGuys;
    else
      view = goodGuy + laserOut + badGuys;
//  You can comment this next line if the status bar annoys you...
    window.status = view;
    document.cntrlForm.gameBox.value = view;
    document.cntrlForm.scoreBox.value = score.toString(10);
    buttonPress = -1;
    if (lenBadGuys<widthGame) {
        setTimeout("game()",pause);
    }
}
// end hiding contents -->
</SCRIPT>

Body Code:

<CENTER>
<B>
<FONT COLOR=YELLOW>
&lt&lt&lt&lt&lt&lt JavaScript Digit Invaders Game &gt&gt&gt&gt&gt&gt
</FONT>
<BR>
As the digits march left, blast the digit in front by pressing the
appropiate button.  Any other button will be ineffective against the onslaught.  The game is over when the digits touch your blaster.
<BR>
<BR>
</B>

<FORM NAME="cntrlForm">
<INPUT TYPE="button" VALUE="   Start   " ONCLICK="score=0;badGuys='';checkBrowser()">
<INPUT TYPE="button" VALUE="   Exit    " ONCLICK="history.go(-1);">
<BR>
<BR>
</CENTER>
Score:<INPUT TYPE="text" NAME="scoreBox" SIZE="6"><BR>
Game:<INPUT TYPE="text" Name="gameBox" SIZE="86">
<CENTER>
<BR>
<BR>
<INPUT TYPE="button" VALUE="     0     " ONCLICK="buttonPress=0;">
<INPUT TYPE="button" VALUE="     1     " ONCLICK="buttonPress=1;">
<INPUT TYPE="button" VALUE="     2     " ONCLICK="buttonPress=2;">
<INPUT TYPE="button" VALUE="     3     " ONCLICK="buttonPress=3;">
<INPUT TYPE="button" VALUE="     4     " ONCLICK="buttonPress=4;">
<INPUT TYPE="button" VALUE="     5     " ONCLICK="buttonPress=5;">
<INPUT TYPE="button" VALUE="     6     " ONCLICK="buttonPress=6;">
<INPUT TYPE="button" VALUE="     7     " ONCLICK="buttonPress=7;">
<INPUT TYPE="button" VALUE="     8     " ONCLICK="buttonPress=8;">
<INPUT TYPE="button" VALUE="     9     " ONCLICK="buttonPress=9;">
</FORM>

Times Viewed: 10

Leave a Reply

Your email address will not be published. Required fields are marked *