value NOT $this->$value; //Our psuedo enums. define("TileType", 0); define("TileValue", 1); define("TileWall", 'w'); //User-placed-wall. define("TileEmpty", 'o'); define("TileStart", 's'); define("TileFinish", 'f'); define("TileCheckpoint", 'c'); define("TileRock", 'r'); define("TileTeleportIn", 't'); define("TileTeleportOut", 'u'); define("TileUnbuildable", 'q'); define("TileSinglePath", 'x'); class map { public $name; public $tiles; public $teleports; public $checkpoints; public $height; public $width; public $isBlind; public $isMultiPath; public $code; public function __construct($code = NULL) { if ($code !== NULL) $this->applyMapFromOldCode($code); //echo "Construct complete"; } public function applyMapFromOldCode($code) { //echo "decoding mapcode: [$code]"; unset($this->tiles); $tmp = explode( ":", $code); $headers = explode( '.', $tmp[0]); $splitCode = explode( '.', $tmp[1]); $dimensions = explode( 'x', $headers[0]); $this->width = $dimensions[0]; $this->height = $dimensions[1]; $this->name = $headers[5]; //Map Name //Make assumptions: $this->isMultiPath = false; $this->isBlind = false; $this->teleports = 0; $this->checkpoints = 0; $t = -1; $index = 0; for ($y = 0; $y < $this->height; $y++) { //Number of Rows for ($x = 0; $x < $this->width; $x++) { //Number of Columns $t++; $next = substr($splitCode[$index], 0, strlen($splitCode[$index]) - 1); //Are we at the next target, if there is one. if ($next == $t AND $next != '') { //Update tile. $type = substr($splitCode[$index], -1, 1); $value = ''; // Count checkpoints and etc. switch ($type) { case 'S': $this->isMultiPath = true; $value = 2; $type = TileStart; break; case 'w': $value = ''; $type = Tilewall; break; case 'r': $value = ''; $type = TileRock; break; case 'R': $value = 2; $type = TileRock; break; case 'q': $value = 3; $type = TileRock; break; //Probably a more intelligent way to do this; but it works: case 'a': $value = ''; $type = TileCheckpoint; break; case 'b': $value = 2; $type = TileCheckpoint; break; case 'c': $value = 3; $type = TileCheckpoint; break; case 'd': $value = 4; $type = TileCheckpoint; break; case 'e': $value = 5; $type = TileCheckpoint; break; case 't': $value = ''; $type = TileTeleportIn; break; case 'm': $value = 2; $type = TileTeleportIn; break; case 'g': $value = 3; $type = TileTeleportIn; break; case 'i': $value = 4; $type = TileTeleportIn; break; case 'k': $value = 5; $type = TileTeleportIn; break; case 'u': $value = ''; $type = TileTeleportOut; break; case 'n': $value = 2; $type = TileTeleportOut; break; case 'h': $value = 3; $type = TileTeleportOut; break; case 'j': $value = 4; $type = TileTeleportOut; break; case 'l': $value = 5; $type = TileTeleportOut; break; } $this->tiles[$y][$x][TileType] = $type; $this->tiles[$y][$x][TileValue] = $value; $index++; //Start from 0 again. $t = -1; } else { $this->tiles[$y][$x][TileType] = TileEmpty; } } } } //Creates the map based on a new code. public function applyMapFromNewCode($code) { $this->code = $code; } //Outputs the new code. public function getCode() { //If we already have the code on hand... if ($this->code) return $this->code; //Otherwise we need to build the code: } //Other "Magical" functions. public function __toString() { return $this->name; } } ?>