1

私はこの非常に単純なゲームをプログラミングしており、各プレイヤーがヒットごとにランダムにダメージを与えたいと考えています。なんらかの理由で、最初のヒットはランダムな値を持ちますが、その後の次の値はまったく同じです。Math.floor(Math.random())関数が 1 回実行されてから停止し、最初に指定された値を使用するようなものです。

コードは次のとおりです。

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 + ".");

}
4

5 に答える 5