Using the Apple class
The Apple class is done, and we can now put it to work.
Add the code to initialize the apple object in the SnakeGame constructor at the end, as shown in the following code:
// Call the constructors of our two game objects mApple = new Apple(context, new Point(NUM_BLOCKS_WIDE, mNumBlocksHigh), blockSize);
Notice we pass in all the data required by the Apple constructor so it can set itself up.
We can now spawn an apple, as shown next, in the newGame method by calling the spawn method that we added when we coded the Apple class previously. Add the highlighted code to the newGame method:
// Called to start a new game
public void newGame() {
...