【发布时间】:2011-06-25 19:22:38
【问题描述】:
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.
.............?
}
只是将我遇到问题的这些结合起来。
【问题讨论】:
-
你想达到什么目的,什么没用?
-
@jootschouten 状态由两个枚举 {Visited, NotVisited} 组成。我想要实现的目标在最后一段代码中突出显示。文本“//到目前为止我已经完成了以下(下一行)”正下方的行。不工作。
-
@jootschouten 我想做的是将错误从
board上的一个地方移到另一个地方(从长远来看)。board由坐标 (x,y) 组成。next()将状态从NotVisited更改为Visited,反之亦然,具体取决于哪个是初始状态。 -
请问,您为什么始终使用 Integer 而不是 int?
-
错误状态(整数 x,整数 y);是没有意义的。即使缺少点,状态也不是静态方法,并且您没有捕获返回值。
标签: java methods accessor mutators