Back to project page android-tic-tac-toe.
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.
package org.shaon.android.tictactoe.board; /*from w w w . j a va 2s . c o m*/ import org.shaon.android.tictactoe.exception.InvalidTurn; import org.shaon.android.tictactoe.model.State.Player; import android.app.Activity; import android.view.View; import android.view.View.OnClickListener; import android.widget.ImageView; import android.widget.Toast; public class Cell implements OnClickListener { private int row; private int column; private int cellId; private Player player; private Board board; private Activity context; private ImageView imageView; public Cell(int row, int column, int cellId, Board board, Activity context) { super(); this.row = row; this.column = column; this.cellId = cellId; this.board = board; this.context = context; this.imageView = (ImageView) context.findViewById(cellId); } @Override public void onClick(View v) { try { board.clickCell(row, column); } catch (InvalidTurn e) { Toast.makeText(context, e.getMessage(), Toast.LENGTH_SHORT).show(); } } /** * Get player associated with the cell * * @return the player */ public Player getPlayer() { return player; } /** * Set player on the cell also updates the image view * associated with the view. * * @param player the player to set */ public void setPlayer(Player player) { this.player = player; Board.updatePlayerView(imageView, player); } /** * Get id of the cell * * @return the cellId */ public int getCellId() { return cellId; } /** * Set id of the cell * * @param cellId the cellId to set */ public void setCellId(int cellId) { this.cellId = cellId; } public void setAsWinningCell(){ Board.updatePlayerView(imageView, player, true); } }