Translate

Friday, 15 April 2016


MainActivity.java


package com.vikesh.gamesudoku;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;

public class MainActivity extends Activity implements OnClickListener {

private static final String TAG = "Sudoku";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Set up click listeners for all the buttons
View continueButton = findViewById(R.id.continue_button);
continueButton.setOnClickListener(this);
View newButton = findViewById(R.id.new_button);
newButton.setOnClickListener(this);
View highScoreButton = findViewById(R.id.high_score);
highScoreButton.setOnClickListener(this);
View aboutButton = findViewById(R.id.about_button);
aboutButton.setOnClickListener(this);
View exitButton = findViewById(R.id.exit_button);
exitButton.setOnClickListener(this);

/*setContentView(R.layout.activity_main);
//int[][] sudoku = SudokuGenerator.getInstance().generateGrid();
//GameEngine.getInstance().setSudoku(sudoku);
GameEngine.getInstance().createGrid(this);
//printSudoku(sudoku);*/
}

@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.continue_button:
startGame(Game.DIFFICULTY_CONTINUE);
break;
case R.id.about_button:
Intent i = new Intent(this, About.class);
startActivity(i);
break;
case R.id.new_button:
openNewGameDialog();
break;
case R.id.high_score:
Intent i1 = new Intent(this,HighScore.class);
startActivity(i1);
break;
case R.id.exit_button:
finish();
break;
}
}
private void openNewGameDialog() {
new AlertDialog.Builder(this)
.setTitle(R.string.new_game_title)
.setItems(R.array.difficulty,
new DialogInterface.OnClickListener() {
public void onClick(
DialogInterface dialoginterface, int i) {
startGame(i);
}
}).show();
}

private void startGame(int i) {
Log.d(TAG, "clicked on " + i);
Intent intent = new Intent(this, Game.class);
intent.putExtra(Game.KEY_DIFFICULTY, i);
startActivity(intent);
}

/*private void printSudoku(int[][] sudoku)
{
for(int y =0;y<9;y++)
{
for(int x =0;x<9;x++)
{
System.out.print(sudoku[x][y]+"|");
}
System.out.println();
}
}*/
}

No comments:

Post a Comment