开发者

php progressive map generation

Hello I've been trying for couple of days to write a script to generate a progressive map using PHP. What I'm trying to achieve but with no success would be something like this:

php progressive map generation

In short I have a "node" defined as 5,6 on xy ( as an example ) then randomly add a random number of "players" close to the "node". From here I w开发者_JS百科ant to connect the closest "player" to the node while having a list of criteria that will determine to which node the "player" will be connected (how many connections are for that node, what's the max number of connections etc ). I haven't written any code yet because I don't know exactly where to start or with what should I start since I'm not that great with math only pretty good with PHP. Andy ideas or advice any help is welcomed.


Well, I think you want to create a topology of the network, having as root the internet provider.

So, I'm thinking that the best way is to create a graph. The root is the red dot. Than the players attached to it. Than the players attached to the already attached players and so on.

something like this :

            *
         /  |  \
         O  O   O
       / |  |    |
      O  O  O    O

now. Each node of the graph can have some info associated to it: type: player | node coordX : 5 coordY: 6 etc...

Displaying the map will just mean that you can walk the tree and draw the elements based on their positions, you can draw lines based on the connections.

If your topology conains cycles, that is player1 connected to player2 which is connected to player3 ..... player n which is connected to player1, than you need a graph structure.

If i described correctly your problem, than you should find some articles about tree / graph algorithm, how to parse them, etc.. and should be able to do your job.


I made a game board 10 x 10 with interacting color elimination.

I use an array to first define the grid. Below creates an array with 100 object slots.

SAMPLE: Game at http://apps.facebook.com/AnotherGrid/ Just login to play and see the grid in action. This array generates 1000 grids for my game dynamicly.

<?php
$lvl = array(
/* row0 */' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
/* row1 */' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
/* row2 */' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
/* row3 */' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
/* row4 */' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
/* row5 */' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
/* row6 */' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
/* row7 */' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
/* row8 */' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
/* row9 */' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '
);
?>

then i used:

foreach ($lvl as $key => $value) {
echo '<div class="grid" id="'.$key.'"onclick="null">'.$value.'</div>';
}

to write the grid, and used CSS to define display: inline-block to each div.

For positioning of each is based on the position of the array object. < div id="0" > would be the very first square upto 99.

<?php
$lvl = array(
/* row0 */'black', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
/* row1 */' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
/* row2 */' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
/* row3 */' ', ' ', ' ', ' ', 'yellow', ' ', ' ', ' ', ' ', ' ',
/* row4 */' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
/* row5 */' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
/* row6 */' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
/* row7 */' ', ' ', ' ', 'blue', ' ', ' ', ' ', 'green', ' ', ' ',
/* row8 */' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
/* row9 */' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '
);
?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜