Jump to content

Array Help.. General Help


pengu

Recommended Posts

Err, I'm not 100% sure this is even possible, but what the hell, I'll ask.

 

<?php

$x = 10;
$y = 5;

$map[0] = "xxxxxxxxxx<br />";
$map[1] = "x........x<br />";
$map[2] = "x........x<br />";
$map[3] = "x........x<br />";
$map[4] = "xxxxxxxxxx<br />";

foreach($map as $map) {
	echo $map;
}

?>

 

I'm trying to create a "map" with an array, I want it based on the dimensions.. x and y. "x" in the map is to represent a "wall".  The "." are floors that can be walked over for example.  Is this theory in my head even possible, I need something similar to this anyways for my project (think of it as a mini-game), you're given an x and y coordinate yourself and it wont be able to clash with the "maps" dimensions bla bla.Then with a HTML form, you can have up, down, left and right.  And I want say a "p" to represent the player.

 

My main question I'm asking here.. is it possible?

Can you place variables on the page based on dimensions.

 

..otherwise I'll just do it with text, which I know is possible.

Link to comment
https://forums.phpfreaks.com/topic/167730-array-help-general-help/
Share on other sites

Yes it's possible.

 

What are you meaning anyway?  Creating an image to represent a map based on coordinate data?  definitely..  you'll need to be a lot more specific.

 

I shall try to be more specific.  Let's start with this image.

example.jpg

 

I want this to be a TOP-DOWN view of this map/place whatever you would like to call it.  I'm also wondering if the letters "x" "f" "y" and "." could be replaced with images.  Now what I want to do  is I don't want "F" to actually be on that map, I want it to be given random coordinates between 12 and 6 and placed accordingly on the map.  Going on the limits of 12 and 6.

 

Does this make sense?

Ok, found preg_replace. Came up with this so far.  But I want "f" to be randomly placed around the map and not to clash with a "x" (wall).

 

!

 

<?php

$string[0] = 'xxxxxxxxxx<br />';
$string[1] = 'xooxooooox<br />';
$string[2] = 'xofxooooox<br />';
$string[3] = 'xoxxooooox<br />';
$string[4] = 'xoooooooox<br />';
$string[5] = 'xoooooofox<br />';
$string[6] = 'xyooooooox<br />';
$string[7] = 'xxxxxxxxxx<br />';

$patterns[0] = '/x/';
$patterns[1] = '/o/';
$patterns[2] = '/f/';
$patterns[3] = '/y/';

$replacements[0] = '<img src="images/x.jpg">';
$replacements[1] = '<img src="images/dot.jpg">';
$replacements[2] = '<a href="map.php?q=female"><img border="0" src="images/f.jpg"></a>';
$replacements[3] = '<img src="images/you.jpg">';

echo "<center>";

foreach($string as $string) {
echo preg_replace($patterns, $replacements, $string);
}

echo "</center>";


?>

Can you give me coordinate data instead?  Are you hand crafting these maps at a set size, and then randomly placing the player and women, as long as they're not in the X areas?

 

I can kind of see what you're doing with the strings, but I'd do much better with math values for wall locations, etc I think.  If you put the data into an array, you could EASILY loop through it, and place images in a grid instead of using preg_replace.

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.