我有一个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的底部)。

最佳答案

原因

这是因为您的可执行代码无法浮动到类的主体中。

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

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


说明:

对于您的代码块,这是第一行,它不仅仅与变量/属性声明相对应,还包括一些可执行代码。这是您为该特定行而不是之前的任何其他行遇到编译错误的特定原因。

关于您的方法

另一方面,将特定行包含在方法中后,代码将起作用,但是这种方法看起来并不是编写任何假装的有效方法。

10-02 07:14