2011-05-09 54 views
0

我需要一些帮助。我正在尝试制作一款基本上使用2个玩家的计时器的迷你游戏。它不断为每个用户获取最高分数,然后在3轮结束时保存它,并显示谁拥有最高分数。我已经试过这个循环周围的其他东西,如果玩== 2,它只是不会正常工作。它会在第一次点击时自动显示赢家。这是该部分的代码。我的游戏不会停止显示赢家

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; 
       } 
       } 

所有这一切都是一个按钮(其他内如果打== 2是那里,因为按钮有2个游戏链接到相同的XML /类... I字体认为是造成虽然事业的任何问题其他游戏正常工作)这个游戏正在显示玩家正确转向和他们的时间。问题发生在应该结束时。我尝试使用,如果elses修复所有这一切,它仍然不会正确显示它。可以使用一些帮助。谢谢。

+0

想问一问在gamedev.stackexchange.com – Nate 2011-05-09 18:20:04

+3

提出7个问题,0个接受的答案?祝你好运... – 2011-05-09 18:23:45

回答

2

什么是你想在这里做:

if (turn == 0 && turn<3) 

你也许是想“或”(||),但即使如此,它是没有意义的仔细检查,因为如果反过来== 0它会定义为< 3)。在任何情况下,你写的东西只会在执行的时候执行== 0

后来,在同一块内,你测试了轮到< 6 - 这是毫无意义的,因为如果再次打开== 0,它只会得到那么多。而且,即使你修复& &到||,这将是通过定义< 6,因为它必须是< 3.

基本上,你的if语句都是靠不住的。

+0

洛尔谢谢。我以为我已经改变了第二轮,但我想我没有。 – steven 2011-05-09 18:39:42

0
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)); 
} 
else 
{ 
    //If we reach this, we must have c1time == c2time 
    ((TextView) findViewById(R.id.display)).setText("No winner!"); 
}