Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <body>
- <?php
- if((!empty($_GET['mapsize']))){
- //header('Content-type: text/xml');
- $generatedIslands = 0;
- $mapSize = $_GET['mapsize'];
- $islands = round($mapSize / 6);
- $maxIslandSize = round($mapSize / 6);
- $tileArray;
- $grass = "grass.jpg";
- $sand = "sand.jpg";
- $water = "water.jpg";
- $tile = "";
- function generateWorld(){
- for($row = 0; $row < $mapSize; $row++){
- for($cell = 0; $cell < $mapSize; $cell++){
- $tile = $water;
- $tileArray[$row][$cell] = $tile;
- }
- }
- for($generatedIslands = 0; $generatedIslands < $islands; $generatedIslands++){
- generateIslands();
- }
- echo "<table cellpadding='0' cellspacing='0'>";
- for($row = 0; $row < $mapSize; $row++){
- echo "<tr>";
- for($cell = 0; $cell < $mapSize; $cell++){
- $tile = $tileArray[$row][$cell];
- echo "<td>";
- echo "<img src='".$tile."'>";
- echo "</td>";
- }
- echo "</tr>";
- }
- echo "</table>";
- }
- function generateIslands(){
- $x = rand(0, ($mapSize - $maxIslandSize));
- $y = rand(0, ($mapSize - $maxIslandSize));
- $size = rand(4, ($maxIslandSize));
- for($checkY = 0; $checkY < $size; $checkY++){
- for($checkX = 0; $checkX < $size; $checkX++){
- if($tileArray[$x + $checkX][$y + $checkY] != $water){
- generateIslands();
- }
- }
- }
- for($rows = 0; $rows < $size; $rows++){
- for($cells = 0; $cells < $size; $cells++){
- if($rows == 0 || $rows == $size-1 || $cells == 0 || $cells == $size-1){
- $tile = $sand;
- } else {
- $tile = $grass;
- }
- $tileArray[$y + $rows][$x + $cells] = $tile;
- }
- }
- }
- generateWorld();
- }
- ?>
- </body>
- </html>
Add Comment
Please, Sign In to add comment