subPos($lengte); } protected function start($lengte) { $this->begin = $this->midden - floor($lengte / 2); } protected function end($lengte) { $this->einde = $this->begin + $lengte - 1; } //bepaald positie van het schip in het dok protected function randomPos($lengte) { $this->midden = rand(floor($lengte / 2), $this->doklengte - 1 - floor($lengte / 2)); } // variable subPos() geeft de lengte aan de duikboot mee en legt eigenschappen duikboot vast. protected function subPos($lengte) { $this->lengte = $lengte; $this->randomPos($lengte); $this->start($lengte); $this->end($lengte); } //return array with beginning and end coordinates public function printCoord() { return [$this->begin, $this->einde]; } //return int doklengte public function printDokLengte() { return $this->doklengte; } public function printLengte() { return $this->lengte; } // kijkt na of schot raak was // tabel begint Bij 1 dus let op bij weergave shot in tabel! // moet hiervoor nog corrigeren!!! public function compareShot($shot) { if ($this->begin <= $shot && $this->einde >= $shot) { if (!in_array($shot, $this->hits)) { //new part ship hit $this->hits[] = $shot; return 1; } } else { return 0; } } } class duikboot extends ship { function __construct() { $this->subPos(1); } } class torpedojager extends ship { function __construct() { $this->subPos(2); } } class kruiser extends ship { function __construct() { $this->subPos(3); } } class slagschip extends ship { function __construct() { $this->subPos(4); } } class vliegdekship extends ship { function __construct() { $this->subPos(5); } }