I need some help with this. I am trying to make a mini game that basically uses a timer with 2 players. It continually takes the highest score for each that user and saves it then at the end of 3 rounds it is supposed to display who has the highest score. I have tried this with a loop around everything within the else if play==2 and it just wouldnt work correctly. It would auto display the winner on first click. Here is the code for that section.
else if (play==2)
{
round++;
turn = turn%2;
if (turn == 0 && turn<3)
{
TextView c1c = (TextView) findViewById(R.id.player);
c1c.setText( " CHALLENGER 1:" );
click=click%2;
if (click==0 && turn<6)
{
reset();
TextView challenger1 = (TextView) findViewById(R.id.display);
challenger1.setText("");
start();
click++;
startbutton.setText("Stop");
}
else if (click==1 && turn < 6)
{
stop();
getElapsedTimeMicro();
TextView time1 = (TextView) findViewById(R.id.display);
time1.setText( " "+ formatter.format(elapsed) );
if (elapsed > c1time )
c1time=elapsed;
click++;
startbutton.setText("Start");
turn++;
}
}
else if (turn ==1 && turn < 3)
{
TextView c2 = (TextView) findViewById(R.id.player);
c2.setText( " CHALLENGER 2:" );
click=click%2;
if (click==0)
{
reset();
TextView challenger2 = (TextView) findViewById(R.id.display);
challenger2.setText("");
start();
click++;
startbutton.setText("Stop");
}
else if (click==1)
{
stop();
getElapsedTimeMicro();
TextView time2 = (TextView) findViewById(R.id.display);
time2.setText( " "+ formatter.format(elapsed) );
if (elapsed>c2time)
c2time=elapsed;
click++;
startbutton.setText("Start");
turn++;
}
}
if ( round==3)
{
if (c1time > c2time)
{
TextView winner1 = (TextView) findViewById(R.id.display);
winner1.setText("Challenger 1 is the Iron Lung!\n"+formatter.format(c1time));
}
else if (c2time > c1time)
{
TextView winner2 = (TextView) findViewById(R.id.display);
winner2.setText("Challenger 2 is the Iron Lung!\n"+formatter.format(c2time));
}
click=0;
turn=0;
c1time=0;
c2time=0;
}
}
All of this is within a button ( the else if play==2 is there because the button has 2 games linked into the same xml/class… I font believe that is causing any problems though cause the other game works fine) This game is displaying the players turn correctly and their times correctly. The problem is occurring when it should be ending. I tried using if if elses to fix all this and it still wont display it properly. Could use some help. Thanks.
what are you trying to do here:
You might have wanted “or” (||) but even then it wouldn’t make sense to double check since if turn==0 it will by definition be <3). In anyevent, what you wrote will only execute when turn==0
Later, inside that same block, you test for turn<6 – which is pointless since it will only get that far if again turn==0. And even if you fix the && to ||, it would be by definition <6 since it must be <3.
Basically, your if statements are all wonky.