Array help

I am trying to make a game using php/mysql.

I’ve been contemplating in my tiny brain and limited knowledge exactly how to solve a specific problem moving across the grid, which is moving from one planet to another. I will try and explain what I am trying to achieve.
The rule is that a planet can move to any other planet, provided that there is clear path i.e. all the planets along the way are owned by the same player. So I guess the best way to achieve this is with any given planet find its neighbour 1 square away and so on.

I have a database with a table (only mentioning relevant one) that contains details of a planet including x/y coordinates.


I have a grid map divided evenly into 8 squares by 15 squares.
Within many of these squares (not all) is a planet.
From any starting planet I wish display a path to any other planet

So far i have created a query to find all the planets x/y coordinates and put the results into an array.

[code]$_SESSION[‘Player’]= ‘1’;
$data = array();

$colname_test = “-1”;
if (isset($_SESSION[‘Player’])) {
$colname_test = (get_magic_quotes_gpc()) ? $_SESSION[‘Player’] : addslashes($_SESSION[‘Player’]);
mysql_select_db($database_swb, $swb);
$query_test = sprintf(“SELECT PlanetName, Xcoordinate, Ycoordinate FROM planet WHERE PlayerID = %s”, $colname_test);
$test = mysql_query($query_test, $swb) or die(mysql_error());
$row_test = mysql_fetch_assoc($test);
$totalRows_test = mysql_num_rows($test);

$data[] = $row_test;
while ($row_test = mysql_fetch_assoc($test));

Thats as far as I have got. I need to determine from a given planet which planets they can move to i.e. as long as there is a clear path from one planet to another (all owned by the same player).

If somebody could please help me I’d be very grateful.

Thank you

Sponsor our Newsletter | Privacy Policy | Terms of Service