fork(2) download
  1. <?php
  2.  
  3. class FieldCreator
  4. {
  5. const WIDTH = 8;
  6. const HEIGHT = 6;
  7.  
  8. public function showField($animal)
  9. {
  10. $animals = $animal->getPoint();
  11. for ($i = 0; $i < self::HEIGHT; $i++) {
  12. for ($i = 0; $i < self::WIDTH; $i++) {
  13. if ($animals[$i] == array(self::WIDTH, self::HEIGHT)) {
  14. echo "m";
  15. } else {
  16. echo ".";
  17. }
  18. }
  19. }
  20. }
  21. }
  22.  
  23. abstract class Animals
  24. {
  25. public $count;
  26.  
  27. public function getPoint()
  28. {
  29. for($i = 0; $i < $this->count; $i++) {
  30. $point[$i] = array (mt_rand(1, FieldCreator::WIDTH), mt_rand(1, FieldCreator::HEIGHT));
  31. }
  32. return $point;
  33. }
  34. }
  35.  
  36. class Mice extends Animals
  37. {
  38. public $count = 4;
  39. }
  40.  
  41. class Cats extends Animals
  42. {
  43. public $name = "K";
  44. public $count = 2;
  45. }
  46.  
  47. $mice = new Mice;
  48.  
  49. $f1 = new FieldCreator;
  50. $f1->showField($mice);
Success #stdin #stdout #stderr 0.01s 20520KB
stdin
Standard input is empty
stdout
........
stderr
PHP Notice:  Undefined offset: 4 in /home/EJShfb/prog.php on line 13
PHP Notice:  Undefined offset: 5 in /home/EJShfb/prog.php on line 13
PHP Notice:  Undefined offset: 6 in /home/EJShfb/prog.php on line 13
PHP Notice:  Undefined offset: 7 in /home/EJShfb/prog.php on line 13