Template:IGEM Kyoto/game/js

From OpenWetWare
Jump to: navigation, search

<html> <script type="text/javascript">

   p=2017;
   pass=new Array(1,0,0,0,0);
   function events(year)
   {
       var a='kyoto-events-'+p
       var dpoff=document.getElementById(a);
       dpoff.style.display="none";
       var b='kyoto-events-'+year
       var dpon=document.getElementById(b);
       dpon.style.display="block";
       p=year;
   
       if(year=="2012")
       {
           if(pass[0]==1)
           {
               pass[1]=1;
               pass[0]=0;
           }
           else
           {
               pass[0]=1;
               for (i=1;i<5;i++){
                   pass[i]=0;
               }
           }
       }
       if(year=="2010")
       {
           if(pass[1]==1)
           {
               pass[2]=1;
               pass[1]=0;
           }
           else
           {
               pass[0]=1;
               for (i=1;i<5;i++){
                   pass[i]=0;
               }
           }
       }
       if(year=="2011")
       {
           if(pass[2]==1)
           {
               pass[3]=1;
               pass[2]=0;
           }
           else if(pass[4]==1)
           {
               var gameback=document.getElementById("kyoto-game-background");
               var gamecenter=document.getElementById("kyoto-game-center");
               gameback.style.display="block";
               gamecenter.style.display="block";
           }
           else
           {
               pass[0]=1;
               for (i=1;i<5;i++){
                   pass[i]=0;
               }
           }
       }
       if(year=="2014")
       {
           if(pass[3]==1)
           {
               pass[4]=1;
               pass[3]=0;
           }
           else
           {
               pass[0]=1;
               for (i=1;i<5;i++){
                   pass[i]=0;
               }
           }
       }

} dx=155, dy=100; x=55, sec=101, pnt=0, dmg=-15, lag=-3; mode=0; var i; baspos=new Array(3); for (i=0;i<3;i++){

   baspos[i]=new Array(4);

} for(i=0;i<3;i++){

   for(j=0;j<4;j++){

baspos[i][j]=0; } } catpos=new Array(0,1);

document.onkeydown=action;


function rnd(){

   return Math.floor(Math.random()*4);

}

function loop() { if(sec>0) { if(dmg<100) { setTimeout("loop()",1000); } else { setTimeout("gameover()",1); } } else { setTimeout("gameover()",1); }

   var a,b;

var base0=document.getElementById("image0"); var base1=document.getElementById("image1"); var base2=document.getElementById("image2"); var time=document.getElementById("time"); var score=document.getElementById("score"); var damage=document.getElementById("damage");

if(baspos[2][catpos[0]]+catpos[1]==5) { pnt+=5; } else{ dmg+=5; } sec-=1;

time.innerHTML=sec; score.innerHTML=pnt; damage.innerHTML=dmg;

for(j=0;j<4;j++){ baspos[2][j]=baspos[1][j]; } for(j=0;j<4;j++){ baspos[1][j]=baspos[0][j]; }

a=rnd(); b=rnd(); for(j=0;j<4;j++){ baspos[0][j]=0; } baspos[0][a]=b+1;

for(j=0;j<4;j++){ if(baspos[0][j]>0){ base0.style.left=55+155*j+"px"; if(baspos[0][j]==1) { base0.src="http://openwetware.org/images/0/0b/Kyoto-game-1.png"; } if(baspos[0][j]==2) { base0.src="http://openwetware.org/images/9/9f/Kyoto-game-2.png"; } if(baspos[0][j]==3) { base0.src="http://openwetware.org/images/6/61/Kyoto-game-3.png"; } if(baspos[0][j]==4) { base0.src="http://openwetware.org/images/3/3f/Kyoto-game-4.png"; } } } for(j=0;j<4;j++){ if(baspos[1][j]>0){ base1.style.left=55+155*j+"px"; if(baspos[1][j]==1) { base1.src="http://openwetware.org/images/0/0b/Kyoto-game-1.png"; } if(baspos[1][j]==2) { base1.src="http://openwetware.org/images/9/9f/Kyoto-game-2.png"; } if(baspos[1][j]==3) { base1.src="http://openwetware.org/images/6/61/Kyoto-game-3.png"; } if(baspos[1][j]==4) { base1.src="http://openwetware.org/images/3/3f/Kyoto-game-4.png"; } } } for(j=0;j<4;j++){ if(baspos[2][j]>0){ base2.style.left=55+155*j+"px"; if(baspos[2][j]==1) { base2.src="http://openwetware.org/images/0/0b/Kyoto-game-1.png"; } if(baspos[2][j]==2) { base2.src="http://openwetware.org/images/9/9f/Kyoto-game-2.png"; } if(baspos[2][j]==3) { base2.src="http://openwetware.org/images/6/61/Kyoto-game-3.png"; } if(baspos[2][j]==4) { base2.src="http://openwetware.org/images/3/3f/Kyoto-game-4.png"; } } } lag+=1; if(lag<0) { var damage=document.getElementById("damage"); damage.innerHTML="" } }

function gameover() {

   var gameover=document.getElementById("gameover");
   var showscore=document.getElementById("showscore");
   showscore.innerHTML="SCORE : "+pnt;
   mode=2;

gameover.style.display="inline"; }

function action() {

   if(event.keyCode==37)

{ if(catpos[0]!=0) { var catcher=document.getElementById("image3"); catpos[0]-=1; x-=dx; catcher.style.left=x+"px"; } }

   if(event.keyCode==39)

{ if(catpos[0]!=3) { var catcher=document.getElementById("image3"); catpos[0]+=1; x+=dx; catcher.style.left=x+"px"; } }

   if(event.keyCode==40)

{ var catcher=document.getElementById("image3"); catpos[1]=catpos[0]+1; catcher.src=catpos[1]+".png"; if(catpos[1]==1) { catcher.src="http://openwetware.org/images/0/0b/Kyoto-game-1.png" } if(catpos[1]==2) { catcher.src="http://openwetware.org/images/9/9f/Kyoto-game-2.png" } if(catpos[1]==3) { catcher.src="http://openwetware.org/images/6/61/Kyoto-game-3.png" } if(catpos[1]==4) { catcher.src="http://openwetware.org/images/3/3f/Kyoto-game-4.png" } }

   if(event.keyCode==13)

{ if(mode==0) { var gamestart=document.getElementById("gamestart"); gamestart.style.display="none"; mode=1; setTimeout("loop()",1); } if(mode==2) { var gameover=document.getElementById("gameover"); mode=1; setTimeout("reset()",1); gameover.style.display="none"; setTimeout("loop()",10); } } }

function reset(){ x=55, sec=101, pnt=0, dmg=-15; var i; for (i=0;i<3;i++){ baspos[i]=new Array(4); } for(i=0;i<3;i++){ for(j=0;j<4;j++){ baspos[i][j]=0; } } catpos[0]=0; catpos[1]=1; var base0=document.getElementById("image0"); var base1=document.getElementById("image1"); var base2=document.getElementById("image2"); var catcher=document.getElementById("image3"); base0.src=""; base1.src=""; base2.src=""; catcher.style.left="55px"; lag=-3; } </script>


</html>