Learning Javascript using the game CATCH FOSS
This page describes the game CATCH FOSS
The game Catcher is written in JavaScript and standard HTML commands.
The player's objective is to make a correct distinction between the free and paid software. The objects appearing on the screen bear the software name and logo and move around in various speeds. The player will receive 10 points after clicking on the correct object (the player successfully recognizes the free software). The player will lose 10 points after clicking on the paid software (the player fails to recognize the paid software). The player can receive a maximum of 50 points as a bonus by clicking on the "Bonus" object. The player can also loose 50 points by clicking on the "Virus" object.
Replacing Images
Modification of the Total Number of the Objects to be Displayed
Brief Description of the Game Functions in JavaScript Language
//detecting browser to dynamically write appropriate DIVs/LAYERs
N=(navigator.appName.indexOf('Netscape')!=-1&&parseInt(navigator.appVersion)<5)
S=(navigator.appName.indexOf('Netscape')!=-1&&parseInt(navigator.appVersion)>4.9)
M=(navigator.appName.indexOf('Microsoft')!=-1)
var Styl,ID,zX,zY,vis,vs,zz
Vis=new Array()
Vis[0]=(M||S) ? "hidden" : "hide"
Vis[1]=(M||S) ? "visible" : "show"
The "GetDiv" and "EndDiv" functions provide the actual display of the layers.
//set parameters layer (tag <DIV>)
function GetDiv(divId,divY,divX,divW,divH,bCol,visb,zInd){
bkCol=(bCol!="")?((N)?" bgColor="+bCol:";background:"+bCol):""
Styl = (M||S) ? "<DIV" : "<LAYER"
if(M||S){
Styl+=" ID="+divId
Styl+=" style='position:absolute;top:"+divY+";left:"+divX+";width:"+divW+";height:"+divH+bkCol
Styl+=";visibility:"+Vis[visb]+";z-index:"+zInd
Styl+="'>"
}
if(N){
Styl+=" ID="+divId
Styl+=" top="+divY+" left="+divX+" width="+divW+" height="+divH+bkCol
Styl+=" visibility="+Vis[visb]+" z-index="+zInd
Styl+=">"
}
document.writeln(Styl)
}
//end tag layer (tag <DIV>)
function EndDiv(){
(M||S)? document.writeln("</DIV>"): document.writeln("</LAYER>")
}
The "PutIt" function sets the layer coordinates.
//set X and Y axis of layer
function PutIt(ID,zX,zY){
if(N){
document.layers[ID].left=zX
document.layers[ID].top=zY
}
//set Zindex tag <DIV>
function Zind(ID,zz){
if(N){
document.layers[ID].zIndex=zz
}
if(M){
document.all[ID].style.zIndex=zz
}
if(S){
document.getElementById(ID).style.zIndex=zz
}
}
//return X axis layer
function Xof(ID){
if(N){
return parseInt(document.layers[ID].left)
}
if(M){
return parseInt(document.all[ID].style.left)
}
if(S){
return parseInt(document.getElementById(ID).style.left)
}
}
//return Y axis layer
function Yof(ID){
if(N){
return parseInt(document.layers[ID].top)
}
if(M){
return parseInt(document.all[ID].style.top)
<HTML>
<head>
<META NAME="AUTHOR" CONTENT="">
<META NAME="description" CONTENT="Javascripts Games">
<META NAME="keywords" CONTENT="games, javascript, graphics">
<META NAME="robots" CONTENT="INDEX, ALL">
<link rel="stylesheet" type="text/css" href="css/game.css" />
<title>Catcher</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1250"><style type="text/css">
<!--
body,td,th {
font-family: Arial, Helvetica, sans-serif;
}
body {
background-color: #999;
}
-->
</style></head>
<script src=laydiv.js></script>
<body text="#FFFF00" style="cursor:cross-hairs">
<form name=Form>
<table width=62%>
<tr>
<td width="37%" height="59" align="left" valign="top"><font size=5>Catch free software!
</td>
<td width="25%" align="center" valign="top"><font size="+1">countdown</font>
<input type="button" name=Countdown size=5>
<td width="20%" align="center" valign="top"><font size="+1">score</font>
<input type="button" name=Playscore size=5></td>
<td width="18%" align="right" valign="top"><a href="teachers_guide.htm" target="_blank">Teachers guide</a>
</td>
</table>
<script>
Z=new Array()
Z[0]=new Array(0,0,0,0,0)
Z[1]=new Array(0,3,0,3,0)
Z[2]=new Array(0,0,3,0,3)
Z[3]=new Array(3,0,3,0,0)
Z[4]=new Array(0,0,0,3,3)
Z[5]=new Array(0,0,3,0,0)
//Display Background
GetDiv("PozadiL",50,0,110,600,'#999',1,4)
document.write("<img src='images//back.gif' width=115 height=500>")
EndDiv()
for(c=0;c<5;c++){
GetDiv("Pozadi"+c,50,110+c*110,110,600,'',1,Z[1][c])
document.write("<img src='images//back.gif' width=115 height=500>")
EndDiv()
}
GetDiv("PozadiR",50,660,300,600,'#999',1,4)
document.write("<img src='images//back.gif' width=115 height=500>")
EndDiv()
Side=new Array()
Dir=new Array()
Dir["L"]=5
Dir["R"]=-5
//random select images
for(x=0;x<6;x++){
GetDiv("L"+x,200,5,50,50,'',1,2)
document.write("<a href='javascript:GetHim(",x,")'><img src='images//L"+x+".gif' border=0></a>")
EndDiv()
GetDiv("R"+x,200,660,50,50,'',1,2)
document.write("<a href='javascript:GetHim(",x,")'><img src='images//R"+x+".gif' border=0></a>")
EndDiv()
Side[x]=(Math.random()>.5)?"L":"R"
}
/* Game initialization
NumberObj - number of objects to end game
Score - score
Timer - actual number of objects which were displayed
*/
function Init(){
Timer=0
Score=0
NumberObj=30
document.Form.Playscore.value=Score
Next()
}
Side=new Array()
Dir=new Array()
Dir["L"]=5
Dir["R"]=-5
//random select images
for(x=0;x<6;x++){
GetDiv("L"+x,200,5,50,50,'',1,2)
document.write("<a href='javascript:GetHim(",x,")'><img src='images//L"+x+".gif' border=0></a>")
EndDiv()
GetDiv("R"+x,200,660,50,50,'',1,2)
document.write("<a href='javascript:GetHim(",x,")'><img src='images//R"+x+".gif' border=0></a>")
EndDiv()
Side[x]=(Math.random()>.5)?"L":"R"
}
/* Game initialization
NumberObj - number of objects to end game
Score - score
Timer - actual number of objects which were displayed
*/
function Init(){
Timer=0
Score=0
NumberObj=30
document.Form.Playscore.value=Score
Next()
}
//Display object on screen
function Slide(){
X=Xof(Obj)+Math.round(dir*(Si/2+1))
PutIt(Obj,X,Y)
if(X>0&&X<670)SlideOut=setTimeout('Slide()',50-Timer)
else {
Side[S]=(Side[S]=="L")?"R":"L"
setTimeout('Next()',700)
// Increase or decrease Score
function GetHim(i){
PutIt("L"+i,5,200)
PutIt("R"+i,660,200)
if (dir==5)
{
switch (i)
{
case 0:
Score+=10;break;
case 1:
Score-=10;break;
case 2:
Score+=10;break;
case 3:
Score-=10;break;
case 4:
Score+=10;break;
case 5:
Score-=10;break;
}
}
else
{
switch (i)
{
case 0:
Score+=10;break;
case 1:
Score-=10;break;
case 2:
Score-=10;break;
case 3:
Score-=50;break;
case 4:
Score+=50;break;
case 5:
NumberObj+=10;
document.Form.Countdown.value=parseInt(NumberObj-Timer)+1;
Score+=50;
break;
}
}
// Score+=10*(i+5)
Side[i]=(Side[i]=="L")?"R":"L"
document.Form.Playscore.value=Score
clearTimeout(SlideOut)
Next()
}
</body> </HTML>