This site requires JavaScript, please enable it in your browser!
Greenfoot back

Report as inappropriate.

danBuonocore
danBuonocore presents ...

2012/3/19

Maze

After you make it to the top-right cell, the computer solves it using recursion, filling all tested cells with circles. Either I did something wrong or it needs to check every cell :o

4675 views / 834 in the last 7 days

Tags: game with-source korea

open in greenfoot
Your browser does not support the canvas tag.
danpostdanpost

2012/3/20

Couple of things that could have made making this a lot easier (1) Using a grid size of 24 would have saved a lot of calculations (other advantages as well) (2) Using block as background and adding a plain gray square (Pad) for each area of path (instead of blocking non-path, and leaving path empty). This way, when moved, if (getIntersectingObjects(Pad.class) != null), then good move else not (avoids checking if valid location and referring to original array in world class). Also, the Pad.class objects could have instance variables to track number of direction choices from it, as well as, if checked for real path, and if is actual path or not. Another thing you could do, is use a double int array instead of a single int array (int[][] as opposed to int[]) for the lvlArray. With that lvlArray.length() would be the number of rows and lvlArray[0].length() would be the number of columns. These suggestions would allow you to create more levels with ease (at least the grid-size one, and the double int one)
danBuonocoredanBuonocore

2012/3/20

Thank you for the suggestions. I completely forgot about the grid size (thanks for the tip), as I do not use Greenfoot that often (just for my computer science class). I was thinking about doing the getIntersectingObjects() method like you said, but (correct me if I'm wrong), testing for the int in the array is much faster. I agree that a double int array would be much more efficient. The reason why I left it as a single array is because this is adapted code I took from an Actionscript Class I wrote several years ago. It was used to create enemies in a side-scrolling shooter game. In order to create the scrolling effect, I iterated through each line in the array at certain time intervals. With a fixed width and varying height (for vertical scroll) it was more efficient to just use a single array. The example my teacher used in class utilized a double array and, therefore, I decided to leave the code as is to delineate another approach. Thanks for the criticisms and if we have to edit our code for the next class I'll definitely take your suggestions(:

Want to leave a comment? You must first log in.

Who likes this?

No votes yet.