<?
//ob_implicit_flush();
class queen{
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 init($x,$y){
for($i=7;$i>=0;$i--){
for($j=0;$j<8;$j++){
if(($i==$x) and ($j==$y)){
$this->Table[$x][$y]=2;
$this->proc($i,$j);
}
}
}
// echo "<script>document.body.innerHTML='';</script>";
}
function proc($x,$y){
for($i=0;$i<8;$i++){
$this->Table[$x][$i]=1;
$this->Table[$i][$y]=1;
if(($x+$i<8) or ($y+$i<8))
$this->Table[$x+$i][$y+$i]=1;
if(($x-$i>=0) or ($y-$i>=0))
$this->Table[$x-$i][$y-$i]=1;
if(($x-$i>=0) or ($y+$i<8))
$this->Table[$x-$i][$y+$i]=1;
if(($x+$i<8) or ($y-$i>=0))
$this->Table[$x+$i][$y-$i]=1;
}
}
function show(){
for($i=7;$i>=0;$i--){
for($j=0;$j<8;$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=7;$i>=0;$i--){
echo "<table border=1 cellpadding='0' cellspacing='0'><tr>";
for($j=0;$j<8;$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];
}
}
$game=new queen();
//while(1){
$x=mt_rand(0,7);
$y=mt_rand(0,7);
$game->init($x,$y);
$game->show();
$game->ToDo();
echo '$x='.$x."<BR>";
echo '$y='.$y;
//}
?>