Android Open Source - android-tic-tac-toe Tic Tac Toe Activity






From Project

Back to project page android-tic-tac-toe.

License

The source code is released under:

MIT License

If you think the Android project android-tic-tac-toe listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package org.shaon.android.tictactoe.activity;
//  w w w . j a v a 2 s  . c  o m
import static org.shaon.android.tictactoe.model.State.COLUMNS;
import static org.shaon.android.tictactoe.model.State.ROWS;

import org.shaon.android.tictactoe.R;
import org.shaon.android.tictactoe.board.Board;
import org.shaon.android.tictactoe.board.Cell;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

public class TicTacToeActivity extends Activity {

  private Board board;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    board = new Board(this);
    assignCellOnClickListener();
  }
  
  private void assignCellOnClickListener() {
    
    for (int i = 0; i < ROWS; i++) {
      for (int j = 0; j < COLUMNS; j++) {
        Cell cell = board.getCell(i, j);
        findViewById(cell.getCellId()).setOnClickListener(board.getCell(i, j));
      }
    }
  }
  
  /**
   * On click method for Reset button 
   * 
   * @param view Associated view object
   */
  public void resetButtonClicked(View view) {
    board.initialize();
  }
  
  /**
   * On click method for Settings button 
   * 
   * @param view Associated view object
   */
  public void settingsButtonClicked(View view) {
    
    //TODO need to make it startActivityForResult()
    
    Intent intent = new Intent(this, SettingsActivity.class);
    startActivity(intent);
  }
}




Java Source Code List

org.shaon.android.tictactoe.TicTacToeApplication.java
org.shaon.android.tictactoe.activity.SettingsActivity.java
org.shaon.android.tictactoe.activity.TicTacToeActivity.java
org.shaon.android.tictactoe.board.Board.java
org.shaon.android.tictactoe.board.Cell.java
org.shaon.android.tictactoe.exception.InvalidTurn.java
org.shaon.android.tictactoe.model.ActionState.java
org.shaon.android.tictactoe.model.Action.java
org.shaon.android.tictactoe.model.AlphaBetaSearch.java
org.shaon.android.tictactoe.model.MinMax.java
org.shaon.android.tictactoe.model.PlayerConfig.java
org.shaon.android.tictactoe.model.SearchAlgorithm.java
org.shaon.android.tictactoe.model.State.java
org.shaon.android.tictactoe.model.TerminatingCondition.java
org.shaon.android.tictactoe.model.WinningCombination.java