fork download
  1. <?php
  2. abstract class Animal{
  3. protected $x;
  4. protected $y;
  5. protected $icon;
  6.  
  7. public function __construct($coordinateX, $coordinateY, $symbol){
  8. $this->x = $coordinateX;
  9. $this->y = $coordinateY;
  10. $this->icon = $symbol;
  11. }
  12. public function getCoordinateX(){
  13. return $this->x;
  14. }
  15. public function getCoordinateY(){
  16. return $this->y;
  17. }
  18. public function getIcon(){
  19. return $this->icon;
  20. }
  21. }
  22.  
  23. class Mouse extends Animal{
  24.  
  25. }
  26.  
  27.  
  28. class GameField{
  29. protected $field;
  30.  
  31. public function __construct($height, $width){
  32. $this->field = array_fill(0, $height, array_fill(0, $width, " . "));
  33. }
  34. public function printField(){
  35. foreach($this->field as $value){
  36. foreach($value as $dot){
  37. echo $dot;
  38. }
  39. echo "\n";
  40. }
  41. }
  42. public function aquireMouse(Mouse $mice){
  43. $x = $mice->getCoordinateX();
  44. $y = $mice->getCoordinateY();
  45. $this->field[$x][$y]=$mice->getIcon();
  46. }
  47. }
  48.  
  49.  
  50.  
  51. $test = new GameField(20, 20);
  52.  
  53. $mouse1 = new Mouse(3, 15, " 1 ");
  54. $test->aquireMouse($mouse1);
  55. $test->printField();
Success #stdin #stdout 0.01s 20520KB
stdin
Standard input is empty
stdout
 .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  . 
 .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  . 
 .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  . 
 .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  1  .  .  .  . 
 .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  . 
 .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  . 
 .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  . 
 .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  . 
 .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  . 
 .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  . 
 .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  . 
 .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  . 
 .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  . 
 .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  . 
 .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  . 
 .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  . 
 .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  . 
 .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  . 
 .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  . 
 .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .