//坦克类
class Tank
{ //x表示坦克的横坐标
int x=0;
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
//y表示坦克的纵坐标
int y=0;
public Tank(int x,int y)
{
this.x=x;
this.y=y;
}
//定义坦克方向
//0表示向上,1右,2下,3左
int direct=0;
public int getDirect() {
return direct;
}
public void setDirect(int direct) {
this.direct = direct;
}
//设置坦克的速度
int speed=5;
public int getSpeed() {
return speed;
}
public void setSpeed(int speed) {
this.speed = speed;
}
int color;
public int getColor() {
return color;
}
public void setColor(int color) {
this.color = color;
}
}
//敌人的坦克
class Enemytank extends Tank
{
public Enemytank(int x,int y)
{
super(x,y);
}
}
//定义我的坦克
class Hero extends Tank
{
public Hero(int x,int y)
{
super(x,y);
}
//坦克向上移动
public void moveup()
{
y-=speed;
}
//坦克向右异底洞
public void moveright()
{
x+=speed;
}
public void moverdown()
{
y+=speed;
}
public void moverleft()
{
x-=speed;
}
class Tank
{ //x表示坦克的横坐标
int x=0;
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
//y表示坦克的纵坐标
int y=0;
public Tank(int x,int y)
{
this.x=x;
this.y=y;
}
//定义坦克方向
//0表示向上,1右,2下,3左
int direct=0;
public int getDirect() {
return direct;
}
public void setDirect(int direct) {
this.direct = direct;
}
//设置坦克的速度
int speed=5;
public int getSpeed() {
return speed;
}
public void setSpeed(int speed) {
this.speed = speed;
}
int color;
public int getColor() {
return color;
}
public void setColor(int color) {
this.color = color;
}
}
//敌人的坦克
class Enemytank extends Tank
{
public Enemytank(int x,int y)
{
super(x,y);
}
}
//定义我的坦克
class Hero extends Tank
{
public Hero(int x,int y)
{
super(x,y);
}
//坦克向上移动
public void moveup()
{
y-=speed;
}
//坦克向右异底洞
public void moveright()
{
x+=speed;
}
public void moverdown()
{
y+=speed;
}
public void moverleft()
{
x-=speed;
}
}
//父类tank中分别包括x坐标,y坐标,tank的方向,颜色,速度属性
//分别对其进行setget方法,setget方法可以通过外部进行调用和设置,保护了系统信息的私密性
//子类中有super(),代表在子类调用父类的构造函数,每一子类的构造方法第一行必须是这样,因为要实例化子类必须先实例化父类