This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I'm looking for feedback on my simple fighting program. It runs just fine and I don't see any bugs, so I'm looking for feedback on what I could've done to make it less verbose, more readable, and just generally want to hear any advice you guys have to improve.
I have a feeling that there is a much easier way to implement a structure that avoids displaying a negative health value rather than all those if/else statements...
I will post all of the classes in their entirety:
Some sample output(with many of the rounds cut out so you guys don't kill me :S):
Nothing is withheld from us what we have conceived to do. -Russel Kirsch-
The code is good. Three things I can think of to improve:
1) Change "else if(ninjaHealth <=0 && boxerHealth <= 0)" to "else" and remove the else that says the code shouldn't get there. The if/else blocks are mutually exclusive so you can just end with an else and make the extra one impossible.
2) Add a helper method the outputs the boxer health, ninja health and a message so there isn't code all over that looks like:
Instead you would have:
This makes the main logic easier to read and removes some repetition.
3) The Boxer and Ninja classes are the same except for the value. You could have a generic Fighter class that takes this value as a constructor. Or create subclasses of that generic Fighter class to supply that value.