Starting the Game

First we need to fill in the code that starts the game. startGame() takes one parameter, the index of the difficulty name selected from the list.

Here's the new definition:

Download Sudokuv2/src/org/example/sudoku/Sudoku.java

private void startGame(int i) { Log.d(TAG, "'clicked on " + i);

Intent intent = new Intent(Sudoku.this, Game.class); intent.putExtra(Game.KEY_DIFFICULTY, i); startActivity(intent);

Sudoku Trivia

A few years after it was published in the United States, Number Place was picked up by the Japanese publisher Nikoli, who gave it the much cooler-sounding name Sudoku (which means "single number" in Japanese). From there it was exported around the world, and the rest is history. Sadly, Garns died in 1989 before getting a chance to see his creation become a worldwide sensation.

The game part of Sudoku will be another activity called Game, so we create a new intent to kick it off. We place the difficulty number in an extraData area provided in the intent, and then we call the startActivity() method to launch the new activity.

The extraData area is a map of key/value pairs that will be passed along to the intent. The keys are strings, and the values can be any primitive type, array of primitives, Bundle, or a subclass of Serializable or Parcelable.

0 0

Post a comment