用PHP写的方块变换模型

来源:互联网 发布:easyui ssh项目源码 编辑:程序博客网 时间:2024/04/30 10:13

<?
//ob_implicit_flush();
class dgt_game{
 var $bmp0="<td><img src='B0.JPG'></td>";
 var $bmp1="<td><img src='B1.JPG'></td>";

 var $Table=array();
 var $save_Table=array();  //保存最后一次状态

 var $fk=array(); //模块形状
 var $row=0;
 var $col=0;

 function J_1($row,$col){
  $this->fk[$row+0][$col+0]=1;
  $this->fk[$row+0][$col+1]=1;
  $this->fk[$row+1][$col+1]=1;
  $this->fk[$row+2][$col+1]=1;
 }
 function J_2($row,$col){
  $this->fk[$row+0][$col+0]=1;
  $this->fk[$row+0][$col+1]=1;
  $this->fk[$row+0][$col+2]=1;
  $this->fk[$row+1][$col+0]=1;
 }
 function J_3($row,$col){
  $this->fk[$row+0][$col+0]=1;
  $this->fk[$row+1][$col+0]=1;
  $this->fk[$row+2][$col+0]=1;
  $this->fk[$row+2][$col+1]=1;
 }
 function J_4($row,$col){
  $this->fk[$row+0][$col+2]=1;
  $this->fk[$row+1][$col+0]=1;
  $this->fk[$row+1][$col+1]=1;
  $this->fk[$row+1][$col+2]=1;
 }
 function input_fk($string){
  switch($string){
   case "J_1":$this->J_1($this->row,$this->col);break;
   case "J_2":$this->J_2($this->row,$this->col);break;
   case "J_3":$this->J_3($this->row,$this->col);break;
   case "J_4":$this->J_4($this->row,$this->col);break;
  }
 }
 
 function save_table(){
  for($i=10;$i>=0;$i--){
   for($j=0;$j<18;$j++){
    if($this->Table[$i][$j]==1)
     $this->save_Table[$i][$j]=$this->Table[$i][$j];
   }
  }
 }
 function save_table_show(){
  for($i=10;$i>=0;$i--){
   for($j=0;$j<18;$j++){
    if($this->Table[$i][$j]==1)
     echo $this->save_Table[$i][$j];
//     $this->save_Table[$i][$j]=$this->Table[$i][$j];
   }
  }
 }

 function init(){
  for($i=10;$i>=0;$i--){
   for($j=0;$j<18;$j++){
     $this->Table[$i][$j]=$this->save_Table[$i][$j];
     $this->fk[$i][$j]=0;
   }
  }
  echo "<script>document.body.innerHTML='';</script>";
 }

 function show(){
  for($i=10;$i>=0;$i--){
   for($j=0;$j<18;$j++){
    if(($this->fk[$i][$j]==1) or ($this->Table[$i][$j]==1)){
     $this->Table[$i][$j]=1;
     if($this->fk[$i+1][$j]==$this->Table[$i][$j])
      $this->Table[$i+1][$j]=1;
    }else
     $this->Table[$i][$j]=0;
   }
  }
 }

 function  ToDo(){
  for($i=10;$i>=0;$i--){
   echo "<table border=0 cellpadding='0' cellspacing='0'><tr>";
   for($j=0;$j<18;$j++){
    if($this->Table[$i][$j]==0){
     echo $this->bmp0;
    }else{
     echo $this->bmp1;
    }
//    $this->save_Table[$i][$j]=$this->Table[$i][$j];
   }
   echo "</tr>";
  }
  echo "</table>";
//  echo $this->Table[$i][$j];
 }
}

for($i=0;$i<255;$i++){
 echo $i;
}
$game=new dgt_game();
/*
for($i=10;$i>=0;$i--){
 sleep(1);
 $game->init();
 $game->row=3;
 $game->col=4;
 $j=mt_rand(1,4);
 $game->input_fk("J_".$j);
 $game->show();
 $game->ToDo();
}
*/
while(1){
 for($i=10;$i>=0;$i--){
 // usleep(200000);
  sleep(1);
  $game->init();
  $game->row=$i;
  $game->col=10;
  $j=mt_rand(0,3);
  $game->input_fk("J_".($j+1));
  $game->show();
  $game->ToDo();
  echo $i;
 }
 echo "<HR>";
 $game->save_table();
 $game->save_table_show();
}
?>

原创粉丝点击