小编Max*_*ian的帖子

如何抛出并捕获IllegalArgumentException?

所以基本上我有一个GridWorld项目,我现在正在AP Comp Sci课程中做.我在做Pacman.这是我的act方法的代码(对于那些不熟悉GridWorld的人来说,每当一个actor需要做一个新的动作时都会调用act方法):

public void act()
{
    Location loc = getLocation();

    if(direction==null) {
    }

    else if(direction.equals("NORTH")) {
        Location next = loc.getAdjacentLocation(loc.NORTH);
        if(getGrid().isValid(next) && (getGrid().get(next)==null || getGrid().get(next) instanceof Food)) {
            if(getGrid().get(next) instanceof Food)
                addFood();
            moveTo(next);
            direction = "NORTH";
        }
    }

    else if(direction.equals("SOUTH")) {
        Location next = loc.getAdjacentLocation(loc.SOUTH);
        if(getGrid().isValid(next) && (getGrid().get(next)==null || getGrid().get(next) instanceof Food)) {
            if(getGrid().get(next) instanceof Food)
                addFood();
            moveTo(getLocation().getAdjacentLocation(getLocation().SOUTH));
            direction = "SOUTH";
        }
    }

    else if(direction.equals("EAST")) {
        Location next = loc.getAdjacentLocation(loc.EAST);
        if(getGrid().isValid(next) && (getGrid().get(next)==null || getGrid().get(next) instanceof Food)) {
            if(getGrid().get(next) …
Run Code Online (Sandbox Code Playgroud)

java gridworld

4
推荐指数
1
解决办法
3万
查看次数

标签 统计

gridworld ×1

java ×1