sowebdev / battleship-game
Small library for building a battleship game in PHP
0.1
2017-05-30 21:56 UTC
Requires
- php: ^7.0
Requires (Dev)
- kahlan/kahlan: ^3.0
- squizlabs/php_codesniffer: ^3.0
This package is auto-updated.
Last update: 2024-05-10 12:06:00 UTC
README
Small library for building a battleship game in PHP.
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";
}