fork(1) download
  1. <?php
  2.  
  3. class Mouse
  4. {
  5. const NAME = 'm';
  6. public $point;
  7.  
  8. public function getStartPoint()
  9. {
  10. $x = mt_rand(1, Field::WIDTH);
  11. $y = mt_rand(1, Field::HEIGHT);
  12.  
  13. $this->point = array("x" => $x,"y" => $y);
  14. }
  15.  
  16. public function takeStep($field)
  17. {
  18. $y = $this->point["y"];
  19. $x = $this->point["x"];
  20.  
  21. $mouseEyes = array();
  22.  
  23. for ($x; $x < $this->point["x"] + 4; $x++) {
  24. if ($field[$y][$x] == Cat::NAME) {
  25. $mouseEyes[] = array($x, $y);
  26. }
  27. }
  28.  
  29. for ($y; $y < $this->point["y"] + 4; $y++) {
  30. if ($field[$y][$x] == Cat::NAME) {
  31. $mouseEyes[] = array($x, $y);
  32. }
  33. }
  34.  
  35. for ($x; $x > $this->point["x"] - 4; $x--) {
  36. if ($field[$y][$x] == Cat::NAME) {
  37. $mouseEyes[] = array($x, $y);
  38. }
  39. }
  40.  
  41. for ($y; $y > $this->point["y"] - 4; $y--) {
  42. if ($field[$y][$x] == Cat::NAME) {
  43. $mouseEyes[] = array($x, $y);
  44. }
  45. }
  46.  
  47. }
  48. }
  49.  
  50. class Cat
  51. {
  52. const NAME = 'C';
  53. public $point;
  54.  
  55. public function getStartPoint()
  56. {
  57. $x = mt_rand(1, 8);
  58. $y = mt_rand(1, 6);
  59.  
  60. $this->point = array("x" => $x,"y" => $y);
  61. }
  62.  
  63. public function takeStep()
  64. {
  65.  
  66. }
  67. }
  68.  
  69. class Field
  70. {
  71. const WIDTH = 16;
  72. const HEIGHT = 20;
  73.  
  74. public $field;
  75.  
  76. public function createField()
  77. {
  78. for ($y = 0; $y < self::WIDTH; $y++) {
  79. for ($x = 0; $x < self::HEIGHT; $x++) {
  80. $field[$y][$x] = ".";
  81. }
  82. }
  83.  
  84. $this->field = $field;
  85. }
  86. }
  87.  
  88. class Game
  89. {
  90.  
  91. }
  92.  
  93. $field = new Field;
  94. $field->createField();
  95.  
  96. $m1 = new Mouse;
  97. $m1->getStartPoint();
  98. $m1->takeStep($field->field);
  99.  
  100. foreach ($field->field as $string) {
  101. echo implode("", $string)."\n";
  102. }
  103.  
Success #stdin #stdout 0.01s 20568KB
stdin
Standard input is empty
stdout
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................