同学这学期学JAVA,现在要交作业,是一个坦克大战的程序,代码如下,请高人给出下面三部分注释和函数功能说明,越详细越好,谢谢
package LIHengYan.Tank;
import java.awt.*;
//坦克血条
public class Blood {
int x, y, w, h;
TankClient tc;
int step = 0;
private boolean live = true;
//指明血块运动的轨迹,由pos中各个点构成
private int[][] pos = {
{350, 300}, {360, 300}, {375, 275}, {400, 200}, {360, 270}, {365, 290}, {340, 280}
};
public Blood() {
x = pos[0][0];
y = pos[0][1];
w = h = 15;
}
public void draw(Graphics g) {
if(!live) return;
Color c = g.getColor();
g.setColor(Color.MAGENTA);
g.fillRect(x, y, w, h);
g.setColor(c);
move();
}
private void move() {
step ++;
if(step == pos.length){
step = 0;
}
x = pos[step][0];
y = pos[step][1];
}
public Rectangle getRect() {
return new Rectangle(x, y, w , h);
}
public boolean isLive() {
return live;
}
public void setLive(boolean live) {
this.live = live;
}
}
package LIHengYan.Tank;
import java.awt.*;
//坦克被击中爆炸
public class Explode {
int x, y;
private boolean live = true;
private TankClient tc ;
int[] diameter = {4, 7, 12, 18, 26, 32, 49, 30, 14, 6};
int step = 0;
public Explode(int x, int y, TankClient tc) {
this.x = x;
this.y = y;
this.tc = tc;
}
public void draw(Graphics g) {
if(!live) {
tc.explodes.remove(this);
return;
}
if(step == diameter.length) {
live = false;
step = 0;
return;
}
Color c = g.getColor();
g.setColor(Color.ORANGE);
g.fillOval(x, y, diameter[step], diameter[step]);
g.setColor(c);
step ++;
}
package LIHengYan.Tank;
import java.awt.*;
//墙壁
public class Wall {
int x, y, w, h;
TankClient tc ;
public Wall(int x, int y, int w, int h, TankClient tc) {
this.x = x;
this.y = y;
this.w = w;
this.h = h;
this.tc = tc;
}
public void draw(Graphics g) {
g.fillRect(x, y, w, h);
}
public Rectangle getRect() {
return new Rectangle(x, y, w, h);
}
}
------解决方案--------------------
楼主 这不是分数的问题
首先有求于人 至少要把问题简化 描述清楚 贴代码使用一下[code=Java][/code]这个标签
增强程序可读性...
坦克游戏 我之前有写过一个
楼主需要的话 可以发给你 参考参考
------解决方案--------------------
另外,如果楼主手上有完整的可运行的程序(你贴出来的是不全的),事情就更好弄一些了:
如果什么地方不太懂,改改,运行程序对比效果,就知道改的地方起什么作用的了。
如果想学会编程,记住程序是你最好的朋友,试着和它交流。
记住计算机是你最好的老师,试着问它问题。