fork download
  1. <?php
  2. header("Content-Type: text/plain; charset=utf-8");
  3. ?>
  4. <?php
  5.  
  6.  
  7. abstract class Animal
  8. {
  9. public $x;
  10. public $y;
  11. public $icon;
  12. public $type;
  13. public $targetX;
  14. public $targetY;
  15. public function __construct($x, $y)
  16. {
  17. $this->x = $x;
  18. $this->y = $y;
  19. foreach ($z->ground as $v) {
  20. foreach ($v as $square)
  21. if (is_object($square)) {
  22. $this->targetX = abs($square->x - $this->x);
  23. $this->targetY = abs($square->y - $this->y);
  24. }
  25. }
  26. }
  27.  
  28. }
  29. class Cat extends Animal
  30. {
  31. public $type = 'cat';
  32. public $icon = ' @ ';
  33. public function getMoveCat()
  34. {
  35.  
  36. }
  37. }
  38. class Mouse extends Animal
  39. {
  40. public $type = 'mouse';
  41. public $icon = ' 1 ';
  42. }
  43. class Table
  44. {
  45. public $length;
  46. public $height;
  47. public $cats;
  48. public $mouses;
  49. public $ground;
  50. public function __construct($n, $cats, $mouses)
  51. {
  52. $ground = array();
  53. for ($i = 1; $i <= $n; $i++) {
  54. $ground[$i] = array_fill(1, $n, ' . ');
  55. }
  56. $this->ground = $ground;
  57. $this->length = $n;
  58. $this->height = $n;
  59. $this->cats = $cats;
  60. $this->mouses = $mouses;
  61. }
  62. public function FillTheGroundPls()
  63. {
  64. $show = '';
  65.  
  66. foreach ($this->ground as $k => $v) {
  67. $table = '';
  68. foreach ($v as $key => $val) {
  69. $table .= $val;
  70. }
  71. $show .= $table . "\n";
  72. }
  73. return $show;
  74. }
  75. public function ShowMeTheGroundPls()
  76. {
  77. foreach ($this->ground as $v) {
  78. foreach ($v as $k => $val) {
  79. if (is_object($val)) {
  80. echo $val->icon;
  81. } else {
  82. echo ' . ';
  83. }
  84. }
  85. echo "\n";
  86. }
  87. }
  88.  
  89.  
  90. }
  91.  
  92.  
  93.  
  94. $z = new Table(10);
  95.  
  96. function getNewAnimals($type, $count, $type2, $count2)
  97. {
  98. global $z;
  99. for ($i = 1; $i <= $count; $i++) {
  100. $animals = array();
  101. $x = mt_rand(1, $z->length);
  102. $y = mt_rand(1, $z->height);
  103.  
  104. if (!is_object($z->ground[$y][$x])) {
  105. $animal = new $type($x, $y);
  106. $animals[] = $animal;
  107. $z->ground[$y][$x] = $animal;
  108. } else
  109. $i--;
  110. }
  111. for ($k = 1; $k <= $count2; $k++) {
  112. $animals = array();
  113. $x = mt_rand(1, $z->length);
  114. $y = mt_rand(1, $z->height);
  115.  
  116. if (!is_object($z->ground[$y][$x])) {
  117. $animal = new $type2($x, $y);
  118. $animals[] = $animal;
  119. $z->ground[$y][$x] = $animal;
  120. } else
  121. $i--;
  122. }
  123.  
  124. return $z->ground;
  125. }
  126.  
  127. $cat = 'Cat';
  128. $mouse = 'Mouse';
  129.  
  130. $z->ground = getNewAnimals($mouse, 3, $cat, 2);
  131. $z->showMeTheGroundPls();
  132.  
Success #stdin #stdout #stderr 0.01s 20520KB
stdin
Standard input is empty
stdout
 
 .  .  .  .  .  .  .  .  .  . 
 .  .  .  .  .  .  .  .  .  . 
 .  .  .  .  .  .  .  .  @  . 
 1  .  .  .  .  .  .  .  .  . 
 .  .  .  .  .  .  .  .  .  . 
 .  .  .  .  .  .  .  .  @  . 
 .  .  .  .  .  .  .  .  .  . 
 .  .  .  .  .  .  .  .  1  . 
 .  .  .  .  .  .  .  .  .  . 
 .  .  .  .  .  .  .  .  1  . 
stderr
PHP Warning:  Missing argument 2 for Table::__construct(), called in /home/WTRJtv/prog.php on line 96 and defined in /home/WTRJtv/prog.php on line 52
PHP Warning:  Missing argument 3 for Table::__construct(), called in /home/WTRJtv/prog.php on line 96 and defined in /home/WTRJtv/prog.php on line 52
PHP Notice:  Undefined variable: cats in /home/WTRJtv/prog.php on line 61
PHP Notice:  Undefined variable: mouses in /home/WTRJtv/prog.php on line 62
PHP Notice:  Undefined variable: z in /home/WTRJtv/prog.php on line 21
PHP Notice:  Trying to get property of non-object in /home/WTRJtv/prog.php on line 21
PHP Warning:  Invalid argument supplied for foreach() in /home/WTRJtv/prog.php on line 21
PHP Notice:  Undefined variable: z in /home/WTRJtv/prog.php on line 21
PHP Notice:  Trying to get property of non-object in /home/WTRJtv/prog.php on line 21
PHP Warning:  Invalid argument supplied for foreach() in /home/WTRJtv/prog.php on line 21
PHP Notice:  Undefined variable: z in /home/WTRJtv/prog.php on line 21
PHP Notice:  Trying to get property of non-object in /home/WTRJtv/prog.php on line 21
PHP Warning:  Invalid argument supplied for foreach() in /home/WTRJtv/prog.php on line 21
PHP Notice:  Undefined variable: z in /home/WTRJtv/prog.php on line 21
PHP Notice:  Trying to get property of non-object in /home/WTRJtv/prog.php on line 21
PHP Warning:  Invalid argument supplied for foreach() in /home/WTRJtv/prog.php on line 21
PHP Notice:  Undefined variable: z in /home/WTRJtv/prog.php on line 21
PHP Notice:  Trying to get property of non-object in /home/WTRJtv/prog.php on line 21
PHP Warning:  Invalid argument supplied for foreach() in /home/WTRJtv/prog.php on line 21