The UI update, in this basic example, done in the onClick method should be done in a separate thread (in the adapter or any middle layer). I
f you are doing an Android project at school or university, this is the simplest and quickest solution for you.
gameOver=c.isWinner(c.cellNumber);
c.setImageResource(R.drawable.x);
c.setScaleType(ScaleType.
c.setImageResource(R.drawable.o_tic);
c.setScaleType(ScaleType.FIT_XY);
gameOver=c.isWinner(c.cellNumber);
}
finish();
f you are doing an Android project at school or university, this is the simplest and quickest solution for you.
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override
public void onClick(View v) {
if (gameOver==false){
ImageCell c=(ImageCell)v;
if (playerId==1){
c.cells[c.cellNumber]=1;
FIT_XY);
}
if (playerId==2){
c.cells[c.cellNumber]=2;
playerId++;
if (playerId>2)playerId=1;
moveCount++;
Toast.makeText(v.getContext(),
"Player "+ playerId +", your turn !",Toast.LENGTH_SHORT).show();
}
if (gameOver==true || moveCount>=9){
Toast.makeText(v.getContext(),
"Game over!",Toast.LENGTH_SHORT).show();
gameOver=true;
}
}
No comments:
Post a Comment