I don't know what it is called as, I believe it is instances.
Let's say we have a "Monster" class. This class should contain "Health" value. It is set to "5" on class creation. It should also contain an unique ID value for each monster.
I think about something like this:
$monster_1 = new Monster(); //sets monster ID to 1 $monster_2 = new Monster(); //sets monster ID to 2 $monster_3 = new Monster(); //sets monster ID to 3 So, let's say I want to calculate the total HP of all monsters.
$totalHp = $monster_1->getHp() + $monster_2->getHp() + $monster_3->getHp(); It will also work, but what if I add a new monster named $monster_4. I would have to add it to $totalHp calculation manually.
I could make an array instead of $monster variables, and calculate the $totalHp with foreach - but it looks weird...
I don't know how it is being done in other languages.
Is there any other way to archieve this?
Ps. I'm trying to get the logic behind "http://www.scirra.com/demos/ghosttutorial/" game. You create a Monster class, and each Monster uses this class as an instance. My solution would definitely work, but I'm not sure if it is a hacky way to archieve this.
eval()but it'd be quite hacky. The array thing seems your best bet, I'd say go with it.