fork download
  1. <?php
  2.  
  3. define('WIDTH', 10);
  4. define('HEIGHT', 10);
  5.  
  6. function gen() {
  7. $dungeon = str_repeat('#', WIDTH * HEIGHT);
  8.  
  9. // top left room
  10. $width1 = rand(1, WIDTH * 3 / 4);
  11. $height1 = rand(1, HEIGHT * 3 / 4);
  12. for ($y = 1; $y < $height1; ++$y)
  13. for ($x = 1; $x < $width1; ++$x)
  14. $dungeon[$y * WIDTH + $x] = ' ';
  15.  
  16. // top right room
  17. $width2 = rand(1, WIDTH * 3 / 4);
  18. $height2 = rand(1, HEIGHT * 3 / 4);
  19. for ($y = 1; $y < $height2; ++$y)
  20. for ($x = 1; $x < $width2; ++$x)
  21. $dungeon[$y * WIDTH + WIDTH - 1 - $x] = ' ';
  22.  
  23. // bottom left room
  24. $width = rand(WIDTH - $width2, WIDTH * 3 / 4);
  25. $height = rand(HEIGHT - $height2, HEIGHT * 3 / 4);
  26. for ($y = 1; $y < $height; ++$y)
  27. for ($x = 1; $x < $width; ++$x)
  28. $dungeon[(HEIGHT - 1 - $y) * WIDTH + $x] = ' ';
  29.  
  30. // bottom right room
  31. $width = rand(WIDTH - $width1, WIDTH * 3 / 4);
  32. $height = rand(HEIGHT - $height1, HEIGHT * 3 / 4);
  33. for ($y = 1; $y < $height; ++$y)
  34. for ($x = 1; $x < $width; ++$x)
  35. $dungeon[(HEIGHT - 1 - $y) * WIDTH + WIDTH - 1 - $x] = ' ';
  36.  
  37. for ($i = 0; $i < HEIGHT; ++$i) {
  38. echo substr($dungeon, $i * WIDTH, WIDTH) . "\n";
  39. }
  40. }
  41.  
  42. header('Content-type: text/plain');
  43. for ($i = 0; $i < 10; ++$i) {
  44. gen();
  45. echo "\n";
  46. }
Success #stdin #stdout 0.02s 52472KB
stdin
Standard input is empty
stdout
##########
#     ## #
#     ## #
#     ## #
#        #
#        #
####     #
#        #
#        #
##########

##########
####     #
####     #
####     #
####     #
#        #
#        #
#        #
#        #
##########

##########
#######  #
#######  #
#      ###
#        #
#        #
#        #
#        #
#        #
##########

##########
#      ###
#      ###
#      ###
#      ###
#        #
#        #
#        #
#        #
##########

##########
# ###### #
# ###### #
#        #
#        #
#        #
#        #
#        #
#        #
##########

##########
#     ####
#     ####
#        #
#        #
#        #
#        #
#        #
#        #
##########

##########
#  #     #
#  #     #
#        #
#        #
#        #
#        #
#        #
#        #
##########

##########
####     #
#        #
#        #
#        #
#        #
#        #
#        #
#        #
##########

##########
# ###### #
# ###### #
# ###### #
# ###### #
#        #
#        #
#        #
#        #
##########

##########
#  #######
###      #
###      #
#        #
#        #
#        #
#        #
#        #
##########