pengu Posted July 28, 2009 Share Posted July 28, 2009 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 More sharing options...
xtopolis Posted July 28, 2009 Share Posted July 28, 2009 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. Link to comment https://forums.phpfreaks.com/topic/167730-array-help-general-help/#findComment-884526 Share on other sites More sharing options...
pengu Posted July 28, 2009 Author Share Posted July 28, 2009 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. 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? Link to comment https://forums.phpfreaks.com/topic/167730-array-help-general-help/#findComment-884537 Share on other sites More sharing options...
pengu Posted July 28, 2009 Author Share Posted July 28, 2009 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>"; ?> Link to comment https://forums.phpfreaks.com/topic/167730-array-help-general-help/#findComment-884597 Share on other sites More sharing options...
xtopolis Posted July 28, 2009 Share Posted July 28, 2009 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. Link to comment https://forums.phpfreaks.com/topic/167730-array-help-general-help/#findComment-884666 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.