I am developing an android game in which i have to return random images from a class. its basically a tic tac toe game in which when a player taps then an image shown which is cross type image. I have 5 cross images having different colors and i want to show them randomly The problem is when i tap on tic tac toe board then if for example green color cross image shown, then computer play its move but then if i make another move it changes the image for second move but it also change the color of the first one which is not required. Lemme clear again by example i tap first green image cross shown i tap second orange color cross shown (but with the second tap the color of the first green image also changes and goes to yellow)
here is my code
public enum Player {
CROSS, CIRCLE, EMPTY;
public int Image() {
switch(this) {
case CROSS :
int[] p = {R.drawable.kii, R.drawable.kiitwo, R.drawable.qq, R.drawable.qqq, R.drawable.qqqqq};
Random random= new Random();
int rndInt = random.nextInt(p.length);
int resID = p[rndInt];
return resID;
case CIRCLE :
int[] pp = {R.drawable.cclefive, R.drawable.ciclee, R.drawable.cicleefour, R.drawable.cicleetwo, R.drawable.ciclethree};
Random randomm= new Random();
int rndIntt = randomm.nextInt(pp.length);
int resIDd = pp[rndIntt];
return resIDd;
default :
return 0;
}
}
and here i am calling the player class
@Override
public void onBoardUpdated(Player[][] board) {
dismissToast();
for (int i = 0; i < mCells.length; ++i) {
for (int j = 0; j < mCells[0].length; ++j) {
Player boardPlayer = board[i][j];
int colorResource = boardPlayer == Player.CROSS ? android.R.color.transparent : android.R.color.transparent;
mCells[i][j].setBackgroundColor(colorResource);
mCells[i][j].setImageResource(board[i][j].Image());
}
}
}
Aucun commentaire:
Enregistrer un commentaire