我正在编写这个非常简单的游戏,并且希望每个玩家每次击中随机造成的伤害。由于某种原因,第一个命中具有随机值,但随后的后续值完全相同。这几乎就像Math.floor(Math.random())
函数运行一次,然后停止并使用第一次给出的值。
这是代码:
this.attackpoints=Math.floor((Math.random()*10)+5);
this.attack=function(opponent) {
opponent.hitpoints-=this.attackpoints;
console.log(this.name + " has " + this.hitpoints + " hitpoints and " + this.energy + " energy.");
console.log(this.name + " just hit " + opponent.name + ".");
}