This is an example from a Pokemon-like game. I am constructing an Object, and inside it i am trying to make a new Object "en" and "to", that is two different attacks. The problem is that when i try to edit something in either of the attack Objects ("en" and "two"), the change happens to every Pokemon with the same name. This doesn't happen with the "health", so i think that the this.en = new Object;
is the problem.
This is the code for constructing the Pokemon
function Fakemon(_navn, _type, _attackPower, _src,
_1Navn, _1Force, _1Antall_, _2Navn, _2Force, _2Antall) {
this.navn = _navn;
this.type = _type;
this.attackPower = _attackPower;
this.src = _src;
this.en = new Object;
this.en.navn = _1Navn;
this.en.force = _1Force;
this.en.antall = _1Antall_;
this.to = new Object;
this.to.navn = _2Navn;
this.to.force = _2Force;
this.to.antall = _2Antall;
this.health = 1000;
console.log(this.en);
this.pushFakemon = function() {
fakemonSamling.push(this);
}
this.pushFakemon();
}
const fakemon1 = new Fakemon("BatCat", "Flying", [10, 50], ["batFront.png", "batBack.png"], "Blood Suck", [25, 38, 60], 10, "Wing Slap", [10, 17, 25], 20);
const fakemon2 = new Fakemon("Muffin Time", "Normal", [15, 45], ["cupcakeFront.png", "cupcakeBack.png"], "Frosting cover", [10, 17, 25], 20, "Cake stomp", [40, 50, 60], 5);
This is the Code for putting three Pokemon's to each player
for (let i = 0; i < 3; i++) {
var temp1 = new Object;
player1.push(Object.assign(temp1, randomFakemon()));
var temp2 = new Object;
player2.push(Object.assign(temp2, randomFakemon()));
}