i am a newbie programmer and want to tryng develop a Knight vs Monster Game using java and i am having trouble as to how to make it so fighting between monster and knight. Which classes and method should i be using in order to approach this problem ?
I shall add this question to our games forum. Games programming is a science in its own right, which I know little about. Before you write any code, you should work out the logic of the application (here, you call that the rules of the game). Please show us what the rules are. That way you know you are programming code to match the rules.
A few comments about your code:-
1: It is good to see somebody who knows how to format code well
2: I can see similarities between the two classes. Consider whether to make them subclasses of an abstract superclass.
2: Your comments look good; they tell readers something they don't know. But I think you should add documentation comments so users know what the methods all do.
3: Why have you got those setXXX() method?
4: Be careful about parameter names. Prefer this:-
to this:-It has the advantage that you are “exposing” the good variable name which you have spent so much time choosing carefully. The same applies to setXXX() methods.
5: What does the predicate in line 113 mean? It looks as if you had meant to write if(...) and forgotten the if.
6: Move all that code out of the main() method into a Game#play() (or similar) method. The ideal length of a main() method is one statement.
7: I prefer printf() to using the + operator and println. I don't use \n, but printf() and %n. I like to join multiple print instcutions into one larger instruction.
Please use the code button for all code. Since you are new, I applied the code button to your code, and doesn't it look better now
8: Why have you got a Knight field (line 63)? You don't appear to use it. Why did you declare it as type Object? The name of a field should be spelt knight.
9: Why are you using random.nextInt() in some places and Math.random() elsewhere? I would prefer random.nextInt() everywhere. Use the same Random object throughout; you usually don't need multiple Random objects.