I am looking at Should I use multiple classes for game? – Robert Pitt’s answer.
interface Weapons {
public function Fire();
}
class Colt implements Weapons {
function Fire() {
echo 'Fire!';
}
}
abstract class Human implements Colt
{
}
class Sniper extends Human
{
public function __construct()
{
}
}
On the “Human” am I perhaps to implement the “Weapons” rather then Colt, and then on the “Sniper” initialize the Right weapon class?
class Sniper extends Human
{
public $weapon;
public function __construct($weapon)
{
$this->weapon = new $weapon;
}
$this->weapon->fire();
}
Or something like that? I am confused of how it works..
EXAMPLE 1
class A {
public $class;
__construct() {
$this->class = new $class;
}
hello() {
$this->class->hello();
}
}
class B {
public function hello() {
echo 'hi';
}
}
It’s up to you, how will you design your classes.
If I would be a game programmer, I’d probably use something like (it’s a working minigame!)
demo