I am working on robot simulations in Java (Swing application). I have an abstract class "Robot" from which different types of robots are made, for example.
public class StupidRobot extends Robot {
int m_stupidness;
int m_insanityLevel;
...
}
public class AngryRobot extends Robot {
float m_aggression;
...
}
As you can see, each Robot subclass has a different set of parameters.
What I would like to do is manage the simulation setup in the original user interface. Select the number and type of robots, indicate their name, fill in the parameters, etc.
This is one of those times when I was such a dinosaur programmer and new to Java, I wonder if there are any higher-level things / thinking that could help me here. So here is what I got:
(1) User Interface
.
" → " "<" ".
.
" ".
(, AngryRobot, AngryRobot , " → " "AngryRobot1" .)
" ...", , .
.
(2)
, , HashMap . , . . :
enum ROBOT_TYPE {STUPID, ANGRY, etc}
public class RobotInitializer {
public ROBOT_TYPE m_type;
public string m_name;
public int[] m_int_params;
public float[] m_float_params;
etc.
:
public RobotInitializer(ROBOT_TYPE type, int[] int_array, float[] float_array, etc){
switch (type){
case STUPID:
m_int_params = new int[STUPID_INT_PARAM_LENGTH];
System.arraycopy(int_array,0,m_int_params,0,STUPID_INT_PARAM_LENGTH);
etc.
RobotInitializers HashMap.
HashMap, Hashmap .
? , ?