Hi,
I'm having problems with week 12 exercise 49 WormGame.
I don't understand how grow() and move() are supposed to talk to each other, or how grow() is supposed to grow the worm by one piece but not add the piece to the List until move() is called. I created a variable to store a new piece when grow() is called and then add it to the list when move() is called but I don't think that is right. The example shows that nothing is supposed to happen when grow() is called until move() is called but how can that be? The example also shows that the first piece of the game doesn't get deleted after grow() and move() are called:
[(5,5)] // new Worm(5,5, RIGHT)
[(5,5), (6,5)] // move
[(5,5), (6,5), (7,5)] // move
[(6,5), (7,5), (8,5)] // move
[(6,5), (7,5), (8,5)] // grow
[(6,5), (7,5), (8,5), (9,5)] // move
How come (6,5) stays in the worm? Shouldn't the worm be (7, 5), (8, 5), (9, 5), (10, 5) if the first piece should be deleted?
Please help, I don't think I am understanding how these methods should be working. Thank you!
The link to my work is here: PASTE TMC PASTEBIN LINK HERE
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