Snakepublic class Snake extends android.app.Activity Snake: a simple game that everyone can enjoy.
This is an implementation of the classic Game "Snake", in which you control a
serpent roaming around the garden looking for apples. Be careful, though,
because when you catch one, not only will you become longer, but you'll move
faster. Running into yourself or the walls will end the game. |
Fields Summary |
---|
private SnakeView | mSnakeView | private static String | ICICLE_KEY |
Methods Summary |
---|
public void | onCreate(android.os.Bundle savedInstanceState)Called when Activity is first created. Turns off the title bar, sets up
the content views, and fires up the SnakeView.
super.onCreate(savedInstanceState);
// No Title bar
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.snake_layout);
mSnakeView = (SnakeView) findViewById(R.id.snake);
mSnakeView.setTextView((TextView) findViewById(R.id.text));
if (savedInstanceState == null) {
// We were just launched -- set up a new game
mSnakeView.setMode(SnakeView.READY);
} else {
// We are being restored
Bundle map = savedInstanceState.getBundle(ICICLE_KEY);
if (map != null) {
mSnakeView.restoreState(map);
} else {
mSnakeView.setMode(SnakeView.PAUSE);
}
}
| protected void | onPause()
super.onPause();
// Pause the game along with the activity
mSnakeView.setMode(SnakeView.PAUSE);
| public void | onSaveInstanceState(android.os.Bundle outState)
//Store the game state
outState.putBundle(ICICLE_KEY, mSnakeView.saveState());
|
|