Action Performed when Button Clicked n Times

后端 未结 1 1363
灰色年华
灰色年华 2021-01-26 07:24
public void boss(final Boss boss) {
    forward.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            boss.setHp(boss.getHp()         


        
相关标签:
1条回答
  • 2021-01-26 08:07

    This should work. Also you don't have to pass boss as function parameter. You can keep that object as field in your class.

    public void boss(final Boss boss) {
        forward.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                if(boss.getHp() > 0){
                    boss.setHp(boss.getHp() - 1);
                    log("" + boss.getHp());
                } else {
                    //boss is dead
                }
            }
        });
    }
    
    0 讨论(0)
提交回复
热议问题