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

2017/6/15

Battleship game world constructor

1
2
ironphoenix20 ironphoenix20

2017/6/15

#
I am making a battleship game. and when i open it it says "the constructor for this world is taking a long time. you may have an infinite loop." the weird thing is if i keep restarting greenfoot over and over, eventually it works. and then if i reset it, the whole problem comes back. any idea what the error could be? i definitely have no infinite loops. i checked that.
danpost danpost

2017/6/15

#
ironphoenix20 wrote...
I am making a battleship game. and when i open it it says "the constructor for this world is taking a long time. you may have an infinite loop." the weird thing is if i keep restarting greenfoot over and over, eventually it works. and then if i reset it, the whole problem comes back. any idea what the error could be? i definitely have no infinite loops. i checked that.
Please comment out all but the 'super' line in the world constructor and re-upload it, making sure the 'Publish source code' checkbox is checked.
ironphoenix20 ironphoenix20

2017/6/15

#
all right. i uploaded it again. here is the link: http://www.greenfoot.org/scenarios/19603. this project is due very soon so i need help ASAP. thanks.
danpost danpost

2017/6/15

#
ironphoenix20 wrote...
all right. i uploaded it again. here is the link: http://www.greenfoot.org/scenarios/19603. this project is due very soon so i need help ASAP. thanks.
You checked the wrong checkbox. Upload it again, the same way (without changing the name or anything) and make sure to check the correct box.
ironphoenix20 ironphoenix20

2017/6/15

#
no. i checked the publish source code box.
ironphoenix20 ironphoenix20

2017/6/15

#
i reuploaded it. is it correct now?
danpost danpost

2017/6/15

#
ironphoenix20 wrote...
i reuploaded it. is it correct now?
Got it. Will not be able to delve into it immediately; but will try to as soon as possible.
ironphoenix20 ironphoenix20

2017/6/15

#
i need help ASAP so please try quickly
Yehuda Yehuda

2017/6/16

#
The infinite loop is the (main) while loop in the addShips method in the MyRadar class. I don't know why yet.
ironphoenix20 ironphoenix20

2017/6/16

#
Ill take a look
Yehuda Yehuda

2017/6/16

#
The reason it's an infinite loop is because the condition is: the loop should continue as long as any one of the five ships is touching a Ship. All the five ships are placed at the same location, so all of those method calls return true.
ironphoenix20 ironphoenix20

2017/6/16

#
yes but through one cycle of the while loop they should be at different locations right? then the while loop will eventually written false and that is the purpose? so why is it infinite?
Yehuda Yehuda

2017/6/16

#
The locations aren't for sure being changed, only with certain conditions does the location change and those conditions are never met since all the Xs and Ys of the ships are never initialized to anything, leaving them at 0.
ironphoenix20 ironphoenix20

2017/6/16

#
so how do i fix this?
Yehuda Yehuda

2017/6/16

#
I'm not fully sure what you were trying to do with all the if statements and while loops but to fix the problem you have to make sure the ships get moved so that they're not intersecting. It's not like Greenfoot doesn't allow the ships to overlap, you did that on purpose with the while loop so if you have a while loop to make sure the ships don't over lap you have to make sure each one gets moved until each ship is in it's own place.
There are more replies on the next page.
1
2