Minor fixes.
This commit is contained in:
parent
ddf09fe00c
commit
c8b93095dc
7 changed files with 26 additions and 32 deletions
|
|
@ -19,7 +19,6 @@ class GameBoard
|
||||||
*/
|
*/
|
||||||
protected GameBoardState $state;
|
protected GameBoardState $state;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new board.
|
* Create a new board.
|
||||||
*/
|
*/
|
||||||
|
|
@ -56,7 +55,7 @@ class GameBoard
|
||||||
/**
|
/**
|
||||||
* Clear the game board.
|
* Clear the game board.
|
||||||
*/
|
*/
|
||||||
public function clear()
|
public function clear() : void
|
||||||
{
|
{
|
||||||
$this->state->clear();
|
$this->state->clear();
|
||||||
}
|
}
|
||||||
|
|
@ -72,6 +71,8 @@ class GameBoard
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Regenerate the board with new cards.
|
* Regenerate the board with new cards.
|
||||||
|
*
|
||||||
|
* @throw NotEnoughCardsException
|
||||||
*/
|
*/
|
||||||
public function regenerate(GameSettings $settings) : self
|
public function regenerate(GameSettings $settings) : self
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -153,7 +153,7 @@ class GameBoardState
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
protected function update()
|
protected function update() : void
|
||||||
{
|
{
|
||||||
foreach($this->state as $pos => $_) {
|
foreach($this->state as $pos => $_) {
|
||||||
$this->state[$pos] = self::STATE_PRESSED;
|
$this->state[$pos] = self::STATE_PRESSED;
|
||||||
|
|
@ -207,10 +207,6 @@ class GameBoardState
|
||||||
if (!$this->isPressed($pos)) {
|
if (!$this->isPressed($pos)) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
if ($this->state[$pos] == self::STATE_WIN) {
|
|
||||||
continue;
|
|
||||||
} */
|
|
||||||
$cards[] = $pos;
|
$cards[] = $pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -229,10 +225,6 @@ class GameBoardState
|
||||||
if (!$this->isPressed($pos)) {
|
if (!$this->isPressed($pos)) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
if ($this->state[$pos] == self::STATE_WIN) {
|
|
||||||
continue;
|
|
||||||
} */
|
|
||||||
$cards[] = $pos;
|
$cards[] = $pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,15 +4,21 @@ namespace App\Game;
|
||||||
|
|
||||||
class GameService
|
class GameService
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* The game session
|
||||||
|
*/
|
||||||
protected GameSession $session;
|
protected GameSession $session;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct a new Game Service
|
||||||
|
*/
|
||||||
public function __construct(GameSession $session)
|
public function __construct(GameSession $session)
|
||||||
{
|
{
|
||||||
$this->session = $session;
|
$this->session = $session;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Get the current session
|
||||||
*/
|
*/
|
||||||
public function session() : GameSession
|
public function session() : GameSession
|
||||||
{
|
{
|
||||||
|
|
@ -24,11 +30,11 @@ class GameService
|
||||||
*/
|
*/
|
||||||
public function newSession(?GameSettings $settings = null) : self
|
public function newSession(?GameSettings $settings = null) : self
|
||||||
{
|
{
|
||||||
// Generate new cards
|
|
||||||
if (!$settings) {
|
if (!$settings) {
|
||||||
$settings = $this->session()->getSettings();
|
$settings = $this->session()->getSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Generate a new board
|
||||||
$this->session->getBoard()->regenerate($settings);
|
$this->session->getBoard()->regenerate($settings);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
|
|
||||||
|
|
@ -17,10 +17,8 @@ class GameSession
|
||||||
protected GameSettings $settings;
|
protected GameSettings $settings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Create a new GameSession
|
||||||
*/
|
*/
|
||||||
//protected $cards;
|
|
||||||
|
|
||||||
public function __construct(GameBoard $board, GameSettings $settings)
|
public function __construct(GameBoard $board, GameSettings $settings)
|
||||||
{
|
{
|
||||||
$this->board = $board;
|
$this->board = $board;
|
||||||
|
|
@ -28,7 +26,7 @@ class GameSession
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Get the board
|
||||||
*/
|
*/
|
||||||
public function getBoard() : GameBoard
|
public function getBoard() : GameBoard
|
||||||
{
|
{
|
||||||
|
|
@ -36,7 +34,7 @@ class GameSession
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Get the board state
|
||||||
*/
|
*/
|
||||||
public function getBoardState() : GameBoardState
|
public function getBoardState() : GameBoardState
|
||||||
{
|
{
|
||||||
|
|
@ -44,7 +42,7 @@ class GameSession
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Get Cards
|
||||||
*/
|
*/
|
||||||
public function getCards() : Collection
|
public function getCards() : Collection
|
||||||
{
|
{
|
||||||
|
|
@ -52,7 +50,7 @@ class GameSession
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Get Settings
|
||||||
*/
|
*/
|
||||||
public function getSettings() : GameSettings
|
public function getSettings() : GameSettings
|
||||||
{
|
{
|
||||||
|
|
@ -60,10 +58,11 @@ class GameSession
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Set new settings
|
||||||
*/
|
*/
|
||||||
public function setSettings(GameSettings $settings)
|
public function setSettings(GameSettings $settings) : self
|
||||||
{
|
{
|
||||||
$this->settings = $settings;
|
$this->settings = $settings;
|
||||||
|
return $this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,9 @@ class Character extends Model
|
||||||
'name',
|
'name',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all cards associated with this character
|
||||||
|
*/
|
||||||
public function cards()
|
public function cards()
|
||||||
{
|
{
|
||||||
return $this->hasMany(Card::class);
|
return $this->hasMany(Card::class);
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,9 @@ class Raid extends Model
|
||||||
'name',
|
'name',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all cards associated with this raid
|
||||||
|
*/
|
||||||
public function cards()
|
public function cards()
|
||||||
{
|
{
|
||||||
return $this->hasMany(Card::class);
|
return $this->hasMany(Card::class);
|
||||||
|
|
|
||||||
|
|
@ -47,14 +47,4 @@ class Setting extends Model
|
||||||
{
|
{
|
||||||
return $q->where('id', Hashids::decode($hash));
|
return $q->where('id', Hashids::decode($hash));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
public function __call($method, $parameters)
|
|
||||||
{
|
|
||||||
if ($method == 'find' && is_string($parameters[0])) {
|
|
||||||
$parameters[0] = Hashids::decode($$parameters[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return parent::__call($method, $parameters);
|
|
||||||
} */
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Reference in a new issue