Jump to content

Help with this CODE!!!


Emperio

Recommended Posts

<?php
include 'connect.php';
session_start();
?>
<link rel="stylesheet" href="style.css" type="text/css">
<?php
//game map test
    $player=$_SESSION['player'];
    $showlink=0;
    $sfield="SELECT * from km_sfield";
    $sfield2=mysql_query($sfield) or die(mysql_error());
    while ($sfield3=mysql_fetch_array($sfield2)) {
    $sfieldy[]=$sfield3[y];
    $sfieldx[]=$sfield3[x];
    $sfieldname[]=$sfield3[name];
    $sfieldclss[]=$sfield3[clss];
    $sfieldid[]=$sfield3[iD];
}
    $warfield="SELECT * from km_users";
    $warfield2=mysql_query($warfield) or die(mysql_error());
    while ($warfield3=mysql_fetch_array($warfield2)) {
    $warfieldmby[]=$warfield3[mby];
    $warfieldmbx[]=$warfield3[mbx];
    $warfieldmbhp[]=$warfield3[hp];
    $warfieldname[]=$warfield3[playername];
}
//set the grid size
$grid_y = (int)1000;
$grid_x = (int)1000;

//x and y rows to display at once
$display_rows = (int)5;

//default display cordinate
$x = (int)1;
$y = (int)1;

$param_x = $_REQUEST["xcord"];
$param_y = $_REQUEST["ycord"];

if (isset($param_x) && isset($param_y)) {
    //validate that the parameter is a legit point
    if (($param_x <= $grid_x) && ($param_x >= 1) && ($param_y <= $grid_y) &&($param_y >= 1)) {
        $x = (int)$param_x;
        $y = (int)$param_y;
    }
}

//the grid position desired will be set to display in the center of the viewable grid
$display_half = round($display_rows / 2);
$other_half = $display_rows - $display_half;

//to display the target in the middle, you have to get the number of rows to display before and after it.
//some simple math to take care of that.
$start_x = ($x - $display_half) +1;
$end_x = $x + $other_half;

//if the $start_x variable is less than 1 the grid would be in the negatives. so set it to 1
if ($start_x < 1) {
    $start_x = 1;
    $end_x = $display_rows;
} else
//if $end_x is off the grid we have to compensate and add the remaining rows to the start.
if ($end_x > $grid_x) {
    $extra = $end_x - $grid_x;
    $end_x = $grid_x;
    
    $start_x = $start_x - $extra;
}

//same applies for the y axis
$start_y = ($y - $display_half) +1;
$end_y = $y + $other_half;

if ($start_y < 1) {
    $start_y = 1;
    $end_y = $display_rows;
} else
if ($end_y > $grid_y) {
    $extra = $end_y - $grid_y;
    $end_y = $grid_y;
    
    $start_y = $start_y - $extra;
}

//showing the current parameters
echo "<font color='red'><p align='center'><B>X $x - Y $y</B></p></font><br>";

?>

<table id="map" width="700" height="700" cellspacing="1" cellpadding="0" border="1" hspace='60'>
<?php
//these 2 for loops represent the y and x axis
//using the data collected above the loops will properly display the grid
for ($Ty = $start_y; $Ty <= $end_y; $Ty++) {
    //start new row
    echo '<tr>';
    for ($Tx = $start_x; $Tx <= $end_x; $Tx++) {
        //show grid
        DisplayGrid($Tx,$Ty);
    }
    echo '</tr>';
}

?>
</table>
<?php
function DisplayGrid($gridx,$gridy) {
    global $x, $y, $player, $sfieldx, $sfieldy, $sfieldclss, $sfieldname, $warfieldmby, $warfieldmbhp, $warfieldmbx, $warfieldname, $player;
$background='background="http://conquerorsofsanvia.890m.com/background/grass.gif"';
$background2='background="http://conquerorsofsanvia.890m.com/background/dirt.gif"';
$imgsrc="<a style='line-height:1em;width:100%;height:300%;display:block;' href='grid.php?xcord=$gridx&ycord=$gridy\'>";
$num_position=count($sfieldx);
$num_position2=count($warfieldname);
for ($i = 0; $i < $num_position; $i++){
for ($ii = 0; $ii < $num_position2; $ii++){
if ($warfieldmby[$ii]==$gridy && $warfieldmbx[$ii]==$gridx)
{
    $imgsrc ="<center><a href='grid.php?xcord=$gridx&ycord=$gridy\'><img src='http://warofnations.freehostia.com/images/barracks.gif' border='0' width='50' height='50'><br>$warfieldname[$ii]</center></a>";
}
}
    if ($gridx==$sfieldx[$i] && $gridy==$sfieldy[$i])
    {
if ($sfieldclss[$i]=='Archers')
    {
    $imgsrc ="<center><a href='grid.php?xcord=$gridx&ycord=$gridy\'><img src='http://warofnations.freehostia.com/images/archer.gif' border='0' width='50' height='50'><br>$sfieldname[$i]</a></center>";
    }
if ($sfieldclss[$i]=='Swordsman')
    {
    $imgsrc ="<center><a href='grid.php?xcord=$gridx&ycord=$gridy\'><img src='http://warofnations.freehostia.com/swordsman.gif' border='0' width='50' height='50'><br>$sfieldname[$i]</a></center>";
    }
if ($sfieldclss[$i]=='Cavalry')
    {
    $imgsrc ="<center><a href='grid.php?xcord=$gridx&ycord=$gridy\'><img src='http://warofnations.freehostia.com/images/cavalry.gif' border='0' width='50' height='50'><br>$sfieldname[$i]</a></center>";
    }
if ($sfieldclss[$i]=='Pikesman')
    {
    $imgsrc ="<center><a href='grid.php?xcord=$gridx&ycord=$gridy\'><img src='http://warofnations.freehostia.com/images/pikeman.gif' border='0' width='50' height='50'><br>$sfieldname[$i]</a></center>";
    }
    }
    }
if ($gridy<20)
{
    echo "<div><td $background width='50' height='50'>$imgsrc</div></td>";
}
else
{
    echo "<div><td $background2 width='50' height='50'>$imgsrc</div></td>";
}
if ($gridx<20)
{
    echo "<div><td $background width='50' height='50'>$imgsrc</div></td>";
}
else
{
    echo "<div><td $background2 width='50' height='50'>$imgsrc</div></td>";
}
}
$num_position2=count($sfieldx);
      print "<table class='maintable'><tr class='headline'><td><center>Command Center</center></td></tr>";
      print "<tr class='mainrow'><td>";
for ($a = 0; $a < $num_position2; $a++){
if ($sfieldx[$a]==$x && $sfieldy[$a]==$y && $sfieldname[$a]==$player)
      {
      print "<html<a href='' onClick=MyWindow=window.open('http://warofnations.freehostia.com/command.php?id=$sfieldid[$a]&ycu=0&xcr=0&xcl=0&ycd=0','MyWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=200,height=600,left=50,top=50'); return false;>Command Selected Soldier</a>";
      }
      }
      print "Each unit contains a squad of 100 units from the same class.<br>";
      print "<form action='dplsoldiers.php' method='post'>";
      print "<select name='class'>";
      $class1="SELECT * from km_soldierclass order by class asc";
      $class2=mysql_query($class1) or die("Could not select Monster");
      while ($class3=mysql_fetch_array($class2))
      {
        print "<option>$class3[class]</option>";
      }
      print "</select><br>";
      print "<input type='submit' name='submit' value='Deploy'></form>";
      print "Each unit contains a squad of 100 units from the same class.<br>";
      print "<form action='makebase.php?xcord=$x&ycord=$y' method='post'>";
      print "<input type='submit' name='submit' value='Create Kingdom'></form>";
      print "</td></tr></table>";
?> 

This code is to make a graphical map, which is used in my mmorpg game....

But its not working well with the last code i putted in..

I wanted to make for example all tiles outisde y and x as 20 dirt tiles and all tiles inside 20 grass tiles

well y is working as it should but x is showing everything twice as you see in this picture:

naamlooscw8.jpg

 

(edited to replace tags with


tags)

Link to comment
https://forums.phpfreaks.com/topic/140110-help-with-this-code/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.