123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- <?php
-
- // Ship class
- class Ships
- {
- protected $length;
- protected $posBegin;
- protected $posEind;
- protected $posMidden;
- protected $amountShots;
- protected $arrPos;
- protected $ammo;
-
-
- function __construct()
- {
- $this->createShip();
- }
-
- protected function createShip()
- {
- $this->calcposMidden();
- $this->calcposBegin();
- $this->calcposEind();
- $this->initPosArr();
- }
-
-
- // Eerste positie van ship
- protected function calcposBegin()
- {
- $this->posBegin = $this->posMidden - floor($this->length / 2);
- }
-
- // Laatste positie van ship
- protected function calcposEind()
- {
- $this->posEind = $this->posBegin + $this->length - 2;
- }
-
- // Begin van ship wordt berekend adhv het midden, wat een random getal is tussen 4 en 47
- public function calcposMidden()
- {
-
- $this->posMidden = rand(4, 47);
- }
-
- // Opvragen van eerste positie van ship
- public function returnPosBegin()
- {
- return $this->posBegin;
- }
-
- // Opvragen van laatste positie van ship
- public function returnPosEind()
- {
- return $this->posEind;
- }
-
- //
- protected function initPosArr()
- {
- for ($i = $this->posBegin; $i <= $this->posEind; $i++) {
- $this->arrPos[] = $i;
- }
- }
-
-
-
- public function posArr()
- {
- return $this->arrPos;
- }
-
- public function hitOrMis($shot)
- {
- if ($shot >= $this->posBegin && $shot <= $this->posEind) {
- return true;
- } else {
- return false;
- }
- }
- }
-
- class vliegdekSchip extends Ships
- {
- protected $shipName;
- protected function createShip()
- {
- $this->length = 8;
- $this->calcposMidden();
- $this->calcposBegin();
- $this->calcposEind();
- $this->initPosArr();
- $this->shipName = "Vliegdekship";
- }
-
- public function returnName()
- {
- return $this->shipName;
- }
- }
- class slagSchip extends Ships
- {
- protected $shipName;
- protected function createShip()
- {
- $this->length = 7;
- $this->calcposMidden();
- $this->calcposBegin();
- $this->calcposEind();
- $this->initPosArr();
- $this->shipName = "Slagship";
- }
-
- public function returnName()
- {
- return $this->shipName;
- }
- }
- class kruiser extends Ships
- {
- protected $shipName;
- protected function createShip()
- {
- $this->length = 6;
- $this->calcposMidden();
- $this->calcposBegin();
- $this->calcposEind();
- $this->initPosArr();
- $this->shipName = "Kruiser";
- }
-
- public function returnName()
- {
- return $this->shipName;
- }
- }
-
- class torpedojager extends Ships
- {
- protected $shipName;
- protected function createShip()
- {
- $this->length = 5;
- $this->calcposMidden();
- $this->calcposBegin();
- $this->calcposEind();
- $this->initPosArr();
- $this->shipName = "Torpedojager";
- }
-
- public function returnName()
- {
- return $this->shipName;
- }
- }
- class duikboot extends Ships
- {
- protected $shipName;
- protected function createShip()
- {
- $this->length = 4;
- $this->calcposMidden();
- $this->calcposBegin();
- $this->calcposEind();
- $this->initPosArr();
- $this->shipName = "Duikboot";
- }
-
- public function returnName()
- {
- return $this->shipName;
- }
- }
|