我正在制作一个唱首歌游戏,您可以在其中点击一个按钮来增加能量。当我的进度条达到最大值时,它会重置并将最大值设置为下一个更高的值(一切正常)。但是当我再次点击时,进度会增加旧的最大值,但之后它会正常继续。我不知道如何解决这个问题
public class MainActivity extends AppCompatActivity {
public int MinPoints = 0;
public int MaxPointsSSJ = 10;
public int MaxPointsSSJ2 = 20;
public int MaxPointsSSJ3 = 50;
public int Progress;
private void checker(int currentPoints, int maxPoints, int
newmaxPoints, ImageView anzeige, int bild, ProgressBar pb){
if (currentPoints == maxPoints)
maxPoints = newmaxPoints;
pb.setMax(newmaxPoints);
anzeige.setImageResource(bild);
pb.setProgress(currentPoints - maxPoints);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final ImageView Anzeige = (ImageView) findViewById(R.id.imageView);
final ProgressBar KiAnzeige = (ProgressBar) findViewById (R.id.progressBar);
Button MehrEnergie = (Button) findViewById(R.id.button);
KiAnzeige.setMax(MaxPointsSSJ);
KiAnzeige.setMin(MinPoints);
KiAnzeige.setProgress(0);
Progress = KiAnzeige.getProgress();
MehrEnergie.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Progress++;
KiAnzeige.setProgress(Progress);
if (Progress == MaxPointsSSJ){
checker(Progress, MaxPointsSSJ, MaxPointsSSJ2, Anzeige, R.drawable.goku_ssj1, KiAnzeige);
}
if (Progress == MaxPointsSSJ2){
checker(Progress, MaxPointsSSJ2, MaxPointsSSJ3, Anzeige, R.drawable.goku_ssj2, KiAnzeige);
}
}
});
}
}
Qyouu
呼唤远方
猛跑小猪
相关分类