I tried to prepare a room with some loops but now my Greenfoot is freezing, saying I have an infinite loop and starting another program alone.I want to place the room in the middle of the screen because its size will be different from the screen size. Sometimes it creates me the room but I should wait and see how it opens me a lot of new windows with the game.The method is called from the world constructor.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | void prepareRoom( int width, int height) { int _width = --width; int _height = --height; int centerX = WIDTH/ 2 ; int centerY = HEIGHT/ 2 ; int size = getCellSize(); int x1 = centerX - width/ 2 ; int x2 = centerX + width/ 2 ; int y1 = centerY - height/ 2 ; int y2 = centerY + height/ 2 ; for ( int i = y1; i < y2; i++) { for ( int j = x1; j < x2; j++) { if (i < height/ 6 ) { addObject( new Wall(size,size), j, i); } else if (j < 2 || j > _width - 2 || i > _height - 2 ) { addObject( new Wall(size,size), j, i); //it will be wall2 } else { addObject( new Floor(size,size), j, i); } } } } |