4

Ik i probably should have went to stack overflow but you guys seem so much more immediate. I'm building a simple tic tac toe game however whenever i hit a tile the second time the counter disappears i refuse to go on to the winning logic before getting this resolved help!!!!

gameState[tappedCounter] = activePlayer;
if (gameState[tappedCounter] == 2) {
//if tapped counter is unplayed

if (activePlayer == 0) {
((ImageView) view).setImageResource(R.drawable.knight);
activePlayer = 1;
//displays knight
//sets active player to player 2

} else if (activePlayer == 1) {
((ImageView) view).setImageResource(R.drawable.sam);
activePlayer = 0;
//displays sam as player 2 character
//sets active player back to player 1
}

Comments
  • 1
    Have you tried debugging it and looking at the values step by step?
  • 2
    You first set tappedCounter index to activeplayer, then check if it is 2 which according to comment is unplayed.

    Will activePlayer ever be 2?

    If not the if will never be true.
  • 1
    @Nbfour so I actually just figured it out. I had counter.setTranslationY(-1000f); above all of this so every time i pressed it looped that 1 piece of outside code over and over. So I placed it at the bottom and viola problem gone. However, to answer your question yes I did that last night I've been on this upwards of 22hrs.
  • 1
    @Voxera yes actually tapped counter is started off as 2 once pressed it'll be set to the active players numbers i didn't full code you guys i just thought the problem was within this area.
  • 5
    @ihavePCSD for the love of Linus Torvald, please post code snipets using something like https://pastebin.com or if your snipped is HTML/CSS/JS, use something like https://jsfiddle.net

    Thank you!
Add Comment