Hi everybody 
I am trying to code cleaner by creating dedicated php classes (in separate files) to manage card behaviour.
All these class inherit from a base class that I would call MyClass for this example.
But within these class method, I would need to access some game methods and properties (from mygame.game.php) such as:
But is that the right way to do this?
Will that referencing work at any time in the game? (player action, game state action and arguments, zombie turn...).
Thanks for your insights!
Take care,
Wood
I am trying to code cleaner by creating dedicated php classes (in separate files) to manage card behaviour.
All these class inherit from a base class that I would call MyClass for this example.
But within these class method, I would need to access some game methods and properties (from mygame.game.php) such as:
- self::loadPlayerBasicInfos
- $this->cards (deck component)
But is that the right way to do this?
Will that referencing work at any time in the game? (player action, game state action and arguments, zombie turn...).
Code: Select all
// In myclass.php
abstract class MyClass {
public static MyGame $game; // This will store the reference of the game object
public doSomeStuff() {
$card_in_db = self::$game->cards->getCard($id);
$players = self::$game->loadPlayerBasicInfos();
[...]
Code: Select all
// In mygame.game.php
class MyGame extends Table {
function __construct() {
parent::__construct();
// Pass a reference to the game object to MyClass
MyClass::$game = $this;
[...]
Take care,
Wood