<?php
// Where abouts to send the form data
$source="m3.php";
// Printout the source code
if($_GET["show"]=="true") {
highlight_file($source);
};
echo "<html><head><title></title>";
echo "</head>\n<body>\n";
// Setup the global variables
$vararray = array("left","right","forward","back","map","facing","x","y","source");
$varstart = count($vararray);
$startmap = file("blankmap.txt");
$startper = file("perspect.txt");
$viewport = array();
$viewsize = 60;
$step=1;
if (isset($HTTP_POST_VARS['submit'])){
$step=2;
} else {
$step=1;
};
echo "<h1>Xeno</h1>\n";
echo "<h2>Map display beta 3</h2>\n";
echo "<hr>\n";
// Make viewport Display
for ($y=0;$y<=$viewsize ;$y++) {
$viewport [$y]="|";
for ($x=0;$x<=$viewsize ;$x++) {
if (($y==0)||($y==$viewsize)) {
$viewport [$y].="-";
} else {
$viewport [$y].=" ";
}
};
$viewport [$y].="|";
};
$viewport[0] = substr_replace($viewport[0], '+', 0, 1);
$viewport[0] = substr_replace($viewport[0], '+', -1, 1);
$viewport[$viewsize ] = substr_replace($viewport[$viewsize ], '+', 0, 1);
$viewport[$viewsize ] = substr_replace($viewport[$viewsize ], '+', -1, 1);
// Page to display if arriving for the first time (ie not submitting a form)
if ($step==1) {
$facing = 0;
$viewmap = $viewport;
echo "<p>\n";
echo "<form name=\"map\" action=\"".$source."\" method=\"post\">\n<table border=\"0\"><tr>";
echo "<td width=\"300\"> </td><td><p>The map</p>\n";
$sizeofmap = count($startmap);
$centreit = floor((count($viewmap)-$sizeofmap)/2);
for ($a=0;$a<$sizeofmap ;$a++){
$inserted = substr($startmap[$a],0,-2);
$viewmap[$centreit+$a] = substr_replace($viewport[$centreit+$a], $inserted , $centreit,strlen($inserted));
};
echo "<pre>\n";
for ($a=0;$a<=$viewsize ;$a++) {
echo $viewmap[$a]."\n";
};
echo "</pre>\n";
echo "<input type=\"submit\" name=\"submit\" value=\"Explore\"> <input type=\"reset\" name=\"reset\">";
echo "</td></tr></table>\n";
echo "</form>\n";
};
if ($step==2) {
$action = $_POST["submit"];
$facing = $_POST[$vararray[5]];
$viewmap = $viewport;
$maparray = array();
$lines = count($startmap);
$x = $_POST[$vararray[6]];
$y = $_POST[$vararray[7]];
for ($a=0;$a<=$lines;$a++){
$maparray[$a] = preg_split('//', $startmap[$a], -1, PREG_SPLIT_NO_EMPTY);
};
if (isset($x)==false){
$y = 5;
$x = 5;
$facing = 0;
$dx=0;
$dy=-1;
$direction="north";
};
switch ($facing) {
case 0:
$dx=0;
$dy=-1;
$direction="north";
break;
case 1:
$dx=1;
$dy=0;
$direction="east";
break;
case 2:
$dx=0;
$dy=1;
$direction="south";
break;
case 3:
$dx=-1;
$dy=0;
$direction="west";
break;
};
switch ($action) {
case $vararray[0]:
if ($facing>0) {
$facing--;
} else {
$facing = 3;
};
break;
case $vararray[1]:
if ($facing<3) {
$facing++;
} else {
$facing = 0;
};
break;
case $vararray[2]:
if (($x+$dx>0)and($x+$dx<26)and($y+$dy>0)and($y+$dy<26)) {
$x=$x+$dx;
$y=$y+$dy;
};
break;
case $vararray[3]:
if (($x-$dx>0)and($x-$dx<26)and($y-$dy>0)and($y-$dy<26)) {
$x=$x-$dx;
$y=$y-$dy;
};
break;
};
switch ($facing) {
case 0:
$dx=0;
$dy=-1;
$direction="north";
break;
case 1:
$dx=1;
$dy=0;
$direction="east";
break;
case 2:
$dx=0;
$dy=1;
$direction="south";
break;
case 3:
$dx=-1;
$dy=0;
$direction="west";
break;
};
$look = array(); // sight offsets
$count = 0;
for ($d=0;$d<3;$d++){ // distance from observer
if (($facing==1)or($facing==3)){
for ($c=6-(2-$d);$c>=(2-$d);$c--){ // cell right to left
$look["x"][$count]=$x+($dx*($d+1))-($dy*($c-3));
$look["y"][$count]=$y+($dy*($d+1))-($dx*($c-3));
$count++;
};
} else {
for ($c=(2-$d);$c<7-(2-$d);$c++){ // cell left to right
$look["x"][$count]=$x+($dx*($d+1))-($dy*($c-3));
$look["y"][$count]=$y+($dy*($d+1))-($dx*($c-3));
$count++;
};
};
};
echo "<p>\n";
echo "<form name=\"map\" action=\"".$source."\" method=\"post\">\n<table border=\"0\"><tr valign=\"top\">";
// Insert viewed squares into the display array
$sizeofmap = count($startmap);
$centreit = floor((count($viewmap)-$sizeofmap)/2);
for ($a=0;$a<$sizeofmap ;$a++){
$inserted = substr($startmap[$a],0,-2);
$viewmap[$centreit+$a] = substr_replace($viewport[$centreit+$a], $inserted , $centreit,strlen($inserted));
};
// Insert bolded characters for the viewed area
$sizeoffov = count($look["x"]);
$content = array();
for ($a=0;$a<$sizeoffov ;$a++){
$fx = $centreit + ($look["x"][$a]*2)+2;
$fy = $centreit + ($look["y"][$a]*2)+1;
$inserted = "*";
$content[$a] = substr($viewmap[$fy],$fx,1);
$viewmap[$fy] = substr_replace($viewmap[$fy], $inserted ,$fx,1);
};
// Insert the player's location
$fx = $centreit + ($x*2)+2;
$fy = $centreit + ($y*2)+1;
$viewmap[$fy] = substr_replace($viewmap[$fy], "@",$fx,1);
// Process 3D View
$search = array("/0/","/1/","/2/","/3/","/4/","/5/","/6/","/7/","/8/","/9/","/a/","/b/","/c/","/d/","/e/");
$offset = floor((strlen($view3d[1])-strlen($startper[1]))/2);
$perheight = count($startper);
$viewper=preg_replace($search,$content,$startper);
echo "<td><p>The map</p>\n";
echo "<span style=\"font-size:6pt;margin:0pt;padding:0pt;line-height:4pt\"><pre>\n";
for ($a=0;$a<=$viewsize ;$a++) {
echo $viewmap[$a]."\n";
};
echo "</pre></span>\n";
echo "<p>Facing : ".$direction."</p>\n";
echo "</td><td><p>Exploring the Map-</p><hr>\n<table><tr>";
for ($a=0;$a<4;$a++){
echo "<td><input type=\"submit\" name=\"submit\" value=\"".$vararray[$a]."\"></td>";
};
echo "</tr></table>\n";
echo "</td><td><p>3D View</p>\n";
echo "<span style=\"font-size:6pt;margin:0pt;padding:0pt;line-height:4pt\"><pre>\n";
for ($a=0;$a<=$perheight;$a++) {
echo $viewper[$a]."\n";
};
echo "</pre></span>\n";
echo "<p>Co-ordinates ";
echo "X: ".$x." | Y: ".$y."</p>\n";
echo "</tr>\n<tr><td><p>Map :-<br>\n";
echo "<input type=\"submit\" name=\"submit\" value=\"Explore\"> <input type=\"reset\" name=\"reset\">";
echo "</td></tr></table>\n";
echo "<input type=\"hidden\" name=\"".$vararray[5]."\" value=\"".$facing."\">\n";
echo "<input type=\"hidden\" name=\"".$vararray[6]."\" value=\"".$x."\">\n";
echo "<input type=\"hidden\" name=\"".$vararray[7]."\" value=\"".$y."\">\n";
echo "</form>\n";
echo "<p>Debug info</p>\n";
// echo "<p>Map Array</p>\n";
// print_r ($maparray);
// echo "<p>Map Array</p>\n";
// print_r ($startmap);
// echo "<p>Cells viewed</p>\n";
// echo "<p>X offset</p>\n";
// print_r ($look["x"]);
// echo "<p>Y offset</p>\n";
// print_r ($look["y"]);
// echo "<p>Square in front</p>\n";
// echo "<p>|".$maparray[$x+$dx+$dx][$y+$dy+$dy]."|</p>\n";
};
?>
<p>View the <A HREF="<?php echo "$source?show=true" ?>">source</A>.</p>
</body>
</html>
View the source.