Esempio n. 1
0
function posship(Ship $ship, $key)
{
    $pos = $ship->getPos();
    $size = $ship->getSize();
    $x = $pos['x'] * 10 + 2 * $pos['x'];
    $y = $pos['y'] * 10 + 2 * $pos['y'];
    $width = $size['height'] * 10 + 2 * $size['height'];
    if ($ship->getDirection() == Ship::SOUTH) {
        $rotate = 'transform-origin: 50% 50%;transform : rotate(90deg);';
    } else {
        if ($ship->getDirection() == Ship::NORTH) {
            $rotate = 'transform-origin: 50% 50%;transform : rotate(270deg);';
        } else {
            if ($ship->getDirection() == Ship::WEST) {
                $rotate = 'transform-origin: 50% 50%;transform : rotateY(180deg);';
            } else {
                $rotate = "";
            }
        }
    }
    echo '<div style=" ' . $rotate . 'position: absolute; left:' . $x . '; top:' . $y . ';">
	  	<img src="' . $ship->getSprite() . '" width ="' . $width . 'px" data-ship="' . $key . '"  class="ship"></div>';
}
Esempio n. 2
0
 /**
  * Return true if the points of the given ship are all hit
  *
  * @param Ship $ship
  * @return bool
  */
 public function isShipSunk(Ship $ship)
 {
     $hitsOnShip = 0;
     foreach ($this->shots as $shot) {
         if ($ship->hasPoint($shot)) {
             if (++$hitsOnShip >= $ship->getSize()) {
                 return true;
             }
         }
     }
     return false;
 }