<?php
class World {
public $sideLength;
public $filler = "0";
function __construct($sideLength) {
$this->sideLength = $sideLength;
}
function draw() {
foreach ($this->field as $line) {
echo "<br>";
}
}
function place(Animal $animal) {
do {
$x = mt_rand(1, $this->sideLength); $y = mt_rand(1, $this->sideLength);
if ($this->field[$x][$y] == $this->filler) {
$this->field[$x][$y] = $animal->icon;
$animal->placed = true;
$animal->x = $x;
$animal->y = $y;
}
} while ($animal->placed == false);
}
}
abstract class Animal {
public $x;
public $y;
public $icon;
public $placed = false;
function __construct($icon) {
$this->icon = $icon;
}
}
class Mouse extends Animal {
public function move (World $world) {
}
}
$world1 = new World(10);
$mouse1 = new Mouse('<bold>1</bold>');
$mouse2 = new Mouse('2');
$mouse3 = new Mouse('3');
$mouse4 = new Mouse('4');
$world1->place($mouse1);
$world1->place($mouse2);
$world1->place($mouse3);
$world1->place($mouse4);
$world1->draw();
?>
PD9waHAKZXJyb3JfcmVwb3J0aW5nKC0xKTsKbWJfaW50ZXJuYWxfZW5jb2RpbmcoInV0Zi04Iik7CgpjbGFzcyBXb3JsZCB7CgkKCXB1YmxpYyAkc2lkZUxlbmd0aDsKCXB1YmxpYyAkZmllbGQgPSBhcnJheSgpOwoJcHVibGljICRmaWxsZXIgPSAiMCI7CgoJZnVuY3Rpb24gX19jb25zdHJ1Y3QoJHNpZGVMZW5ndGgpIHsKCQkkdGhpcy0+c2lkZUxlbmd0aCA9ICRzaWRlTGVuZ3RoOwoJCSR0aGlzLT5maWVsZCA9IGFycmF5X2ZpbGwoMSwgJHNpZGVMZW5ndGgsIGFycmF5X2ZpbGwoMSwgJHNpZGVMZW5ndGgsICR0aGlzLT5maWxsZXIpKTsJCQoJfQoKCWZ1bmN0aW9uIGRyYXcoKSB7CgkJZm9yZWFjaCAoJHRoaXMtPmZpZWxkIGFzICRsaW5lKSB7CgkJCWVjaG8gaW1wbG9kZSgiICAiLCRsaW5lKTsKCQkJZWNobyAiPGJyPiI7CgkJfQoJfQoKCWZ1bmN0aW9uIHBsY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