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;
}
を組み合わせたJavaメソッドを取得:トラブル私はすでに次を持って一つのメインの方法で
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.
.............?
}
それはちょうど組み合わせていますこれらは私が問題を抱えている。
欲しいものだと思いますか? – joostschouten
@jootschoutenステータスは2つのEnum {Visited、NotVisited}で構成されます。達成したいのは、コードの最後のブロックで強調されています。 "//私はこれまでに次の行を行っています"というテキストのすぐ下の行。動かない。 – maclunian
@jootschouten私がしたいのは、バグを 'board 'のある場所から別の場所に移動することです(長期的には)。ボードは座標(x、y)からなる。 'next()'は、どちらが初期であるかに応じて、ステータスを「NotVisited」から「Visited」に、またはその逆に変更します。 – maclunian