我正在创建一个制作房间的工厂,它通过一个步骤和一个开始房间,它应该做一个步骤,建立一个房间,然后用一个较少的步骤和新房间作为开始房间自行呼叫.问题是它永远不会结束.在调试器中,我可以看到它正在调用自身,这会在内存中创建另一个实际上只有一个步骤的方法调用,但是执行行将转到当前方法调用的顶部!所以它永远不会真正完成新的通话.好像它将新调用放入堆而不是堆栈,然后实际上从未实现过.
码:
@Override
public Room place(Level level, int cycles, Room start_room,
Direction direction, int shop, int exit, LevelFactoryReport report) throws Exception
{
Room room = null;
if(cycles < 1)
{
return start_room;
}
else
{
report.addEvent("--Placer step--");
report.addEvent("Steps remaining: "+cycles);
room = this.Step(level, start_room, direction, shop, exit, report);
if(room == null)
{
cycles = 0;
report.addEvent("Step returned a null room (probably because it ran into an existing room). Ending cycle.");
}
}
return place(level, (cycles--), room, direction, (shop--), …Run Code Online (Sandbox Code Playgroud)