将 java 方法合并到一个主方法中时遇到问题
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.
.............?
}
它只是将我遇到问题的这些内容组合起来。
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;
}
I already have the following:
Status status(Integer x, Integer y) {
return board[x][y];
}
void update(Integer x, Integer y) {
board[x][y].next();
}
This part below is where I'm having some trouble:
/* 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.
.............?
}
It's just combining these that I'm having trouble with.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
很难理解你想要做什么,但我认为这就是你想要的
It's hard to understand what you're trying to do, but I think here's what you want