坦克大战——坦克类

//坦克类
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(),代表在子类调用父类的构造函数,每一子类的构造方法第一行必须是这样,因为要实例化子类必须先实例化父类


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值