Coding the Snake class
Add the single import
statement and the member variables. Be sure to study the code it will give some insight and understanding to the rest of the Snake
class.
import java.util.ArrayList; class Snake { // The location in the grid of all the segments private ArrayList<Point> segmentLocations; // How big is each segment of the snake? private int mSegmentSize; // How big is the entire grid private Point mMoveRange; // Where is the center of the screen // horizontally in pixels? private int halfWayPoint; // For tracking movement Heading private enum Heading { UP, RIGHT, DOWN, LEFT } // Start by heading to the right private Heading heading = Heading.RIGHT; // A bitmap for each direction the head can face private Bitmap mBitmapHeadRight; ...
Get Learning Java by Building Android Games - Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.