1

我想将 gridworld 中的网格从默认的 10x10 调整为我想要的任何大小。我一直在用 15x15 对其进行测试,看看它是否有效。但我似乎无法弄清楚这一点,互联网上的其他消息来源说我正在做的事情应该有效。

即使我尝试设置rowSize& colSize,网格仍保持在 10x10,我该如何解决这个问题,以便将网格打开到 15x15 屏幕?

这个类是我调整网格大小的地方

import info.gridworld.actor.*;
import info.gridworld.grid.BoundedGrid;

public class pokeGrid extends ActorWorld{

    private static final int rowSize = 15;
    private static final int colSize = 15;

    public pokeGrid(){
        super(new BoundedGrid<Actor>(rowSize, colSize));
    }
}

这个类是actor的runner

public class BeecherBugRunner extends pokeGrid {

    private static pokeGrid world = new pokeGrid();

    public static void main(String[] args)
    {
        ActorWorld world = new ActorWorld();
        BeecherBug beecher = new BeecherBug(4);
        world.add(new Location(7, 8), beecher);
        world.show();
    }
}
4

1 回答 1

3
private static pokeGrid world = new pokeGrid();

public static void main(String[] args)
{
    ActorWorld world = new ActorWorld();

    ...
}

这里的问题是声明world的基类型变量隐藏了您的成员变量。因此,后续方法调用在默认世界类型上运行,而不是您自定义的世界类型。ActorWorldmainpokeGridworldworld

要解决此问题,请ActorWorld world = ...main. 然后方法调用将在您的自定义类上运行。

于 2014-05-16T17:08:03.470 回答