fork download
  1. <?php
  2. header('Content-type: text/plain');
  3.  
  4.  
  5. class Cat {
  6. public $range; // Много ненужного, это на БУДУЩЕЕ
  7. public $x;
  8. public $y;
  9. public $z;
  10. public $spawn;
  11.  
  12. function spawnCat() {
  13. $this->range = 10;
  14. $this->x = true;
  15. $this->y = true;
  16. $this->z = true;
  17. $this->spawn = array(
  18. 'x' => rand(0, 9),
  19. 'y' => rand(0, 9));
  20. return $this->spawn;
  21. }
  22. }
  23.  
  24. class Field {
  25. public $width;
  26. public $height;
  27.  
  28. function createBlankField() {
  29. $this->width = 10;
  30. $this->height = 10;
  31. $field = array(
  32. array(".", ".", ".", ".", ".", ".", ".", ".", ".", "."),
  33. array(".", ".", ".", ".", ".", ".", ".", ".", ".", "."),
  34. array(".", ".", ".", ".", ".", ".", ".", ".", ".", "."),
  35. array(".", ".", ".", ".", ".", ".", ".", ".", ".", "."),
  36. array(".", ".", ".", ".", ".", ".", ".", ".", ".", "."),
  37. array(".", ".", ".", ".", ".", ".", ".", ".", ".", "."),
  38. array(".", ".", ".", ".", ".", ".", ".", ".", ".", "."),
  39. array(".", ".", ".", ".", ".", ".", ".", ".", ".", "."),
  40. array(".", ".", ".", ".", ".", ".", ".", ".", ".", "."),
  41. array(".", ".", ".", ".", ".", ".", ".", ".", ".", ".")
  42. );
  43. return $field;
  44. }
  45. }
  46. $fieldObj = new Field();
  47. $blankField = $fieldObj->createBlankField();
  48.  
  49. for ($x = 0; $x < 10; $x++) {
  50. for ($y = 0; $y < 10; $y++) {
  51. echo $blankField[$x][$y];
  52. }
  53. echo "\n";
  54. }
  55. echo "\n";
  56.  
  57. $catObj = new Cat();
  58. $cat = $catObj->spawnCat();
  59.  
  60. $xc = $cat['x'];
  61. $yc = $cat['y'];
  62.  
  63. $field = $blankField;
  64. $field[$xc][$yc] = "C";
  65. for ($x = 0; $x < 10; $x++) {
  66. for ($y = 0; $y < 10; $y++) {
  67. echo $field[$x][$y];
  68. }
  69. echo "\n";
  70. }
  71. echo "\n";
  72. ?>
Success #stdin #stdout 0.01s 20568KB
stdin
Standard input is empty
stdout
..........
..........
..........
..........
..........
..........
..........
..........
..........
..........

..........
..........
..........
..........
..........
..........
.........C
..........
..........
..........