fork download
  1. <?php
  2.  
  3. class World {
  4.  
  5. public $sideLength;
  6. public $field = array();
  7.  
  8. function __construct($sideLength) {
  9. $this->sideLength = $sideLength;
  10. $this->field = array_fill(1, $sideLength, array_fill(1, $sideLength, "0"));
  11. }
  12.  
  13. function draw() {
  14. foreach ($this->field as $line) {
  15. echo implode(" ",$line);
  16. echo "\n";
  17. }
  18. }
  19.  
  20. function place(Animal $animal) {
  21. $x = mt_rand(1, $this->sideLength);
  22. $y = mt_rand(1, $this->sideLength);
  23.  
  24. $this->field[$x][$y] = $animal->icon;
  25. }
  26.  
  27. }
  28.  
  29. abstract class Animal {
  30. public $x;
  31. public $y;
  32. public $icon;
  33.  
  34. function __construct($icon) {
  35. $this->icon = $icon;
  36. }
  37. }
  38.  
  39. class Mouse extends Animal {
  40. public function move () {
  41.  
  42. }
  43. }
  44.  
  45. $world1 = new World(8);
  46.  
  47. $mouse1 = new Mouse('1');
  48.  
  49. $world1->place($mouse1);
  50.  
  51. $world1->draw();
  52.  
  53. ?>
Success #stdin #stdout 0.02s 52472KB
stdin
Standard input is empty
stdout
0  0  0  0  0  0  0  0
0  0  0  0  0  0  0  0
0  0  0  0  0  0  0  0
0  0  0  0  0  0  0  0
0  0  0  0  0  0  0  0
0  0  0  0  0  0  0  0
0  0  1  0  0  0  0  0
0  0  0  0  0  0  0  0