اخر المواضيع

آخر الأخبار

الاثنين

كود The Game of Tetris لعبة تتريس

السلام عليكم
عدد المشاهدات الان

المثال

الكود

<div align=center>

<script language="JavaScript">


var fixtime=120000; // Set time in Milliseconds


var delay = 100;

var startd,timera;

var oldv=0;

var rows = 25;

var cols = 11;

var count = rows*cols;

var total = rows*cols;

var speeda = 350;

var speedb = 350;

var inc_score = 20;

var bonus2,bonus3,bonus4;

var timerx;

var df  = new Array(total);

var dfc = new Array(total);

var cells1=new Array(4);

var temp1 = new Array(4);

var test1 = 246;

var down1 = 0;

var ran;

var ranc;

var rowsclear=0;

var score2=0;

var time_final;

var inc_time=10000;

var mtime_check=1;

var moves=0;

var times=0;

var finished = 0;

var firstmove = 0;

var timee = 0

var ur = document.location.href;

if ( ur.indexOf("?") != -1 ){

 var a = ur.split("=");

 var level = a[1];

}

else {

 level = 2;

}

for(var x=0; x<df.length; x++) {

df[x] = 0;

}

for(var x=0; x<dfc.length; x++) {

dfc[x] = 8;

}

if (level<=5) {

speeda=speeda-(level*50);

speedb=speedb-(level*50);

inc_score=inc_score+(level*10);

bonus2=inc_score*2;

bonus3=inc_score*3;

bonus4=inc_score*4;

}

document.onkeydown = downfunc;


function timer() {

    var f = new Date();

    var fg = f.valueOf();

    if(oldv==0)

startd = fg-1;

    var gap = fg-startd;

    if(oldv>gap){

refresh();

return;

    }else{

timee = gap;

    }

    oldv = gap;

    var ede = eval("document.getElementById('tim')");

    ede.value=timee;

    if(finished == 0)

     timera = self.setTimeout("timer()", delay);

}

function move()

{

  mtime_check = (fixtime+rowsclear*inc_time-timee)/1000;

  var as1 = document.op;

  as1.mtime.value=mtime_check;

  

  if (df[235]==1)

  areset();

  

  if (mtime_check > 0.05)

  {

  stop = false;

  for(var y=0; y<cells.length; y++)

  {

    var cellno = cells[y];

    

    if(cellno >= 0)

{

       if(df[cellno-cols] == 1 || cellno-cols < 0)

   {    

          stop = true;

   }

}

  }

  if(stop == true)

  {

    for(var y=0; y<cells.length; y++)

{

var cellno = cells[y];       

        if(cellno >= 0)

        {

   df[cellno] = 1;

   dfc[cellno]= ranc;

}

  }

 

  var firstrowpos = true;

  var sd_temp=0;

  var rowcount=0;

  for(var sd=0; sd<=rows; sd++)

{

      var pos1 = sd*cols;

      var pos2 = true;

 

if (sd!=rows)

{

  for(var s=pos1;s<pos1+cols;s++)

{

  if(df[s]!=1)

  pos2 = false;

}

}

else if (sd==rows)

        pos1=sd_temp*cols;

for(var s=pos1;s<(pos1+cols);s++)

{

  if(df[s]!=1)

  pos2 = false;

}

if (pos2== true)

{

  sd=sd_temp;

  if(rowcount==1)

     score2=score2+bonus2;

  else if (rowcount==2)

score2=score2+bonus3;

  else if (rowcount==3)

score2=score2+bonus4;

}

}

           

if(pos2 == true)  //remove rows and reset values

{

         if (firstrowpos == true)

         {

  firstrowpos = false;

  sd_temp=sd;

   }

   rowsclear=rowsclear+1;

   rowcount=rowcount+1;

   score2=score2+inc_score;

   time_final=time_final+10000; 

   var as = document.op;

   as.level1.value=level;

   as.sw.value=rowsclear;

   as.score1.value=score2;

       for(var gh=0; gh<cols; gh++)

   {

       df[pos1+gh] = 0;

       dfc[pos1+gh] = 8;

       var ded = document.getElementById(pos1+gh);

               ded.style.backgroundColor = "white";

   }

   for(var sdfsdf=sd+1; sdfsdf<rows; sdfsdf++)

   {

       for(var gh=0; gh<cols; gh++)

   {

         oldcol = (sdfsdf*cols)+gh;

         newcol = (sdfsdf*cols)+gh-cols;

if(df[oldcol] == 1)

{

         var ded = document.getElementById(oldcol);

                 ded.style.backgroundColor = "white";

      df[newcol] = df[oldcol];

      dfc[newcol] = dfc[oldcol];

      df[oldcol] = 0;

      dfc[oldcol] = 8;

  ded = document.getElementById(newcol);

            ded.style.backgroundColor =change_color(dfc[newcol]);

             }

               }

     }

}

}

 

  }

  else

  {

     for(var y=0; y<cells.length; y++)

{

    var cellno = cells[y];       

        var ded = document.getElementById(cellno);

        ded.style.backgroundColor = "white";

     }

     for(var y=0; y<cells.length; y++)

{

var cellno = cells[y];       

        cells[y] = parseInt(cellno)-cols;

        ded = document.getElementById(cells[y]);

        ded.style.backgroundColor = change_color(ranc);

     }

  }

 

  if(stop != true)

  {

    timerx = setTimeout('move()',speeda);

  }

  else

  {

    speeda =speedb;

    areset();

  }

   }// check if 

   else

   {

var pos = (count-cols)-(i*cols)+j;

document.getElementById("tim").disabled =  true; 

document.getElementById("mtime").disabled =  true;

         document.getElementById("score1").disabled = true;

         document.getElementById("level1").disabled = true;

         document.getElementById("check2").disabled = true;

     

     moves = score2;  //the total No. of tries can be displayed to score 

     finished=1;

}

}

function downfunc(e)

{

  if (!e) var e = window.event;

  if (e.keyCode) x = e.keyCode;

  else if (e.which) x = e.which;


  if(x == 39)// -->

  {

      

if(((cells[cells.length-1]+1)%cols != 0)&& (df[(cells[cells.length-1]+1)]==0))

{

for(var y=cells.length; y>=0; y--)

{

    var cellno = cells[y];

        if(((cellno > 0)) && (((cells[cells.length]))!=1))

{

         var ded = document.getElementById(cellno);

ded.style.backgroundColor = "white";

cells[y] = parseInt(cellno)+1;

         var ded1 = document.getElementById(cells[y]);

         ded1.style.backgroundColor = change_color(ranc);   


}

}

}

   }

   else if (x==37)  //<--

   {

     

if(((cells[0])%cols != 0)&& (df[(cells[0]-1)]==0)) {

  for(var y=0; y<cells.length; y++)

{

    var cellno = cells[y];

if((cellno > 0))

{

         var ded = document.getElementById(cellno);

         ded.style.backgroundColor = "white";

cells[y] = parseInt(cellno)-1;

         ded = document.getElementById(cells[y]);

         ded.style.backgroundColor = change_color(ranc);    

}

}

}

   }

   else if (x==40)

   {

speeda = 50;  

   }

   else if (x==38)

   {

//temparray = new Array(test1,test1-cols,test1+1,test1+2);

if(ran==1)

{

   

    //alert(cells)

   if ((df[(cells[1]-cols)]==0)&&(df[(cells[1]-(2*cols))]==0)&&((cells[0]-cells[1])==cols)&&((cells[2]-cells[0])==1)&&((cells[3]-cells[2])==1))//

   {

   var ded = document.getElementById(cells[3]);

       ded.style.backgroundColor = "white";

   var ded = document.getElementById(cells[1]);

       ded.style.backgroundColor = "white";

     cells[0]=cells[0]+(cols);

   cells[1]=cells[0]+1;

   cells[2]=cells[0]+1-cols;

   cells[3]=cells[0]+1-2*cols;

   

   }

   else if(((cells[3]+1)%cols!=0)&&((cells[1]-cells[0])==1)&& ((cells[1]-cells[2])==cols)&& ((cells[2]-cells[3])==cols) )

   {

 

   var ded = document.getElementById(cells[3]);

       ded.style.backgroundColor = "white";

   cells[2]=cells[0]+2;

   cells[3]=cells[2]+cols;

   

   }

   else if(((cells[1]-cells[0])==1)&& ((cells[2]-cells[1])==1)&& ((cells[3]-cells[2])==cols) )

   {

       var ded = document.getElementById(cells[3]);

       ded.style.backgroundColor = "white";

   var ded = document.getElementById(cells[2]);

       ded.style.backgroundColor = "white";

       cells[1]=cells[0]+cols;

   cells[2]=cells[1]+cols;

   cells[3]=cells[0]+1;

   

   }

   else if((df[(cells[0]-cols)]==0)&&(df[(cells[0]-(2*cols))]==0)&&((cells[1]-cells[0])==cols)&& ((cells[2]-cells[1])==cols)&& ((cells[3]-cells[0])==1) )

   {

       

//alert(cells)

   var ded = document.getElementById(cells[3]);

       ded.style.backgroundColor = "white";

   var ded = document.getElementById(cells[2]);

       ded.style.backgroundColor = "white";

       var ded = document.getElementById(cells[1]);

       ded.style.backgroundColor = "white";

       cells[0]=cells[0];

       cells[1]=cells[0]-cols;

       cells[2]=cells[0]+1;

   cells[3]=cells[0]+2;

   

   }

}

else if(ran==2)

{

//temparray = new Array(test1,test1+1,test1+2,test1+2-cols);

   

   if ((df[(cells[0]-cols)]==0)&&(df[(cells[0]-(2*cols))]==0)&&(df[(cells[0]-(3*cols))]==0)&&(df[(cells[0]+1)]==0)&&((cells[1]-cells[0])==1)&&((cells[2]-cells[1])==1)&&((cells[2]-cells[3])==cols))

   {

   var ded = document.getElementById(cells[3]);

       ded.style.backgroundColor = "white";

   var ded = document.getElementById(cells[2]);

       ded.style.backgroundColor = "white";

       cells[1]= cells[0]-cols;

   cells[2]= cells[0]-2*cols;

   cells[3]= cells[0]+1;

   

   }

   else if((df[(cells[0]+cols)]==0)&&(df[(cells[0]+1)]==0)&&(df[(cells[0]+2)]==0)&&((cells[3]+1)%cols!=0)&&((cells[0]-cells[1])==cols)&& ((cells[1]-cells[2])==cols)&& ((cells[3]-cells[0])==1) )

   {

   var ded = document.getElementById(cells[3]);

       ded.style.backgroundColor = "white";

   var ded = document.getElementById(cells[2]);

       ded.style.backgroundColor = "white";

   cells[1]=cells[0]+cols;

   cells[2]=cells[0]+1;

   cells[3]=cells[0]+2;

   }

   else if(((cells[1]-cells[0])==cols)&& ((cells[2]-cells[0])==1)&& ((cells[3]-cells[0])==2) )

   {

   var ded = document.getElementById(cells[3]);

       ded.style.backgroundColor = "white";

   var ded = document.getElementById(cells[1]);

       ded.style.backgroundColor = "white";

       cells[1] = cells[0]+1;

   cells[2]=cells[1]+cols;

   cells[3]=cells[2]+cols;

   }

   else if(((cells[3]+1)%cols!=0)&&((cells[1]-cells[0])==1)&& ((cells[2]-cells[1])==cols)&& ((cells[3]-cells[2])==cols) )

   {

   var ded = document.getElementById(cells[3]);

       ded.style.backgroundColor = "white";

   var ded = document.getElementById(cells[2]);

       ded.style.backgroundColor = "white";

       cells[0]=cells[0];

       cells[1]=cells[0]+1;

       cells[2]=cells[0]+2;

   cells[3]=cells[2]-cols;

   }

}

else if(ran==3)

{

   

   if ((df[(cells[1]-cols)]==0)&&(df[(cells[1]-(2*cols))]==0)&&((cells[1]-cells[0])==1)&&((cells[2]-cells[1])==cols)&&((cells[3]-cells[1])==1))

   {

   var ded = document.getElementById(cells[0]);

       ded.style.backgroundColor = "white";

       cells[0]=cells[1]-cols;

   cells[1]=cells[0]+cols;

   cells[2]=cells[0]+2*cols;

   cells[3]=cells[1]+1;

  // alert(cells)

  

   }

   else if((df[(cells[1]-cols)]==0)&&(df[(cells[1]-(2*cols))]==0)&&((cells[3]+1)%cols!=0)&&((cells[1]-cells[0])==cols)&& ((cells[2]-cells[1])==cols)&& ((cells[3]-cells[1])==1) )

   {

   var ded = document.getElementById(cells[2]);

       ded.style.backgroundColor = "white";

       cells[0]=cells[1]-1;

       cells[2]=cells[1]-cols;

      

  /* cells[0] = cells[0]+2*cols;

   cells[1] = cells[0]+1;

   cells[2] = cells[1]-cols;

   cells[3] = cells[0]+2;*/

   }

   else if((df[(cells[1]-cols)]==0)&&(df[(cells[1]-(2*cols))]==0)&&((cells[1]-cells[0])==1)&& ((cells[1]-cells[2])==cols)&& ((cells[3]-cells[1])==1))

   {

   var ded = document.getElementById(cells[3]);

       ded.style.backgroundColor = "white";

   cells[3]=cells[1]+cols;

   

   }

   else if(((cells[3]+1)%cols!=0)&&((cells[1]-cells[0])==1)&& ((cells[1]-cells[2])==cols)&& ((cells[3]-cells[1])==cols) )

   {

       var ded = document.getElementById(cells[2]);

       ded.style.backgroundColor = "white";

       cells[1]=cells[0]+1;

       cells[2]=cells[1]+cols;

   cells[3]=cells[1]+1;

   }

}

else if(ran==4)

{

   

//  alert(cells);

   if ((df[(cells[0]+1-cols)]==0)&&(df[(cells[0]+1-(2*cols))]==0)&&(df[(cells[0]+2-cols)]==0)&&(df[(cells[0]+2-(2*cols))]==0)&&((cells[3]+1)%cols!=0)&&((cells[0]-cells[1])==cols)&&((cells[2]-cells[0])==1)&&((cells[3]-cells[2])==cols))

   {

   var ded = document.getElementById(cells[3]);

       ded.style.backgroundColor = "white";

   cells[1] = cells[0]+1;

   cells[2] = cells[1]-cols;

   cells[3] = cells[2]+1;

   

   }

   else if((df[(cells[0]-cols)]==0)&&(df[(cells[1]-(2*cols))]==0)&&(df[(cells[2]+cols)]==0)&&(df[(cells[2]+(2*cols))]==0)&&((cells[1]-cells[0])==1)&& ((cells[1]-cells[2])==cols)&& ((cells[3]-cells[2])==1) )

   {

   var ded = document.getElementById(cells[3]);

       ded.style.backgroundColor = "white";

   cells[1] = cells[0]-cols;

   cells[2] = cells[0]+1;

   cells[3] = cells[2]+cols;

   

   }

  

}

else if(ran==5)

{

  // alert(cells) 

   if((df[(cells[0]-cols)]==0)&&(df[(cells[0]+cols)]==0)&&(df[(cells[0]+(2*cols))]==0)&&(df[(cells[0]+(3*cols))]==0)&&((cells[1]-cells[0])==1)&& ((cells[2]-cells[0])==2)&&((cells[2]-cells[1])==1)&&((cells[3]-cells[2])==1))

   {

   var ded = document.getElementById(cells[3]);

     ded.style.backgroundColor = "white";

     var ded = document.getElementById(cells[2]);

         ded.style.backgroundColor = "white";

         var ded = document.getElementById(cells[1]);

         ded.style.backgroundColor = "white";

         

         

         cells[1]=cells[0]+cols;

         cells[2]=cells[1]+cols;

         cells[3]=cells[2]+cols;

   /*cells[0]=cells[0]+2*cols;

   cells[1]=cells[0]+cols;

   cells[2]=cells[0]-cols;

   cells[3]=cells[0]-2*cols;*/

   }

   else if((df[(cells[0]+1)]==0)&&(df[(cells[0]+2)]==0)&&(df[(cells[0]+3)]==0)&&((cells[1]-cells[0])==cols)&&((cells[2]-cells[1])==cols)&&((cells[2]-cells[0])==2*cols)&&((cells[3]-cells[2])==cols))

   {

   

   var ded = document.getElementById(cells[3]);

     ded.style.backgroundColor = "white";

     var ded = document.getElementById(cells[2]);

         ded.style.backgroundColor = "white";

         var ded = document.getElementById(cells[1]);

         ded.style.backgroundColor = "white";

   

   cells[0]=cells[0];

   cells[1]=cells[0]+1;

   cells[2]=cells[0]+2;

   cells[3]=cells[0]+3;

   }

}

else if(ran==6)

{

  //alert(cells);

  

  if ((df[(cells[0]+1)]==0)&&(df[(cells[0]+1+cols)]==0)&&(df[(cells[0]+cols+2)]==0)&&((cells[3]+1)%cols!=0)&&((cells[0]-cells[1])==cols)&&((cells[2]-cells[1])==1)&&((cells[2]-cells[3])==cols))    

   {

   var ded = document.getElementById(cells[3]);

     ded.style.backgroundColor = "white";

   cells[1] = cells[0]+1;

   cells[2] = cells[1]+cols;

   cells[3] = cells[2]+1;

   }

   else if((df[(cells[0]+cols)]==0)&&(df[(cells[1]-cols)]==0)&&(df[(cells[1]-(2*cols))]==0)&&((cells[1]-cells[0])==1)&& ((cells[2]-cells[1])==cols)&& ((cells[3]-cells[2])==1) )

   {

   var ded = document.getElementById(cells[3]);

     ded.style.backgroundColor = "white";

   var ded = document.getElementById(cells[2]);

       ded.style.backgroundColor = "white";

       cells[1] = cells[0];

       cells[0] = cells[1]+cols;

       cells[2] = cells[1]+1;

       cells[3] = cells[2]-cols;

   }

}

else if(ran==7)

{

  //new Array( test2,test2-cols2,test2+1,test2+2,test2+2-cols2);

  

   if((df[(cells[0]+1)]==0)&&(df[(cells[0]+1-cols)]==0)&&(df[(cells[0]+1-(2*cols))]==0)&&((cells[0])%cols!=0)&&((cells[0]-cells[1])==cols)&&((cells[2]-cells[0])==1)&&((cells[3]-cells[2])==1)&&((cells[3]-cells[4])==cols))

   {

   var ded = document.getElementById(cells[3]);

       ded.style.backgroundColor = "white";

       var ded = document.getElementById(cells[4]);

       ded.style.backgroundColor = "white";

       cells[1]=cells[0]+1;

       cells[2]=cells[1]-cols;

       cells[4]=cells[2]-cols;

       cells[3]=cells[4]-1;

   }

   else if((df[(cells[1]-cols)]==0)&&(df[(cells[1]-cols-1)]==0)&&(df[(cells[1]-cols-2)]==0)&&(df[(cells[1]-2)]==0)&&((cells[0])%cols!=0)&&((cells[1]-cells[0])==1)&&((cells[2]-cells[4])==cols)&&((cells[4]-cells[3])==1)&&((cells[0]-cells[3])==2*cols))

   {

     

   var ded = document.getElementById(cells[0]);

       ded.style.backgroundColor = "white";

  

   cells[4]=cells[1];

   cells[3]=cells[4]-cols;

   cells[2]=cells[3]-1;

   cells[1]=cells[2]-1;

   cells[0]=cells[1]+cols;

   //alert(cells)

   

   }

   else if((df[(cells[0]+1)]==0)&&(df[(cells[0]+cols)]==0)&&(df[(cells[0]+(2*cols))]==0)&&(df[(cells[0]+(2*cols)+1)]==0)&&((cells[0]-cells[1])==cols)&&((cells[2]-cells[1])==1)&&((cells[3]-cells[2])==1)&&((cells[4]-cells[3])==cols))

   {

 

   var ded = document.getElementById(cells[3]);

       ded.style.backgroundColor = "white";

       var ded = document.getElementById(cells[4]);

       ded.style.backgroundColor = "white";

   cells[1]=cells[0]+1;

   cells[2]=cells[0]+cols;

   cells[3]=cells[2]+cols;

   cells[4]=cells[3]+1;

   }

   

   else if((df[(cells[0]-cols)]==0)&&(df[(cells[0]+1)]==0)&&(df[(cells[0]+2)]==0)&&(df[(cells[0]+2-cols)]==0)&&((cells[3]-cells[2])==cols)&&((cells[1]-cells[0])==1)&&((cells[3]-cells[2])==cols)&&((cells[4]-cells[3])==1))

   {

     var ded = document.getElementById(cells[2]);

       ded.style.backgroundColor = "white";

   var ded = document.getElementById(cells[3]);

       ded.style.backgroundColor = "white";

       var ded = document.getElementById(cells[4]);

       ded.style.backgroundColor = "white";

 

   cells[1]=cells[0]-cols;

   cells[2]=cells[0]+1;

   cells[3]=cells[2]+1;

   cells[4]=cells[3]-cols;

   }

}

   }

}

var temparray = new Array(test1,test1-cols,test1+1,test1+1-cols);

    var tran = 0;

    var tranc = 0;

    

function areset()

{

      if(finished == 0) // for time start

  {

   document.getElementById("tim").disabled =  false;

   document.getElementById("mtime").disabled =  false;

           document.getElementById("score1").disabled = false;

           document.getElementById("level1").disabled = false;

           document.getElementById("check2").disabled = false;

           document.op.level1.focus();

           

   if(firstmove == 0)

   {

   timer();

   firstmove++;

   }

      }

      

  cells = new Array(temparray.length);

  

  for( var xa=0; xa<temparray.length; xa++)

  {

     cells[xa] = temparray[xa];

    }

    

  ran   = tran;

  ranc  = tranc;

  

  if(level<=4)

  tran  = Math.round(Math.random()*6);

  else 

    tran  = Math.round(Math.random()*7);

    

  tranc = Math.round(Math.random()*8);

   // 123

//  tran=7;

  

  if(tran == 0)// 2x2 box

  {

    temparray = new Array(test1,test1-cols,test1+1,test1+1-cols);

  }

  else if(tran == 1)  ///L  bolow 1 col then  3 row 

  {

    temparray = new Array(test1,test1-cols,test1+1,test1+2);   

  }

  else if(tran == 2) ///L    3 row then  bolow 1 col 

  {

    temparray = new Array(test1,test1+1,test1+2,test1+2-cols);   

  }

  else if(tran == 3) // down T   3row and center up 1 col 

  {

    temparray = new Array(test1,test1+1,test1+1+cols,test1+2);   

  }

  else if(tran == 4)  // Z  down 1 col 2 row and up 1 col 

  {

    temparray = new Array(test1,test1-cols,test1+1,test1+1+cols);   

  }

  else if(tran == 5)//4 cell striaght line

  {

    

    temparray = new Array(test1,test1+1,test1+2,test1+3);

  }

  else if(tran == 6)// Z  up 1 cols and 2 row and down 1 cols

  {

    temparray = new Array(test1+cols,test1,test1+1,test1+1-cols);   

  }

  else if(tran == 7)//cup cell  only level 5

  {

    temparray = new Array(test1,test1-cols,test1+1,test1+2,test1+2-cols);

  }


  display_next();

     

  var fixed_time=fixtime+rowsclear*inc_time;   

  time_final=(fixed_time-timee)/1000;

     

  if((df[test1[0]]!= 1)&& (df[235]!=1)&& (time_final > 0.05))

  {

move();

  }

 

     if ((df[235]==1)||(time_final< 0.05))

      {

     document.getElementById("tim").disabled =  true;

document.getElementById("mtime").disabled =  true;

         document.getElementById("score1").disabled = true;

         document.getElementById("level1").disabled = true;

         document.getElementById("check2").disabled = true;     

     // for the getting the display code the header,footer and topscore

moves = score2;  //the total No. of tries can be displayed to score 

finished=1;

  }

 

}

function display_next()

{

var i,j;

var cols2=4;

var test2;

for (i=0; i<4; i++)

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

{

///df1[(i*4)+j]=0;

var dd = document.getElementById('xx'+((i*4)+j));

dd.style.backgroundColor = "#EEEEEE";//"B3FFFF";

}

switch(tran)

{

  

  

  case 0: test2=9;

  cells2 = new Array(test2,test2-cols2,test2+1,test2+1-cols2);

  break;

 

  case 1: test2=9;

  cells2 = new Array(test2,test2-cols2,test2+1,test2+2);

  break;


  case 2: test2=8;

  cells2 = new Array(test2,test2+1,test2+2,test2+2-cols2);

  break;

 

  case 3: test2=5;

  cells2 = new Array(test2,test2+1,test2+1+cols2,test2+2);

  break;

 

  case 4: test2=5;

  cells2 = new Array(test2,test2-cols2,test2+1,test2+1+cols2);

  break;

 

  case 5: test2=4;  

  cells2 = new Array( test2,test2+1,test2+2,test2+3);

  break;

 

  case 6: test2=5;

  cells2 = new Array(test2+cols2,test2,test2+1,test2+1-cols2);

  break;

 

  case 7: test2=9;  

      cells2 = new Array( test2,test2-cols2,test2+1,test2+2,test2+2-cols2);

  break;

 

}

for(var y=0; y<cells2.length; y++)

{

        var ded1 = document.getElementById('xx'+cells2[y]);

        ded1.style.backgroundColor = change_color(tranc);

    }

  }

  

function change_color(n)

{

   // n=6;

if (n==0) // brown

    {

  return "#A52A2A";

}

else if (n==1) // blue-violet

    {

  return "#8040FF";

}

else if (n==2)// green

    {

  return "#009F00"

}

else if (n==3)// blue

{

  return "#0000ff";  //#6677AA,,cABE62

}

else if (n==4)// Magenta

{

  return "#ff00ff";

}

else if (n==5) // purple

{

  return "#800080";

}

else if (n==6) // olive

{

  return "#808000";

}

else if (n==7)// Red

{

  return "#FF3B01";//FF3127C";

}

else if (n==8)// orange

{

  return "#FFAC01";

}

}

function refresh()

{

document.location.reload();

}

</script>

<tr><td bgcolor=white align=center valign=top> 

<form name=op method="post" action="index.php">

<strong><font color="#FF0000" size=3><b>The Game of Tetris لعبة تتريس</b></font></strong> <br>

<table  border=1>

    <tr> 

      <td > 

      

      <table style="border: 1px solid black;"  align=center  bgcolor= white>

      

<script language=javascript>

document.open("text/plain");

        var count = rows*cols;    

for(var i=0; i<rows; i++)

{

document.write("<tr>");

for(var j=0; j<cols; j++)

{

var pos = (count-cols)-(i*cols)+j;

if(pos == 274)

document.write("<td name=a"+pos+" id="+pos+" style=\"border: 1 px solid black; width:15px; height: 15px; font-size: 8px;\"><a style=\"text-decoration:none;\" href=&nbsp;&nbsp;</a></td>");

else

document.write("<td name=a"+pos+" id="+pos+" style=\"border: 1 px solid black; width:15px; height: 15px; font-size: 8px;\">&nbsp;</td>");

}

document.write("</tr>");

}

document.close();

</script>

       </table>


    </td>

      <td style="border: 1px solid black; background-color: #eceded "> <!--set bg for column two-->

  <table  align="center">

            <tr align="center"> 

                <td >

                

                <input type=button name="start11" id="start11" value="بدايه" onclick="areset()"  style="margin-right: 10px; color: #FF0000;  font-family: arial; font-weight: bold;  border: 1px dashed #008000;">

                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

<input type=button name="refresh1" id="refresh1" value=إعاده onclick=refresh() style="margin-right: 10px; color: #FF0000;  font-family: arial; font-weight: bold;  border: 1px dashed #008000;">

                

                <br><br>

                </td>

            </tr>

            <tr><td>

<b><font color=green size=2>اختار مستوى</font></b><br>

<input type="radio" id=myid1 name=myradio onclick="window.location.href='?level=1'">1

<input type="radio" id=myid2 name=myradio onclick="window.location.href='?level=2'">2

<input type="radio" id=myid3 name=myradio onclick="window.location.href='?level=3'">3

<input type="radio" id=myid4 name=myradio onclick="window.location.href='?level=4'">4

<input type="radio" id=myid5 name=myradio onclick="window.location.href='?level=5'">5

<br><br>

</td></tr>

            <tr> 

                <td >

               <b><font color=Green size=2>مستوي :</font></b> <input size=1 type=text id="level1" name=level1 value=0  style="color: red;  text-align: center; font-size: 16 px; font-family: arial; font-weight:  bold; border: 1px solid green;" disabled>  &nbsp;&nbsp;&nbsp;

                <b><font color=green size=2>تم مسح الصفوف :</font></b> <input size=4 type=button id="check2" name=sw value=0  style="color: red; font-size: 16 px; font-family: arial; font-weight: bold; border: 1px solid green;" disabled> <br> <br> 

                

                <strong><b><font color=green size=2>نتيجة :</font></b></strong> </b>  <input size=4 type=button id="score1" name=score1 value=0 style="color: red; font-size: 16 px; font-family: arial; font-weight: bold; border: 1px solid green;" disabled>&nbsp;&nbsp;&nbsp;

                &nbsp;&nbsp;<b><font color=green size=2>وقيت :</font></b>  <input type=button name=timename id=tim value=0 style="color: red; font-size: 16 px; font-family: arial; font-weight: bold; border: 1px solid green;"disabled>

                <br><br><br>

                <font color=green size=2>الوقت المتبقي :</font></b> <input type=button id="mtime" name=score11 value=60 style="color: red; font-size: 19 px; font-family: arial; font-weight: bold; border: 1px solid green;" disabled>&nbsp;&nbsp;&nbsp;<font color=green size=-1>ثواني</font>

                

                <br><br>

                </td>

            </tr>

            <tr> 

            <td align="center"> 

              <table border="0" bordercolor=red>

                <tr>

                  <td align="center">

  <table border="0"  bgcolor="#EEEEEE">

<div align=center>التالي</div>

<script language=javascript>

document.open("text/plain");    

    var rows1=4;

var cols1=4;  //B3FFFF

for(var i=0; i<rows1; i++)

{

document.write("<tr>");

for(var j=0; j<cols1; j++)

{

var pos1 =12-(i*cols1)+j;

document.write("<td  name=x"+pos1+" id=xx"+pos1+" width=16 height=16></td>");

}

document.write("</tr>");

}

document.close();


</script>

                  </table>

     </td>

                   </tr>

                </table>

  

  </td></tr>            

       </table> 

   </td></tr>            

       </table> 

<script language=javascript>    

switch(parseInt(level)) {

  case 1: document.getElementById("myid1").checked=true;

break;

      case 2: document.getElementById("myid2").checked=true;

break;      

      case 3: document.getElementById("myid3").checked=true;

break;      

      case 4: document.getElementById("myid4").checked=true;

break;      

      case 5: document.getElementById("myid5").checked=true;

break;      

}

document.op.level1.value=level;

document.op.sw.value=rowsclear;

document.op.score1.value=rowsclear*inc_score;

document.op.mtime.value=fixtime/1000;     

</script>     

</form>

</div>

المشاهده كود The Game of Tetris لعبة تتريس هنا

https://blog-hkrkoz.blogspot.com/p/game-of-tetris.html

وسلامتكم

اذا حبيت نسخ المقالهـ

author
  • اضافة تعليق
  • ليست هناك تعليقات:

    اضف تعليقك ممكن

    آلتآريخ هجري وميلآدي

    المتابعون