用PHP写的方块变换模型

<?
//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();
}
?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值