gpt4 book ai didi

java - MovableObject java语法错误

转载 作者:行者123 更新时间:2023-11-30 11:25:27 25 4
gpt4 key购买 nike

我有一个处理对象位置的 Tile 类。编译器对该类没有任何问题。

但是,当我尝试在 MovableObject 中使用该类时,我无法在创建新 Tile 时使用这些方法。

这是我的代码:

package game;

public class Tile {
int posx;
int posy;
int indice;
Tile [] proximasSalidas;
//int fila;
//int columna;
public boolean esInterseccion;
boolean esPasillo;
boolean esL;
Tile [] adyacencias;

public Tile(){
posx = 0;
posy = 0;
proximasSalidas = null;
esInterseccion = false;
esPasillo = false;
esL = false;
adyacencias = null;
}

public Tile(int posx,int posy,Tile [] adyacencias,Tile [] proximasSalidas,boolean esPasillo, boolean esInterseccion, boolean esL){
this.posx = posx;
this.posy = posy;
this.proximasSalidas = proximasSalidas;
this.adyacencias = adyacencias;
this.esInterseccion = esInterseccion;
this.esPasillo = esPasillo;
this.esL = esL;
}

public void setValores(int posx,int posy,Tile [] adyacencias,Tile [] proximasSalidas,boolean esPasillo, boolean esInterseccion, boolean esL){
this.posx = posx;
this.posy = posy;
this.proximasSalidas = proximasSalidas;
this.adyacencias = adyacencias;
this.esInterseccion = esInterseccion;
this.esPasillo = esPasillo;
this.esL = esL;
}



}

还有我的 MovableObject 类:

package game;

import java.awt.Graphics2D;

import com.golden.gamedev.*;
import com.golden.gamedev.*;
import com.golden.gamedev.engine.*;
import com.golden.gamedev.object.*;
import com.golden.gamedev.object.sprite.*;
import com.golden.gamedev.engine.BaseAudioRenderer;

public class MovableObject {

public int columna;
public int fila;
public int pos_x;
public int pos_y;
private int moveSize;
public int direction;
public int[] availableDirections;
public int targetTile;


Tile t1 = new Tile(1,1,null,null,false,false,false);//no es pasillo
Tile t0 = new Tile(1,1,null,null,true,false,false);//es pasillo



//adyacencias,proximasSalidas,es pasillo,es interseccion,esL

Tile t3 = new Tile(1,1,null,null,true,false,false);//no es interseccion
Tile t4 = new Tile(1,1,null,null,true,false,false);//no es interseccion
Tile t6 = new Tile(1,1,null,null,true,false,false);//no es interseccion
Tile t7 = new Tile(1,1,null,null,true,false,false);//no es interseccion
Tile t10 = new Tile(1,1,null,null,true,false,false);//no es interseccion
Tile t11 = new Tile(1,1,null,null,true,false,false);//no es interseccion
Tile t13 = new Tile(1,1,null,null,true,false,false);//no es interseccion
Tile t14 = new Tile(1,1,null,null,true,false,false);//no es interseccion
Tile t16 = new Tile(1,1,null,null,true,false,false);//no es interseccion
Tile t17 = new Tile(1,1,null,null,true,false,false);//no es interseccion
Tile t18 = new Tile(1,1,null,null,true,false,false);//no es interseccion
Tile t19 = new Tile(1,1,null,null,true,false,false);//no es interseccion
Tile t20 = new Tile(1,1,null,null,true,false,false);//no es interseccion
Tile t21 = new Tile(1,1,null,null,true,false,false);//no es interseccion
Tile t23 = new Tile(1,1,null,null,true,false,false);//no es interseccion
Tile t25 = new Tile(1,1,null,null,true,false,false);//no es interseccion
Tile t27 = new Tile(1,1,null,null,true,false,false);//no es interseccion
Tile t29 = new Tile(1,1,null,null,true,false,false);//no es interseccion
Tile t31 = new Tile(1,1,null,null,true,false,false);//no es interseccion
Tile t33 = new Tile(1,1,null,null,true,false,false);//no es interseccion
Tile t34 = new Tile(1,1,null,null,true,false,false);//no es interseccion
Tile t35 = new Tile(1,1,null,null,true,false,false);//no es interseccion
Tile t36 = new Tile(1,1,null,null,true,false,false);//no es interseccion
Tile t38 = new Tile(1,1,null,null,true,false,false);//no es interseccion
Tile t41 = new Tile(1,1,null,null,true,false,false);//no es interseccion
Tile t43 = new Tile(1,1,null,null,true,false,false);//no es interseccion
Tile t44 = new Tile(1,1,null,null,true,false,false);//no es interseccion
Tile t46 = new Tile(1,1,null,null,true,false,false);//no es interseccion
Tile t48 = new Tile(1,1,null,null,true,false,false);//no es interseccion
Tile t50 = new Tile(1,1,null,null,true,false,false);//no es interseccion
Tile t52 = new Tile(1,1,null,null,true,false,false);//no es interseccion
Tile t53 = new Tile(1,1,null,null,true,false,false);//no es interseccion
Tile t54 = new Tile(1,1,null,null,true,false,false);//no es interseccion
Tile t55 = new Tile(1,1,null,null,true,false,false);//no es interseccion
Tile t57 = new Tile(1,1,null,null,true,false,false);//no es interseccion
Tile t58 = new Tile(1,1,null,null,true,false,false);//no es interseccion
Tile t60 = new Tile(1,1,null,null,true,false,false);//no es interseccion
Tile t61 = new Tile(1,1,null,null,true,false,false);//no es interseccion
Tile t63 = new Tile(1,1,null,null,true,false,false);//no es interseccion
Tile t64 = new Tile(1,1,null,null,true,false,false);//no es interseccion
Tile t66 = new Tile(1,1,null,null,true,false,false);//no es interseccion
Tile t67 = new Tile(1,1,null,null,true,false,false);//no es interseccion
Tile t68 = new Tile(1,1,null,null,true,false,false);//no es interseccion
Tile t69 = new Tile(1,1,null,null,true,false,false);//no es interseccion
Tile t70 = new Tile(1,1,null,null,true,false,false);//no es interseccion
Tile t71 = new Tile(1,1,null,null,true,false,false);//no es interseccion
Tile t72 = new Tile(1,1,null,null,true,false,false);//no es interseccion
Tile t73 = new Tile(1,1,null,null,true,false,false);//no es interseccion
Tile t74 = new Tile(1,1,null,null,true,false,false);//no es interseccion
Tile t75 = new Tile(1,1,null,null,true,false,false);//no es interseccion
Tile t77 = new Tile(1,1,null,null,true,false,false);//no es interseccion
Tile t78 = new Tile(1,1,null,null,true,false,false);//no es interseccion
Tile t80 = new Tile(1,1,null,null,true,false,false);//no es interseccion
Tile t82 = new Tile(1,1,null,null,true,false,false);//no es interseccion
Tile t83 = new Tile(1,1,null,null,true,false,false);//no es interseccion
Tile t85 = new Tile(1,1,null,null,true,false,false);//no es interseccion
Tile t86 = new Tile(1,1,null,null,true,false,false);//no es interseccion
Tile t88 = new Tile(1,1,null,null,true,false,false);//no es interseccion
Tile t90 = new Tile(1,1,null,null,true,false,false);//no es interseccion
Tile t91 = new Tile(1,1,null,null,true,false,false);//no es interseccion
Tile t93 = new Tile(1,1,null,null,true,false,false);//no es interseccion
Tile t94 = new Tile(1,1,null,null,true,false,false);//no es interseccion
Tile t95 = new Tile(1,1,null,null,true,false,false);//no es interseccion
Tile t96 = new Tile(1,1,null,null,true,false,false);//no es interseccion
Tile t97 = new Tile(1,1,null,null,true,false,false);//no es interseccion
Tile t98 = new Tile(1,1,null,null,true,false,false);//no es interseccion
Tile t100 = new Tile(1,1,null,null,true,false,false);//no es interseccion
Tile t101 = new Tile(1,1,null,null,true,false,false);//no es interseccion
Tile t103 = new Tile(1,1,null,null,true,false,false);//no es interseccion
Tile t104 = new Tile(1,1,null,null,true,false,false);//no es interseccion



Tile t2 = new Tile(1,1,new Tile[]{t3,t16},null,true,true,true);//es L
Tile t8 = new Tile(1,1,new Tile[]{t7,t18},null,true,true,true);//es L
Tile t9 = new Tile(1,1,new Tile[]{t19,t10},null,true,true,true);//es L
Tile t15 = new Tile(1,1,new Tile[]{t14,t21},null,true,true,true);//es L
Tile t37 = new Tile(1,1,new Tile[]{t34,t38},null,true,true,true);//es L
Tile t39 = new Tile(1,1,new Tile[]{t38,t43},null,true,true,true);//es L
Tile t40 = new Tile(1,1,new Tile[]{t44,t41},null,true,true,true);//es L
Tile t42 = new Tile(1,1,new Tile[]{t41,t35},null,true,true,true);//es L
Tile t45 = new Tile(1,1,new Tile[]{t46,t60},null,true,true,true);//es L
Tile t51 = new Tile(1,1,new Tile[]{t50,t61},null,true,true,true);//es L
Tile t99 = new Tile(1,1,new Tile[]{t96,t100},null,true,true,true);//es L
Tile t105 = new Tile(1,1,new Tile[]{t98,t104},null,true,true,true);//es L

Tile t56 = new Tile();



t56.setValores(1,1,new Tile[]{t52,t57,t66},new Tile[]{t5,t59,t76},true,true,false);//es interseccion


...

在上面的代码中,编译器无法识别 setValores()(在 MoveableObject 的底部)。

最佳答案

原因

这是因为您的可执行代码不能 float 到类的主体中。

下一行必须位于类方法中。

 t56.setValores(1,1,new Tile[]{t52,t57,t66},new Tile[]{t5,t59,t76},true,true,false);//es interseccion

解释:

对于您的代码块,它是第一行不对应于变量/属性声明并且它包含一些可执行代码,这是您针对该特定行而不是任何其他行获得编译错误的具体原因行之前。

关于您的方法

另一方面,一旦您将此特定行包含到一个方法中,代码就会工作,但这种方法看起来并不是一种有效的编码方式,无论您假装做什么。

关于java - MovableObject java语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20279261/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com