Game Development Reference
In-Depth Information
if (_health <= 0)
{
_dead ¼ true;
}
} ...
}
class Player
{
...
int _health ¼ 10;
bool _dead ¼ false;
int _shieldPower ¼ 2;
void OnShot()
{
if (_shieldPower > 0)
{
_shieldPower--;
return;
}
_health--;
if (_health <= 0)
{
_dead ¼ true;
}
}
...
}
The above code is becoming more difficult to maintain. It could be a lot cleaner
if the repeated code was refactored into a parent class.
class Spacecraft
{
int _health ¼ 10;
bool _dead ¼ false;
int _shieldPower ¼ 2;
void OnShot()
{
if (_shieldPower > 0)
{
_shieldPower--;
return;
}
Search WWH ::




Custom Search