worm game

224 views
Skip to first unread message

colorad...@gmail.com

unread,
Dec 2, 2015, 11:17:17 AM12/2/15
to mooc.fi
Hi,

I'm having problems with week 12 exercise 49.
I get:
Apple's location isn't random enough with code:
WormGame mp = new WornGame();



I don't quite know how to replicate this. WormGame has to have two arguments, width and height.

*Explain your problem here in English or Finnish*


Best regards


Supported languages are English and Finnish

Please use our build in TMC Pastebin when asking questions related to your code  
 
TMC Plugin has built-in code sharing feature. 
In NetBeans, select TMC -> Send code to TMC pastebin. Copy the link you receive and paste it to your message.  

You may use our web interface to share code snippets: http://paste.mooc.fi

ljleppan

unread,
Dec 3, 2015, 3:28:48 AM12/3/15
to mooc.fi, colorad...@gmail.com
Hi,

Because of the line if (rWidth != this.width / 2 && rHeight != this.height / 2) in the WormGame constructor your apple can never spawn in the row or the same column in which the worm starts. So if you have a board with both X and Y coordinates ranging from 0 to 5 and, then you will never have an apple spawn at coordinates of form [3, Y] or [X, 3]. This is incorrect since only [3,3] is forbidden in this example case.

To fix this, you need to change the above conditional so that it only prevents the exact coordinates of the worms start place and not the whole column and row.

-Leo
Reply all
Reply to author
Forward
0 new messages