It's time to create our player! Since a snake is a collection of tiles, let's use an array to model our player. Each element in the array can be an object with an (x,y) coordinate.
In the last chapter, we made a handy loop to draw each tile in our grid. We want the tile to be blue if it is empty, and green if the snake is in that tile. To test if the player is in the current tile, we must loop through the player array to see if any element in the array has the same (x,y) coordinates as the current tile we are rendering. If we find the element in the player array that is in the current tile, we can set the color to green and break out of the loop, since we know each tile can only be inhabited once.
So the entire render function should now look like this:
Success!
Our grid now has a snake in it! But what good is a static image when we want to create a game? In the next chapter, we learn how to control the player.