[英]How do I change my level after a certain score has been reached? (Java, NetBeans)
I already have some part of the code but I'm not sure whether or not it's okay like this.我已经有了部分代码,但我不确定这样是否可以。 I need to change it somehow because it doesn't work like this.我需要以某种方式更改它,因为它不能像这样工作。 This is my current code;这是我当前的代码;
public void changeLevel(){
for(int i = 1; i < getScore(); i++){
if(getScore() % 100 == 0){
level++;
}
}
}
In this case, every time after 100 points I want my level to add 1. If anybody could help me out, that would be hugely appreciated: :)在这种情况下,每次达到 100 分后,我都希望我的等级加 1。如果有人可以帮助我,我将不胜感激::)
I think you are looking for this:我想你正在寻找这个:
public void changeLevel() {
level = level + (getScore()/100);
}
The level change code should rather be related to the score change code.级别更改代码应该与分数更改代码相关。
Something like:就像是:
public void incrementScore() {
if (++this.score % 100 == 0) ++this.level;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.