Java 爪哇:超级班赢了';超驰控制功能
我已经做了一段时间的游戏,我想有一个不同的类为每种类型的生物,有。现在,所有不同生物的AI都在一个长的开关中运行,我想要一个超类来验证该生物的AI功能。我已经设置好了,但无法覆盖 我忘了什么吗 Bunny.java:Java 爪哇:超级班赢了';超驰控制功能,java,superclass,overriding,Java,Superclass,Overriding,我已经做了一段时间的游戏,我想有一个不同的类为每种类型的生物,有。现在,所有不同生物的AI都在一个长的开关中运行,我想要一个超类来验证该生物的AI功能。我已经设置好了,但无法覆盖 我忘了什么吗 Bunny.java: package creature; import org.newdawn.slick.opengl.Texture; import creature.Creature; import creature.CreatureType; import data.Tile; publi
package creature;
import org.newdawn.slick.opengl.Texture;
import creature.Creature;
import creature.CreatureType;
import data.Tile;
public class Bunny extends Creature{
public Bunny(CreatureType type, float x, float y, float speed1) {
super(type, x, y, speed1);
}
public void AI(int type) {
System.out.println("test");
}
}
bioter.java:
public Creature(CreatureType type, float x, float y, float speed1) {
this.texture = drawImg(type.textureName);
this.textureHamster = drawImg("creatures/HamsterFace");
this.healthBackground = drawImg("health_background");
this.healthForeground = drawImg("health_foreground");
this.healthBorder = drawImg("health_border");
this.startTile = startTile;
this.x = x;
this.y = y;
this.intX = (int) x;
this.intY = (int) y;
this.width = texture.getImageWidth();
this.height = texture.getImageHeight();
this.speed1 = speed1;
this.speed = speed;
this.intspeed = speed;
this.grid = grid;
this.health = type.health;
this.inithealth = type.health;
this.hiddenHealth = health;
this.startHealth = health;
this.dir = false;
this.dchosen = false;
this.setx = 0;
this.hurt = 0;
this.panick = 0;
this.deathWish = 0;
this.pdir = -1;
this.myX = x;
this.myY = HEIGHT / 2;
this.right = false;
this.left = false;
this.fade = 0;
this.fir = true;
this.aiType = type.aiType;
this.yOffset = 0;
}
.....
public void AI(int type) {
if(panic > 0)
panic--;
hurt();
speed = speed1;
switch(type) {
case 1:
if(panic > 0) {
if(pickRandom(150, 300) < 10) {
direction = !direction;
}
if(direction) {
if(!right) {
x += speed;
} else {
if(falling < 2)
gravity = 8;
}
} else {
if(!left) {
x -= speed;
} else {
if(falling < 2)
gravity = 8;
}
}
} else {
if(getRange(WIDTH / 2, myX) > 200) {
directionCoolDown++;
if(directionCoolDown > pickRandom(150, 3000)) {
direction = !direction;
directionCoolDown = 0;
}
if(direction) {
if(!right) {
x += speed / 3.2;
} else {
if(falling < 2)
gravity = 8;
}
} else {
if(!left) {
x -= speed / 3.2;
} else {
if(falling < 2)
gravity = 8;
}
}
} else {
if(myX < WIDTH / 2) {
direction = true;
} else {
direction = false;
}
}
}
break;
case 2:
yOffset = -25;
if(!angry) {
pdir = 0;
if(getRange(Player.getX(), myX) < 300) {
hamsterFace = true;
} else {
hamsterFace = false;
}
if(!hamsterFace) {
directionCoolDown++;
if(directionCoolDown > pickRandom(150, 3000)) {
direction = !direction;
directionCoolDown = 0;
}
if(direction) {
if(!right) {
x += speed / 3.2;
} else {
if(falling < 2)
gravity = 8;
}
} else {
if(!left) {
x -= speed / 3.2;
} else {
if(falling < 2)
gravity = 8;
}
}
}
} else {
pdir++;
hamsterFace = false;
if(myX < Player.getX()) {
direction = true;
} else {
direction = false;
}
if(direction) {
if(!right) {
x += speed / 1;
} else {
if(falling < 2)
gravity = 8;
}
} else {
if(!left) {
x -= speed / 1;
} else {
if(falling < 2)
gravity = 8;
}
}
if(getRange(myX, Player.getX()) < 5 && getRange(myY, Player.getY()) < 5) {
hurtPlayer(-2);
direction = !direction;
if(direction) {
if(!right) {
x += speed * 10;
} else {
if(falling < 2)
gravity = 8;
}
} else {
if(!left) {
x -= speed * 10;
} else {
if(falling < 2)
gravity = 8;
}
}
}
}
if(panic > 1) {
angry = true;
} else {
if(pdir > pickRandom(1000,2000)) {
angry = false;
}
}
break;
}
}
.....
公共生物(生物类型、浮点数x、浮点数y、浮点数速度1){
this.texture=drawImg(type.textureName);
this.textureHamster=绘图(“生物/仓鼠脸”);
this.healthBackground=图纸(“健康背景”);
this.healthForeground=图纸(“健康前景”);
this.healthBorder=图纸(“健康边界”);
this.startTile=startTile;
这个.x=x;
这个。y=y;
this.intX=(int)x;
this.intY=(int)y;
this.width=texture.getImageWidth();
this.height=texture.getImageHeight();
此参数为.speed1=speed1;
速度=速度;
这个.intspeed=速度;
this.grid=grid;
this.health=type.health;
this.inithealth=type.health;
hiddenheath=健康;
this.startHealth=健康;
this.dir=false;
this.dchosen=false;
这个.setx=0;
this.hurt=0;
这是0.k=0;
这是死亡之翼=0;
这个值为0.pdir=-1;
this.myX=x;
this.myY=高度/2;
this.right=false;
this.left=false;
该值为0;
this.fir=真;
this.aiType=type.aiType;
此值为0.yOffset=0;
}
.....
公共无效AI(整型){
如果(恐慌>0)
恐慌--;
伤害();
速度=速度1;
开关(类型){
案例1:
如果(恐慌>0){
if(随机选取(150300)<10){
方向=!方向;
}
如果(指示){
如果(!对){
x+=速度;
}否则{
如果(下降<2)
重力=8;
}
}否则{
如果(!左){
x-=速度;
}否则{
如果(下降<2)
重力=8;
}
}
}否则{
如果(getRange(宽度/2,myX)>200){
方向冷却++;
如果(方向冷却>随机选取(1503000)){
方向=!方向;
方向冷却时间=0;
}
如果(指示){
如果(!对){
x+=速度/3.2;
}否则{
如果(下降<2)
重力=8;
}
}否则{
如果(!左){
x-=速度/3.2;
}否则{
如果(下降<2)
重力=8;
}
}
}否则{
如果(myX<宽度/2){
方向=真;
}否则{
方向=假;
}
}
}
打破
案例2:
yOffset=-25;
如果(!生气){
pdir=0;
if(getRange(Player.getX(),myX)<300){
仓鼠脸=真;
}否则{
仓鼠脸=假;
}
如果(!仓鼠脸){
方向冷却++;
如果(方向冷却>随机选取(1503000)){
方向=!方向;
方向冷却时间=0;
}
如果(指示){
如果(!对){
x+=速度/3.2;
}否则{
如果(下降<2)
重力=8;
}
}否则{
如果(!左){
x-=速度/3.2;
}否则{
如果(下降<2)
重力=8;
}
}
}
}否则{
pdir++;
仓鼠脸=假;
if(myX1){
愤怒=真实;
}否则{
如果(pdir>pickRandom(10002000)){
愤怒=虚假;
}
}
打破
}
}
.....
(两个类都在同一个包中)
编辑:我修正了打字错误….你在兔子课上的错误:
public void AI() {
System.out.println("test");
}
在生物类中:
public void AI(int type) {
if(panic > 0)
....
所以
void AI(int-type)
和void AI()
不是同一种方法(检查签名以及它们如何获取不同的参数!)
ther