私は基本的なテキストアドベンチャーゲームを作成しようとしており、自分のキャラクターにダメージを与えるのに苦しんでいるようです。私はダメージの数字を得ることができますが、何らかの理由で彼らの健康に影響を与えているようには見えません。詳細に見なければ、あなたのコードが動作しない1つの明白な理由は、コードの以下の部分が間違っているということです損害はオブジェクトに適用されないようですか?
function Person(firstName, lastName, hp, concious, str, def, agi, frc) {
this.firstName = firstName;
this.lastName = lastName;
this.hp = hp;
this.concious = concious;
this.str = str;
this.def = def;
this.agi = agi;
this.frc = frc;
var sayName = function(p) {
console.log(p.firstName);
}
this.attack = function(Person) {
var attPow = Math.floor(Math.random() * this.str);
var attSpe = Math.floor(Math.random() * this.agi);
var defAtt = Math.floor(Math.random() * Person.def);
var defAgi = Math.floor(Math.random() * Person.agi);
console.log(attPow, attSpe, defAtt, defAgi);
if (attPow > defAtt && attSpe > defAgi){
return Person.hp -= attPow + attSpe - defAtt;
console.log(Person.hp);
} if(attPow < defAtt && attSpe < defAgi) {
alert("You missed");
} if (attPow < defAtt) {
alert("He blocked you're attack");
} if (attSpe < defAgi) {
alert("He dodged you're attack");
}
}
};
var Angelo = new Person("Angelo", " ", 75, 50, 5, 5, 5, 5);
var boy = new Person("boy","dead", 75,50,5,2,5,5);
Angelo.attack(boy);
ああ、私はそれを得ていると思う。ダンプでは、方程式全体を完全に削除することを意味しますか? – l34lo1
@ l34lo1 - ダンプは、変数の値を出力することを意味します。 :Pそれが助けてくれることを望みます。まだ質問がある場合は教えてください。私があなたを助けてくれたなら、私の答えの横にあるチェックマークをクリックすることで答えをマークすることができます。 –