私はこれをできる限り最善の方法で説明しようとしているので、ここに行きます. 私のプロジェクトでは、ビデオ ゲームを作成しており、現在、プレイヤーが使用するスキルを書いています。しかし、私が見る大きな、明白な問題があります。つまり、プレイヤーがドラゴンと戦うとき、プレイヤーはドラゴンの HP の一部を奪うなどのスキルを設定しています。生き物?現在私のコードにあるように、スキルは特にドラゴンにリンクされているため、正しく機能しません。
すべてのモンスターを含むオブジェクトを使用することにしましたが、オブジェクト コードを 1 つだけ参照できるように集中化する方法がわかりません。これにより、どのモンスターと戦っているのかを検索できます。そうすれば、スキルが効率化され、戦闘ごとに新しいスキルを作成する必要がなくなります。どうすればこれを設定できますか?
// 1. CHARACTER OBJECTS
function player(hp, hpcap, mana, manacap, energy, energycap, atb) {
this.hp = hp;
this.hpcap = hpcap;
this.mana = mana;
this.manacap = manacap;
this.energy = energy;
this.energycap = energycap;
this.atb = atb;
}
function playerStats(strength, armor, magicdamage, magicresistance, precision, parry, critical, manaregen, energyregen) {
this.strength = strength;
this.armor = armor;
this.magicdamage = magicdamage;
this.magicresistance = magicresistance;
this.precision = precision;
this.parry = parry;
this.critical = critical;
this.manaregen = manaregen;
this.energyregen = energyregen;
}
function npc(hp, mana, energy, atb) {
this.hp = hp;
this.mana = mana;
this.energy = energy;
this.atb = atb;
}
function npcStats(strength, armor, magicdamage, magicresistance, precision, parry, critical, manaregen, energyregen) {
this.strength = strength;
this.armor = armor;
this.magicdamage = magicdamage;
this.magicresistance = magicresistance;
this.precision = precision;
this.parry = parry;
this.critical = critical;
this.manaregen = manaregen;
this.energyregen = energyregen;
}
// 2. GLOBAL PLAYER/NPC VARIABLES
var character = new player(1, 100, 50, 50, 75, 75, 6);
var cs = new playerStats(20, 1, 10, 1, 30, 10, 10, 1, 1);
var dragon = new npc(250, 80, 75, 6);
var dragonstats = new npcStats(15, 3, 15, 5, 40, 10, 10, 2, 2);