Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <?php
  2. // Ship class
  3. class Ships
  4. {
  5. protected $length;
  6. protected $posBegin;
  7. protected $posEind;
  8. protected $posMidden;
  9. protected $amountShots;
  10. protected $arrPos;
  11. protected $ammo;
  12. function __construct()
  13. {
  14. $this->createShip();
  15. }
  16. protected function createShip()
  17. {
  18. $this->calcposMidden();
  19. $this->calcposBegin();
  20. $this->calcposEind();
  21. $this->initPosArr();
  22. }
  23. // Eerste positie van ship
  24. protected function calcposBegin()
  25. {
  26. $this->posBegin = $this->posMidden - floor($this->length / 2);
  27. }
  28. // Laatste positie van ship
  29. protected function calcposEind()
  30. {
  31. $this->posEind = $this->posBegin + $this->length - 2;
  32. }
  33. // Begin van ship wordt berekend adhv het midden, wat een random getal is tussen 4 en 47
  34. public function calcposMidden()
  35. {
  36. $this->posMidden = rand(4, 47);
  37. }
  38. // Opvragen van eerste positie van ship
  39. public function returnPosBegin()
  40. {
  41. return $this->posBegin;
  42. }
  43. // Opvragen van laatste positie van ship
  44. public function returnPosEind()
  45. {
  46. return $this->posEind;
  47. }
  48. //
  49. protected function initPosArr()
  50. {
  51. for ($i = $this->posBegin; $i <= $this->posEind; $i++) {
  52. $this->arrPos[] = $i;
  53. }
  54. }
  55. public function posArr()
  56. {
  57. return $this->arrPos;
  58. }
  59. public function hitOrMis($shot)
  60. {
  61. if ($shot >= $this->posBegin && $shot <= $this->posEind) {
  62. return true;
  63. } else {
  64. return false;
  65. }
  66. }
  67. }
  68. class vliegdekSchip extends Ships
  69. {
  70. protected $shipName;
  71. protected function createShip()
  72. {
  73. $this->length = 8;
  74. $this->calcposMidden();
  75. $this->calcposBegin();
  76. $this->calcposEind();
  77. $this->initPosArr();
  78. $this->shipName = "Vliegdekship";
  79. }
  80. public function returnName()
  81. {
  82. return $this->shipName;
  83. }
  84. }
  85. class slagSchip extends Ships
  86. {
  87. protected $shipName;
  88. protected function createShip()
  89. {
  90. $this->length = 7;
  91. $this->calcposMidden();
  92. $this->calcposBegin();
  93. $this->calcposEind();
  94. $this->initPosArr();
  95. $this->shipName = "Slagship";
  96. }
  97. public function returnName()
  98. {
  99. return $this->shipName;
  100. }
  101. }
  102. class kruiser extends Ships
  103. {
  104. protected $shipName;
  105. protected function createShip()
  106. {
  107. $this->length = 6;
  108. $this->calcposMidden();
  109. $this->calcposBegin();
  110. $this->calcposEind();
  111. $this->initPosArr();
  112. $this->shipName = "Kruiser";
  113. }
  114. public function returnName()
  115. {
  116. return $this->shipName;
  117. }
  118. }
  119. class torpedojager extends Ships
  120. {
  121. protected $shipName;
  122. protected function createShip()
  123. {
  124. $this->length = 5;
  125. $this->calcposMidden();
  126. $this->calcposBegin();
  127. $this->calcposEind();
  128. $this->initPosArr();
  129. $this->shipName = "Torpedojager";
  130. }
  131. public function returnName()
  132. {
  133. return $this->shipName;
  134. }
  135. }
  136. class duikboot extends Ships
  137. {
  138. protected $shipName;
  139. protected function createShip()
  140. {
  141. $this->length = 4;
  142. $this->calcposMidden();
  143. $this->calcposBegin();
  144. $this->calcposEind();
  145. $this->initPosArr();
  146. $this->shipName = "Duikboot";
  147. }
  148. public function returnName()
  149. {
  150. return $this->shipName;
  151. }
  152. }