123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- <?php
- class ship
- {
- //properties
- protected $lengte;
- protected $begin;
- protected $einde;
- protected $midden;
- protected $doklengte = 50;
- protected $hits = [];
-
- //methods
- function __construct($lengte)
- {
- $this->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);
- }
- }
|