42 lines
757 B
PHP
42 lines
757 B
PHP
<?php
|
|
|
|
namespace App\Game;
|
|
|
|
class GameService
|
|
{
|
|
/**
|
|
* The game session
|
|
*/
|
|
protected GameSession $session;
|
|
|
|
/**
|
|
* Construct a new Game Service
|
|
*/
|
|
public function __construct(GameSession $session)
|
|
{
|
|
$this->session = $session;
|
|
}
|
|
|
|
/**
|
|
* Get the current session
|
|
*/
|
|
public function session() : GameSession
|
|
{
|
|
return $this->session;
|
|
}
|
|
|
|
/**
|
|
* Generate a new Game session
|
|
*/
|
|
public function newSession(?GameSettings $settings = null) : self
|
|
{
|
|
if (!$settings) {
|
|
$settings = $this->session()->getSettings();
|
|
}
|
|
|
|
// Generate a new board
|
|
$this->session->getBoard()->regenerate($settings);
|
|
|
|
return $this;
|
|
}
|
|
}
|