我对 Java 还很陌生,但我个人觉得我的代码很草率,变量太多。我知道我可以将它们隐藏在方法或类中,但我听说将它们放在单独的类中是不好的做法,而且它们中的大多数都不是静态的。谁能给我一些提示?提前致谢!
public static float c = .2f; //cube dimensions
private float separation = 4.0f*c;
private float angle = 0f; //set to 0
private float rotate = 1.0f;
private float h_height = 1.0f;
private float h_width = 1.0f;
private float h_length = 1.0f;
private float b_height = 1.5f;
private float b_width = .5f;
private float b_length = 1.0f;
private float a_height = 1.5f;
private float a_width = .5f;
private float a_length = .5f;
private float l_height = 1.5f;
private float l_width = .5f;
private float l_length = .5f;
private float h_x_s = 0.0f*c;
private float h_y_s = 5.0f*c;
private float h_z_s = 0.0f*c;
private float h_x;
private float h_y;
private float h_z;
private float b_x_s = 0.0f*c;
private float b_y_s = 2.5f*c;
private float b_z_s = 0.0f*c;
private float b_x;
private float b_y;
private float b_z;
private float a_x_s = 1.5f*c;
private float a_y_s = 2.5f*c;
private float a_z_s = .0f*c;
private float a_x;
private float a_y;
private float a_z;
private float l_x_s = .5f*c;
private float l_y_s = -.5f*c;
private float l_z_s = 0.0f*c;
private float l_x;
private float l_y;
private float l_z;
private float a_rotate = 0f;
private float a_speed = .6f;
private float l_rotate = 0;
private float l_speed = .6f;
private double a_c;
private double l_c;
private double a_s;
private double l_s;
private float max_a = 30f; //angle
private float max_l = 30f; //angle
private boolean a_forward;
private boolean l_forward;
private float move_z = 0; //set to 0
private float speed_z = .01f*separation;
private float max_z = 2*separation;
private boolean forward_z;
PS评论实际上并不是变量的用途,只是在调试时提醒我。此外,我的变量名称可能会遭到专业开发人员的反对,但我可以轻松地跟踪它。就像我之前说的,这些变量中的大多数都在积极变化,并在多种方法中使用,但有一些我不在,我可以躲起来。