简体   繁体   English

达到一定分数后如何更改等级? (Java、NetBeans)

[英]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.

相关问题 当达到特定分数时,如何在我的骰子游戏中添加警报对话框? Java,Android工作室 - How do I add an Alert Dialog to my Dice Game when a certain score is reached? Java, Android Studio 达到某个值后如何触发声音 - How to trigger a sound once after a certain value has been reached 一旦达到特定的障碍,如何停止动画? - How do I stop an animation once a certain barrier has been reached? 如何让我的 Java 程序在读取到某个频率后立即停止捕获音频? - How do I make my Java program stop capturing audio as soon as a certain frequency has been read? 在Java游戏中达到分数后,重新生活 - Adding a new life once a score has been reached in a Java game 被杀死后,如何在我的Java应用程序中做一些事情? - How can I do some stuff in my java app, after it has been killed? 如何以操纵方式重复文本,并重复此操作直到达到我的目标? - How can I repeat text in a manipulative way, and repeat this action until my target has been reached? 显示JFrame后如何更改它的内容(java) - how to change the contents of a JFrame after it has been displayed (java) 实例化后,如何在javafx应用程序中更改变量值? - How do I change variable values in an javafx application after it has been instantiated? 创建菜单后,如何更改菜单中的图标? - How do I change an icon in a menu, after the menu has already been created?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM