Implementing the Snake game activity
Not all of this code is new. In fact, we have either used most of it before or discussed it earlier in the chapter. However, I wanted to present every line to you in order and in context with at least a brief explanation, even when we have seen it before. Having said that, I haven't included the long list of imports as we will either be prompted to add them automatically or we can just press Alt + Enter when needed.
This way, we can remind ourselves how the whole thing comes together without any blanks in our understanding. As usual, I will summarize as we proceed through the implementation, and go into a few bits of extra depth at the end:
Add an activity called
GameActivity
. Select a blank activity when asked.Make the activity full screen as we have done before.
As usual, create some sound effects or use mine. Create an
assets
directory in themain
directory in the usual way. Copy and paste the sound files (sample1.ogg
,sample2.ogg
,sample3.ogg
, andsample4...