Guest User

Untitled

a guest
Jul 16th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.68 KB | None | 0 0
  1. <html>
  2. <body>
  3. <?php
  4.     if((!empty($_GET['mapsize']))){
  5.         //header('Content-type: text/xml');
  6.         $generatedIslands = 0;
  7.         $mapSize = $_GET['mapsize'];
  8.         $islands = round($mapSize / 6);
  9.         $maxIslandSize = round($mapSize / 6);
  10.         $tileArray;
  11.         $grass = "grass.jpg";
  12.         $sand = "sand.jpg";
  13.         $water = "water.jpg";
  14.         $tile = "";
  15.        
  16.         function generateWorld(){
  17.             for($row = 0; $row < $mapSize; $row++){
  18.                 for($cell = 0; $cell < $mapSize; $cell++){
  19.                     $tile = $water;
  20.                     $tileArray[$row][$cell] = $tile;
  21.                 }
  22.             }
  23.            
  24.             for($generatedIslands = 0; $generatedIslands < $islands; $generatedIslands++){
  25.                 generateIslands();
  26.             }
  27.            
  28.             echo "<table cellpadding='0' cellspacing='0'>";
  29.             for($row = 0; $row < $mapSize; $row++){
  30.                 echo "<tr>";
  31.                 for($cell = 0; $cell < $mapSize; $cell++){
  32.                     $tile = $tileArray[$row][$cell];
  33.                     echo "<td>";
  34.                     echo "<img src='".$tile."'>";
  35.                     echo "</td>";
  36.                 }
  37.                 echo "</tr>";
  38.             }
  39.             echo "</table>";
  40.         }
  41.        
  42.         function generateIslands(){
  43.             $x = rand(0, ($mapSize - $maxIslandSize));
  44.             $y = rand(0, ($mapSize - $maxIslandSize));
  45.             $size = rand(4, ($maxIslandSize));
  46.             for($checkY = 0; $checkY < $size; $checkY++){
  47.                 for($checkX = 0; $checkX < $size; $checkX++){
  48.                     if($tileArray[$x + $checkX][$y + $checkY] != $water){
  49.                         generateIslands();
  50.                     }
  51.                 }
  52.             }
  53.             for($rows = 0; $rows < $size; $rows++){
  54.                 for($cells = 0; $cells < $size; $cells++){
  55.                     if($rows == 0 || $rows == $size-1 || $cells == 0 || $cells == $size-1){
  56.                         $tile = $sand;
  57.                     } else {
  58.                         $tile = $grass;
  59.                     }
  60.                     $tileArray[$y + $rows][$x + $cells] = $tile;
  61.                 }
  62.             }
  63.         }
  64.        
  65.         generateWorld();
  66.     }
  67. ?>
  68. </body>
  69. </html>
Add Comment
Please, Sign In to add comment