rvaken 3 лет назад
Родитель
Сommit
8f79e0cfdd
1 измененных файлов: 37 добавлений и 8 удалений
  1. 37
    8
      board.php

+ 37
- 8
board.php Просмотреть файл

@@ -9,6 +9,7 @@ class Board


protected $currentShips;
protected $posArr;

// We constructen de array die het spelbord zal vullen

@@ -21,29 +22,57 @@ class Board

protected function initShips($difficulty)
{


if ($difficulty == 'Easy') {
$this->currentShips[] = new torpedojager();
$this->currentShips[] = new duikboot();
$this->currentShips[0] = new torpedojager();
$this->currentShips[1] = new duikboot();


$_SESSION['ammo'] = 30;
} else if ($difficulty == 'Normal') {
$this->currentShips[] = new slagSchip();
$this->currentShips[] = new kruiser();
$this->currentShips[0] = new slagSchip();
$this->currentShips[1] = new kruiser();
$_SESSION['ammo'] = 24;
} else if ($difficulty == 'Hard') {
$this->currentShips[] = new vliegdekSchip();
$this->currentShips[] = new slagSchip();
$this->currentShips[0] = new vliegdekSchip();
$this->currentShips[1] = new slagSchip();
$_SESSION['ammo'] = 16;
}



$this->posArr[0][0] = $this->currentShips[0]->returnPosBegin();
$this->posArr[0][1] = $this->currentShips[0]->returnPosEind();
$this->posArr[1][0] = $this->currentShips[1]->returnPosBegin();
$this->posArr[1][1] = $this->currentShips[1]->returnPosEind();


while ($this->legalShipPosition($this->currentShips[1]->posArr(), $this->posArr[0][0], $this->posArr[0][1])){
$this->initShips($difficulty);
}

}

//Overlappingen tegengaan (niet meer gevonden :/)
//Overlappingen tegengaan

protected function legalShipPosition()
protected function legalShipPosition($arr, $firstPos, $lastPos)
{
foreach ($arr as $value) {
if ($value >= $firstPos && $value <= $lastPos) {
return true;
}
}

return false;

}


// Actieve ships returnen

public function returnCurrentShips()
{
return $this->currentShips;

Загрузка…
Отмена
Сохранить