1
我將盡力解釋這是我可以做到的最好的方式,所以在這裏。在我的項目中,我正在製作視頻遊戲,目前我正在編寫玩家將要使用的技能。但是,我看到了一個巨大而明顯的問題。也就是說,我正在設定技能,所以當玩家與龍戰鬥時,玩家將會脫掉龍的一些HP等。但是當玩家使用相同的技能與地精或其他玩家生物?它不能正常工作,因爲我的技能現在已經在我的代碼中有了,所以這些技能特別與龍有關。Javascript:我如何集中一個對象來處理所有其他對象?
我決定使用物體和其中的所有怪物,但我不知道如何集中它,以便我只能引用一個目標代碼,然後查找我正在與之戰鬥的怪物。這樣一來,技能就會流水線化,而且我不必爲每場戰鬥都寫一個新技能。我如何設置?
// 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);