I'm rather new to programming and Java specifically. I'm currently building a game with a Ship
object. It has the following data members;
int START_M_ENERGY = 21;
int START_C_ENERGY = 1;
int STARTING_HEALTH = 5;
int maximalEnergyLevel = STARTING_MAX_ENERGY;
int currentEnergyLevel = STARTING_CURRENT_ENERGY;
The code also has a 'death' method. This method basically resets all of these data members back to their original values (as they change during the game). The method basically looks exactly like the code above.
So, is this considered 'duplicate code'? Is there a way to avoid it? (We're not allowed to use abstract classes or something yet, not sure if it's related but i've seen the subject pop up). Important to note, the SpaceShip
class has no constructor because I think initializing these as members make sense. Will calling the constructor upon death make sense? I don't want the object to be replaced upon death, only resetted!
Thanks!