0

Is this code right? It's a code from Android studio, i don't understand what's the function of activeplayer=1????

public class MainActivity extends ActionBarActivity { // 0 = yellow, 1 = red int activePlayer = 0; public void dropIn(View view) { ImageView counter = (ImageView) view; counter.setTranslationY(-1000f); if (activePlayer == 0) { counter.setImageResource(R.drawable.yellow); activePlayer = 1; } else { counter.setImageResource(R.drawable.red); activePlayer = 0; } }

22nd Mar 2017, 5:19 AM
周钰404
周钰404 - avatar
7 Respuestas
+ 6
Well, I think the code is correct. There is a button or so whose onclick() maybe set as the dropIn() function. That moves the ImageView down and changes its color to yellow or red depending on the integer variable 'activePlayer'.
22nd Mar 2017, 6:03 AM
Krishna Teja Yeluripati
Krishna Teja Yeluripati - avatar
+ 6
Can you tell what exactly should be done by this code?
22nd Mar 2017, 6:26 AM
Krishna Teja Yeluripati
Krishna Teja Yeluripati - avatar
+ 5
That's it. When user touches for the first time, 'activePlayer' is 0 meaning yellow color is set and 'activePlayer' is set to 1. For the next touch, 'activePlayer' is 1 meaning red color is set and 'activePlayer' is again set to 0.
22nd Mar 2017, 8:46 AM
Krishna Teja Yeluripati
Krishna Teja Yeluripati - avatar
0
but what's the use of 1 , I am writing same code but ain't getting same results as instructor 😥 yeah onclick is set to dropIn
22nd Mar 2017, 6:21 AM
周钰404
周钰404 - avatar
0
it's a tic tac toe game's code , when a user touch screen it should show yellow image then red image then yellow , like that but what my code is doing, showing only yellow images , no red image
22nd Mar 2017, 8:41 AM
周钰404
周钰404 - avatar
0
yeah that's correct only problem is when I enter this code on my Android studio only yellow colour is showing no red color at all
22nd Mar 2017, 10:26 AM
周钰404
周钰404 - avatar
0
can someone tell me?
23rd Mar 2017, 3:32 AM
周钰404
周钰404 - avatar