Formatting fixes and cleanup.
This commit is contained in:
parent
a1e14a3e60
commit
51fb71e469
41 changed files with 394 additions and 392 deletions
|
|
@ -39,7 +39,7 @@ class GameBoard
|
|||
/**
|
||||
* Return the state
|
||||
*/
|
||||
public function getState() : GameBoardState
|
||||
public function getState(): GameBoardState
|
||||
{
|
||||
return $this->state;
|
||||
}
|
||||
|
|
@ -47,7 +47,7 @@ class GameBoard
|
|||
/**
|
||||
* Get the size of the board.
|
||||
*/
|
||||
public function getSize() : int
|
||||
public function getSize(): int
|
||||
{
|
||||
return $this->state->getSize();
|
||||
}
|
||||
|
|
@ -55,7 +55,7 @@ class GameBoard
|
|||
/**
|
||||
* Clear the game board.
|
||||
*/
|
||||
public function clear() : void
|
||||
public function clear(): void
|
||||
{
|
||||
$this->state->clear();
|
||||
}
|
||||
|
|
@ -64,7 +64,7 @@ class GameBoard
|
|||
* Check if the board is in an ended state.
|
||||
* E.g: all cards is in a winning state.
|
||||
*/
|
||||
public function hasGameEnded() : bool
|
||||
public function hasGameEnded(): bool
|
||||
{
|
||||
return $this->state->isFull(GameBoardState::STATE_WIN);
|
||||
}
|
||||
|
|
@ -74,7 +74,7 @@ class GameBoard
|
|||
*
|
||||
* @throw NotEnoughCardsException
|
||||
*/
|
||||
public function regenerate(GameSettings $settings) : self
|
||||
public function regenerate(GameSettings $settings): self
|
||||
{
|
||||
$num_cards = $this->getSize();
|
||||
$cards = Card::getBySettings($settings, $num_cards);
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ class GameBoardState
|
|||
/**
|
||||
* Set the state of a cell.
|
||||
*/
|
||||
public function set(int $pos, bool $pressed = true) : self
|
||||
public function set(int $pos, bool $pressed = true): self
|
||||
{
|
||||
if ($this->hasGameEnded()) {
|
||||
return $this;
|
||||
|
|
@ -62,7 +62,7 @@ class GameBoardState
|
|||
/**
|
||||
* Toggle pressed state of a cell.
|
||||
*/
|
||||
public function toggle(int $pos) : self
|
||||
public function toggle(int $pos): self
|
||||
{
|
||||
return $this->set($pos, !$this->isPressed($pos));
|
||||
}
|
||||
|
|
@ -70,7 +70,7 @@ class GameBoardState
|
|||
/**
|
||||
* Check if a cell is pressed or not.
|
||||
*/
|
||||
public function isPressed(int $pos) : bool
|
||||
public function isPressed(int $pos): bool
|
||||
{
|
||||
return isset($this->state[$pos]);
|
||||
}
|
||||
|
|
@ -78,7 +78,7 @@ class GameBoardState
|
|||
/**
|
||||
* Check if a cell is part of a winning row/column.
|
||||
*/
|
||||
public function isWin(int $pos) : bool
|
||||
public function isWin(int $pos): bool
|
||||
{
|
||||
return isset($this->state[$pos]) && $this->state[$pos] == self::STATE_WIN;
|
||||
}
|
||||
|
|
@ -86,7 +86,7 @@ class GameBoardState
|
|||
/**
|
||||
* Get the sate of the cells.
|
||||
*/
|
||||
public function getState() : array
|
||||
public function getState(): array
|
||||
{
|
||||
return $this->state;
|
||||
}
|
||||
|
|
@ -94,7 +94,7 @@ class GameBoardState
|
|||
/**
|
||||
* Get the size of the board.
|
||||
*/
|
||||
public function getSize() : int
|
||||
public function getSize(): int
|
||||
{
|
||||
return $this->width * $this->height;
|
||||
}
|
||||
|
|
@ -102,7 +102,7 @@ class GameBoardState
|
|||
/**
|
||||
* Clear the board.
|
||||
*/
|
||||
public function clear() : self
|
||||
public function clear(): self
|
||||
{
|
||||
$this->state = [];
|
||||
$this->winning = 0;
|
||||
|
|
@ -110,7 +110,7 @@ class GameBoardState
|
|||
}
|
||||
|
||||
// TODO: Rename
|
||||
public function getNumWinRows() : int
|
||||
public function getNumWinRows(): int
|
||||
{
|
||||
return $this->winning;
|
||||
}
|
||||
|
|
@ -118,13 +118,13 @@ class GameBoardState
|
|||
/**
|
||||
* Check if the board only has winning cards
|
||||
*/
|
||||
public function hasGameEnded() : bool
|
||||
public function hasGameEnded(): bool
|
||||
{
|
||||
if (count($this->state) < $this->width * $this->height) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach($this->state as $pos) {
|
||||
foreach ($this->state as $pos) {
|
||||
if ($pos !== self::STATE_WIN) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -135,14 +135,14 @@ class GameBoardState
|
|||
/**
|
||||
* Check if the board is full and all positions is in a given state.
|
||||
*/
|
||||
public function isFull($state) : bool
|
||||
public function isFull($state): bool
|
||||
{
|
||||
// Board not filled, impossible to have all positions set.
|
||||
if (count($this->state) < $this->width * $this->height) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach($this->state as $pos) {
|
||||
foreach ($this->state as $pos) {
|
||||
if ($pos !== $state) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -153,15 +153,15 @@ class GameBoardState
|
|||
/**
|
||||
*
|
||||
*/
|
||||
protected function update() : void
|
||||
protected function update(): void
|
||||
{
|
||||
foreach($this->state as $pos => $_) {
|
||||
foreach ($this->state as $pos => $_) {
|
||||
$this->state[$pos] = self::STATE_PRESSED;
|
||||
}
|
||||
|
||||
$patterns = $this->checkWinningState();
|
||||
foreach($patterns as $cards) {
|
||||
foreach($cards as $pos) {
|
||||
foreach ($patterns as $cards) {
|
||||
foreach ($cards as $pos) {
|
||||
$this->state[$pos] = self::STATE_WIN;
|
||||
}
|
||||
}
|
||||
|
|
@ -171,12 +171,12 @@ class GameBoardState
|
|||
/**
|
||||
* Check if the board is in a winning state.
|
||||
*/
|
||||
protected function checkWinningState() : array
|
||||
protected function checkWinningState(): array
|
||||
{
|
||||
$win = [];
|
||||
|
||||
// Rows
|
||||
for($y=0; $y < $this->height; $y++) {
|
||||
for ($y = 0; $y < $this->height; $y++) {
|
||||
$c = $this->checkRow($y);
|
||||
if (count($c)) {
|
||||
$win[] = $c;
|
||||
|
|
@ -184,7 +184,7 @@ class GameBoardState
|
|||
}
|
||||
|
||||
// Columns
|
||||
for($x=0; $x < $this->width; $x++) {
|
||||
for ($x = 0; $x < $this->width; $x++) {
|
||||
$c = $this->checkCol($x);
|
||||
if (count($c)) {
|
||||
$win[] = $c;
|
||||
|
|
@ -197,12 +197,12 @@ class GameBoardState
|
|||
/**
|
||||
* Check if a row is in a winning state (all cells pressed)
|
||||
*/
|
||||
protected function checkRow($y) : array
|
||||
protected function checkRow($y): array
|
||||
{
|
||||
$cards = [];
|
||||
|
||||
$y = $y * $this->width;
|
||||
for($x = 0; $x < $this->width; $x++) {
|
||||
for ($x = 0; $x < $this->width; $x++) {
|
||||
$pos = $x + $y;
|
||||
if (!$this->isPressed($pos)) {
|
||||
return [];
|
||||
|
|
@ -216,11 +216,11 @@ class GameBoardState
|
|||
/**
|
||||
* Check if a column is in a winning state (all cells pressed)
|
||||
*/
|
||||
protected function checkCol($x) : array
|
||||
protected function checkCol($x): array
|
||||
{
|
||||
$cards = [];
|
||||
|
||||
for($y = 0; $y < $this->height; $y++) {
|
||||
for ($y = 0; $y < $this->height; $y++) {
|
||||
$pos = $x + ($y * $this->width);
|
||||
if (!$this->isPressed($pos)) {
|
||||
return [];
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ class GameService
|
|||
/**
|
||||
* Get the current session
|
||||
*/
|
||||
public function session() : GameSession
|
||||
public function session(): GameSession
|
||||
{
|
||||
return $this->session;
|
||||
}
|
||||
|
|
@ -28,7 +28,7 @@ class GameService
|
|||
/**
|
||||
* Generate a new Game session
|
||||
*/
|
||||
public function newSession(?GameSettings $settings = null) : self
|
||||
public function newSession(?GameSettings $settings = null): self
|
||||
{
|
||||
if (!$settings) {
|
||||
$settings = $this->session()->getSettings();
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ class GameSession
|
|||
/**
|
||||
* Get the board
|
||||
*/
|
||||
public function getBoard() : GameBoard
|
||||
public function getBoard(): GameBoard
|
||||
{
|
||||
return $this->board;
|
||||
}
|
||||
|
|
@ -36,7 +36,7 @@ class GameSession
|
|||
/**
|
||||
* Get the board state
|
||||
*/
|
||||
public function getBoardState() : GameBoardState
|
||||
public function getBoardState(): GameBoardState
|
||||
{
|
||||
return $this->getBoard()->getState();
|
||||
}
|
||||
|
|
@ -44,7 +44,7 @@ class GameSession
|
|||
/**
|
||||
* Get Cards
|
||||
*/
|
||||
public function getCards() : Collection
|
||||
public function getCards(): Collection
|
||||
{
|
||||
return $this->getBoard()->getCards();
|
||||
}
|
||||
|
|
@ -52,7 +52,7 @@ class GameSession
|
|||
/**
|
||||
* Get Settings
|
||||
*/
|
||||
public function getSettings() : GameSettings
|
||||
public function getSettings(): GameSettings
|
||||
{
|
||||
return $this->settings;
|
||||
}
|
||||
|
|
@ -60,7 +60,7 @@ class GameSession
|
|||
/**
|
||||
* Set new settings
|
||||
*/
|
||||
public function setSettings(GameSettings $settings) : self
|
||||
public function setSettings(GameSettings $settings): self
|
||||
{
|
||||
$this->settings = $settings;
|
||||
return $this;
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ class GameSettings
|
|||
}
|
||||
}
|
||||
|
||||
public function toArray() : array
|
||||
public function toArray(): array
|
||||
{
|
||||
return [
|
||||
'classes' => $this->classes->toArray(),
|
||||
|
|
@ -54,7 +54,7 @@ class GameSettings
|
|||
];
|
||||
}
|
||||
|
||||
public function all() : Collection
|
||||
public function all(): Collection
|
||||
{
|
||||
return collect([
|
||||
'classes' => $this->classes->all()->toArray(),
|
||||
|
|
|
|||
Reference in a new issue