Stack Overflow Error

Posted by dylanisawesome1 on Game Development See other posts from Game Development or by dylanisawesome1
Published on 2012-12-08T06:23:48Z Indexed on 2012/12/08 11:39 UTC
Read the original article Hit count: 386

I recently created a recursive cave algorithm, and would like to have more extensive caves, but get a stack overflow after re-cursing a couple times. Any advice? Here's my code:

for(int i=0;i<100;i++) {
      int rand = new Random().nextInt(100);
      if(rand<=20) {
        if(curtile.bounds.y-40>500+new Random().nextInt(20))
          digDirection(Direction.UP);
      }
      if(rand<=40 && rand>20) {
        if(curtile.bounds.y+40<m.height)
          digDirection(Direction.DOWN);
      }
      if(rand<=60 && rand>40) {
        if(curtile.bounds.x-40>0)
          digDirection(Direction.LEFT);
      }
      if(rand<=80 && rand>60) {
        if(curtile.bounds.x+40<m.width)
          digDirection(Direction.RIGHT);
      }

    }
  }
  public void digDirection(Direction d) {
    if(new Random().nextInt(100)<=10) {
      new Miner(curtile, map);
//      try {
//        Thread.sleep(2);
//      } catch (InterruptedException e) {
//        // TODO Auto-generated catch block
//        e.printStackTrace();
//      }
      //Tried this to avoid stack overflow. Didn't work.
    }

© Game Development or respective owner

Related posts about java

Related posts about procedural-generation