sowebdev/battleship-game

Small library for building a battleship game in PHP

0.1 2017-05-30 21:56 UTC

This package is auto-updated.

Last update: 2024-05-10 12:06:00 UTC


README

Small library for building a battleship game in PHP.

Minimum PHP Version Build status Coverage report

Requirements

PHP 7+

Description

This library only provides the game logic. Some changes have been made comparing to the original game :

  • all players share the same grid
  • ships are placed randomly on the map
  • all ships have the same size
  • each player only has one ship

Any user or networking management is out of scope and will have to be implemented on your side.

Example usage

<?php

$players = [
  new \Battleship\Game\Player(),
  new \Battleship\Game\Player(),
];
$config = new \Battleship\Game\Configuration($players);
$config->setShipSize(3);

$gameBuilder = new \Battleship\Game\GameBuilder();
$game = $gameBuilder->newGame($config);

$player = $game->currentPlayer();
$game->shoot($player, 0, 1);
if ($game->isOver()) {
    echo "Already over";
}