Hi,
I\'ve create a Class Cube which is a object that contain 6 faces in a cube and got functions to turn the cubes in all directions.
Here is the code of cube.obj :
PHP:--------------------------------------------------------------------------------
class Cube {
var $order;
function Cube($a, $b, $c, $d, $top, $base) {
$this->order=array($a, $b, $c, $d, $top, $base);
}
function getFront() {
return $this->order[0];
}
function moveUp() {
$this->order = array($this->order[4], $this->order[1], $this->order[5], $this->order[3], $this->order[2], $this->order[0]);
}
function moveDown() {
$this->order = array($this->order[5], $this->order[1], $this->order[4], $this->order[3], $this->order[0], $this->order[2]);
}
function moveLeft() {
$this->order = array($this->order[1], $this->order[2], $this->order[3], $this->order[0], $this->order[4], $this->order[5]);
}
function moveRight() {
$this->order = array($this->order[3], $this->order[0], $this->order[1], $this->order[2], $this->order[4], $this->order[5]);
}
function getOrder() {
return $this->order;
}
function printCube() {
?>
<table width=600 border=1 cellspacing=2 cellpadding=2>
<tr>
<td><?=$this->order[4]?></td>
<td> </td>
<td> </td>
<td> </td></tr>
<tr>
<td><?=$this->order[0]?></td>
<td><?=$this->order[1]?></td>
<td><?=$this->order[2]?></td>
<td><?=$this->order[3]?></td></tr>
<tr>
<td><?=$this->order[5]?></td>
<td> </td>
<td> </td>
<td> </td></tr></table>
<?
}
}
And this is the test Program : test.php :
PHP:--------------------------------------------------------------------------------
<?
require (\"cube.obj\");
if (!$c)
$c = new Cube(\"Front\", \"Right\", \"Back\", \"Left\", \"Top\", \"Base\");
switch ($a) {
case \"up\" :
$c->moveUp();
break;
case \"down\" :
$c->moveDown();
break;
case \"left\" :
$c->moveLeft();
break;
case \"right\" :
$c->moveRight();
break;
}
echo \"[ <a href=$PHP_SELF?a=up>UP</a> ] \";
echo \"[ <a href=$PHP_SELF?a=down>DOWN</a> ] \";
echo \"[ <a href=$PHP_SELF?a=left>LEFT</a> ] \";
echo \"[ <a href=$PHP_SELF?a=right>RIGHT</a> ] <br>\";
$c->printCube();
?>
But how to pass the Cube object between Page ??
I\'ve tried to change the link to ?a=top&c=\$c
But doesn\'t work ?
Please advise how can i pass the object, so i can keep rotate the cube in all directions!
Thanks