Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/374.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java GridWorld,网格未扩展_Java_Gridworld - Fatal编程技术网

Java GridWorld,网格未扩展

Java GridWorld,网格未扩展,java,gridworld,Java,Gridworld,基本上,我制作了一个类来扩展网格到11乘11,构造函数被调用,但是它并没有改变网格。如有任何关于原因的意见或信息,将不胜感激。我已经在下面发布了我的代码: import info.gridworld.actor.*; import info.gridworld.grid.BoundedGrid; public class ChangeGrid extends ActorWorld{ private static final int SIZEROW = 11; private static f

基本上,我制作了一个类来扩展网格到11乘11,构造函数被调用,但是它并没有改变网格。如有任何关于原因的意见或信息,将不胜感激。我已经在下面发布了我的代码:

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

public class ChangeGrid extends ActorWorld{

private static final int SIZEROW = 11;
private static final int SIZECOL = 11;

public ChangeGrid()
{
    super(new BoundedGrid<Actor>(SIZEROW, SIZECOL));
    System.out.println("test");
}

}


import info.gridworld.actor.Bug;
public class XBug extends Bug {
    /**
     * A <code>BoxBug</code> traces out a square "box" of a given size. <br />
     * The implementation of this class is testable on the AP CS A and AB exams.
     */

        private int steps;
        private int sideLength;
        private int x = 0;

        private static ChangeGrid object = new ChangeGrid();


        /**
         * Constructs a box bug that traces a square of a given side length
         * @param length the side length
         */
        public XBug(int length)
        {
            steps = 0;
            sideLength = length;
        }

        /**
         * Moves to the next location of the square.
         */
        public void act()
        {
            if (steps < sideLength && canMove())
            {
                if(x==0)
                {
                    turn();
                }
                move();
                steps++;
                x++;
            }
            else
            {
                turn();

                steps = 0;
            }
        }

}

创建世界时未调用构造函数。您在
Actors
类中调用它,然后甚至不调用
.show()
方法。您只需要将runner类更改为调用
ChangeWorld
,而不是
ActorWorld

下面是一个代码示例

    public class Runner 
    {
        public static void main(String[]args)
        {
            ChangeWorld world = new ChangeWorld();
            XBug bug = new XBug();

            world.add(bug);

            world.show();
        }
    }    

您的
XBug
构造函数设置两个整数。就这样。你期望它做什么呢?
XBug
类似乎与实际问题无关。但是,似乎缺少一些可能相关的代码。例如,
ChangeGrid
在何处以及如何使用,或者是否打印了“测试”并表明修改后的构造函数实际上被调用。。。