Actionscript 3 值变为负数-如何阻止它?

Actionscript 3 值变为负数-如何阻止它?,actionscript-3,flash,function,numbers,Actionscript 3,Flash,Function,Numbers,我有一个小的升级系统,用户可以使用屏幕上的方向箭头增加或减少他们的健康和防御状态。基本上,我是这样做的,当你增加或减少统计数据时,剩下的分数会相应地上升或下降。问题是,当生命值和防御值都达到零,并且你按下按钮在所有的分数都消失后降低/增加统计数据时,分数变成负数 我想知道是否有一种方法可以做到,当用户使用了所有的统计点时,统计数字会识别出它们都被使用了,而不会变成负数。这是在AS3中编码的。这是我的密码 addEventListener(Event.ENTER_FRAME, healthScor

我有一个小的升级系统,用户可以使用屏幕上的方向箭头增加或减少他们的健康和防御状态。基本上,我是这样做的,当你增加或减少统计数据时,剩下的分数会相应地上升或下降。问题是,当生命值和防御值都达到零,并且你按下按钮在所有的分数都消失后降低/增加统计数据时,分数变成负数

我想知道是否有一种方法可以做到,当用户使用了所有的统计点时,统计数字会识别出它们都被使用了,而不会变成负数。这是在AS3中编码的。这是我的密码

addEventListener(Event.ENTER_FRAME, healthScore);
addEventListener(Event.ENTER_FRAME, defenceScore);
addEventListener(Event.ENTER_FRAME, remainPoints);

decBtnDef.addEventListener(MouseEvent.CLICK, decreaseDefenceDef);
incBtnDef.addEventListener(MouseEvent.CLICK, increaseDefenceDef);
decBtnHP.addEventListener(MouseEvent.CLICK, decreaseHealthHP);
incBtnHP.addEventListener(MouseEvent.CLICK, increaseHealthHP);

function healthScore (event:Event){
healthShow.text = String (health);
}
function defenceScore (event:Event){
defenceShow.text = String (defence);
}
function remainPoints (event:Event){
pointsShow.text = String (points);
}

var health:Number = 10;
var defence:Number = 10;
var points:Number = 10;

_test3.text = "You have"; pointsShow.text = String (points); _pointstxt.text = "points.";
_test.text = "You have"; healthShow.text = String (health); _healthtxt.text = "health.";
_test2.text = "You also have"; defenceShow.text = String (defence); _deftxt.text =     "defence.";

function increaseDefenceDef (e:MouseEvent):void{ //when mouse click on up btn
if (defence >= 0)
    defence +=1;
    points -=1;
} 

function decreaseDefenceDef (e:MouseEvent):void{ //when mouse click on down btn
if (defence > 0)
defence -= 1;
points +=1;
}

function increaseHealthHP (e:MouseEvent):void{ //when mouse click on up btn
if (health >= 0)
    health +=1;
    points -=1;
} 

function decreaseHealthHP (e:MouseEvent):void{ //when mouse click on down btn
if (health > 0)
health -= 1;
points +=1;
}

通读。也不需要三个输入框监听器-您可以将所有三个文本表达式放在一个输入框监听器中是的,因为它缺少拥抱条件。我在答案中添加了拥抱,请重试
   function increaseDefenceDef (e:MouseEvent):void
   { //when mouse click on up btn
        if (points >= 1)
        {
            defence +=1;
            points -= 1;
        }
    } 

    function decreaseDefenceDef (e:MouseEvent):void
    { //when mouse click on down btn
        if (defence >= 1)
        {
            defence -= 1;
            points += 1;
        }
    }

    function increaseHealthHP (e:MouseEvent):void
    { //when mouse click on up btn
        if (points >= 1)
        {
            health +=1;
            points -= 1;
        }
    } 

    function decreaseHealthHP (e:MouseEvent):void
    { //when mouse click on down btn
        if (health >= 1)
        {
        health -= 1;
        points += 1;
        }
    }