@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_one_player); Bundle extras = getIntent().getExtras(); gameLogic = new GameLogic(); // initialize buttons one_one = (ImageButton) findViewById(R.id.one_one); one_two = (ImageButton) findViewById(R.id.one_two); one_three = (ImageButton) findViewById(R.id.one_three); two_one = (ImageButton) findViewById(R.id.two_one); two_two = (ImageButton) findViewById(R.id.two_two); two_three = (ImageButton) findViewById(R.id.two_three); three_one = (ImageButton) findViewById(R.id.three_one); three_two = (ImageButton) findViewById(R.id.three_two); three_three = (ImageButton) findViewById(R.id.three_three); playerScoreLabel = (TextView) findViewById(R.id.player_score); computerScoreLabel = (TextView) findViewById(R.id.computer_score); Typeface type = Typeface.createFromAsset(getAssets(), "fonts/Cheveuxdange.ttf"); playerScoreLabel.setTypeface(type); computerScoreLabel.setTypeface(type); if (extras != null) { player = (Player) extras.getSerializable("player"); computer = (Player) extras.getSerializable("computer"); difficulty = extras.getString("difficulty"); } playerMarker = player.getPlayerMarker(); playerScore = player.getScore(); playerName = player.getName(); computerName = computer.getName(); computerScore = computer.getScore(); computerMarker = computer.getPlayerMarker(); gameLogic.setCompMarker(computerMarker); playerScoreLabel.setText(playerName + ": " + playerScore); computerScoreLabel.setText(computerName + ": " + computerScore); rowAI = new Random(); colAI = new Random(); sound = MediaPlayer.create(this, R.raw.pencil); // set click listeners one_one.setOnClickListener(this); one_two.setOnClickListener(this); one_three.setOnClickListener(this); two_one.setOnClickListener(this); two_two.setOnClickListener(this); two_three.setOnClickListener(this); three_one.setOnClickListener(this); three_two.setOnClickListener(this); three_three.setOnClickListener(this); }
public void checkGameStatus() { if (gameLogic.hasWon()) { AlertDialog.Builder builder = new AlertDialog.Builder(this); if (gameLogic.getWinningMarker() == playerMarker) { builder.setTitle("Congratulations, You Won!"); winSound = MediaPlayer.create(this, R.raw.woohoo); player.setScore(playerScore + 1); } else { builder.setTitle("You Lost, Better Luck Next Time!"); winSound = MediaPlayer.create(this, R.raw.crowd_boo); computer.setScore(computerScore + 1); } builder .setPositiveButton( "New Game", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { Intent newGame = new Intent(OnePlayerActivity.this, OnePlayerActivity.class); newGame.putExtra("player", player); newGame.putExtra("computer", computer); newGame.putExtra("difficulty", difficulty); startActivity(newGame); } }) .setNegativeButton( "Main Menu", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { Intent loginActivity = new Intent(OnePlayerActivity.this, LoginActivity.class); startActivity(loginActivity); } }); winSound.start(); builder.create().show(); } else if (gameLogic.checkFull()) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder .setTitle("Tie Game, Better Luck Next Time") .setPositiveButton( "New Game", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { Intent newGame = new Intent(OnePlayerActivity.this, OnePlayerActivity.class); newGame.putExtra("player", player); newGame.putExtra("computer", computer); newGame.putExtra("difficulty", difficulty); startActivity(newGame); } }) .setNegativeButton( "Main Menu", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { Intent loginActivity = new Intent(OnePlayerActivity.this, LoginActivity.class); startActivity(loginActivity); } }); winSound = MediaPlayer.create(this, R.raw.crowd_boo); winSound.start(); builder.create().show(); } }