Проблемы с получением Java-методов в одном основном методе - PullRequest
0 голосов
/ 25 июня 2011
class Bug {

// An ant is represented by the coordinates of its location,
// and the direction it is facing.
Integer x;
Integer y;
Dir dir;

enum Dir { E,W,N,S }
}

Bug(Integer x, Integer y, Dir dir) {
    this.x = x;
    this.y = y;
    this.dir = dir;
}}

class BugWorld {


Integer theBreadth, theHeight;
Board board;
Bug bug;

BugWorld(Integer breadth, Integer height) {
    board = new board(breadth, height);
    bug = new Bug(breadth/2, height/2, Ant.Direction.Y);
    theBreadth = breadth;
    theHeight = height;
}

У меня уже есть следующее:

Status status(Integer x, Integer y) {
    return board[x][y];
}


void update(Integer x, Integer y) {
    board[x][y].next();
}

В этой части у меня возникли некоторые проблемы:

/* Take the world of the bug to the next step. */
void step() {
    // 1) Get the state at the present bug position.
          //I've done the following (next line) so far.
           Bug status(Integer x, Integer y); ...?

    // 2) Change the 'status' at that position.
             .............?
}

У меня просто проблемы с этим.

1 Ответ

0 голосов
/ 25 июня 2011

Трудно понять, что ты пытаешься сделать, но я думаю, вот чего ты хочешь

void step(){

     //get the location of the bug 
     int x = bug.x;
     int y = bug.y;

     //gets the status of the location of the bug
     Status s = status(x,y);

     //move the bug, or do something based on the status of the place

     //update the status of the location the bug was originally on
     update(x,y)
}
...