2011-05-09 5 views
0

나는 이것에 대해 도움이 필요합니다. 기본적으로 2 명의 플레이어와 함께 타이머를 사용하는 미니 게임을 만들려고합니다. 그것은 계속해서 각 사용자에 대해 가장 높은 점수를 얻고 점수를 저장 한 3 라운드가 끝날 때 저장합니다. 나는 이것을 play == 2로했을 때 else 내 모든 것을 둘러싼 루프를 시도했다. 첫 번째 클릭시 승자가 자동으로 표시됩니다. 이 섹션의 코드는 다음과 같습니다. 버튼이 같은 XML/클래스로 연결된 2 개 개의 게임을 가지고 있기 때문에 플레이 == 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; 
       } 
       } 

이 모든 것은 내가 원인하지만 문제의 원인이라고 생각 글꼴 ... 버튼합니다 (다른 내 다른 게임은 잘 작동합니다.)이 게임은 플레이어가 올바르게 바뀌 었음을 올바르게 표시합니다. 문제가 끝나야 할 때 발생합니다. 나는이 모든 것을 고치기 위해 elses를 사용했다면 시도했다. 도움을 좀 줘. 감사. 당신이 뭘 하려는지

+0

gamedev.stackexchange.com – Nate

+3

질문 7 건의 답변을 수락 할 수 있습니까? 행운을 빕니다 ... –

답변

2

:

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

당신이 원하는 "또는"수도 (||)하지만 그렇다하더라도 그것은 의미가 한 번 확인하지 것이기 때문에 경우 회전 == 0을 것 정의에 따라 < 3). anyevent에서 쓴 내용은 turn == 0 일 때만 실행됩니다.

나중에 같은 블록 내에서 < 번을 테스트합니다. 다시 돌아 오면 == 0만큼 멀어 지므로 아무런 의미가 없습니다. 그것은 기본적으로 < 3.

해야하기 때문에 그리고 당신이 & &은 ||을 수정하더라도, 그것은 정의 < 6하여 문이 모든 경우가 남았습니다 될 것이다.

+0

롤 감사합니다. 나는 두 번째 턴을 돌았다고 생각했지만, 나는 그렇지 않았다. – steven

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!"); 
} 
관련 문제