Got an issue with some function i'm writing. My "bateau" is an object that has a x position and y position to place it inside my "grille" object which is a table of "bateau" elements.
Joueur.prototype.placeFullBateau = function(grille, bateau) {
var x = bateau.positionX;
var y = bateau.positionY;
var direction = bateau.direction;
if (direction == "droite") {
for (var i = 0; i <= bateau.taille-1; i++) {
grille.plateau[x][y+i] = $(bateau);
console.log(bateau);
console.log($(bateau));
console.log("Bateau : "+$(bateau).get(0).nom+", positionY : "+grille.plateau[x][y+i].get(0).positionY);
console.log(grille.plateau[x][y+i]);
$(bateau).get(0).positionY += 1;
};
};
In the console.log() of "bateau", my positionX & positionY are good, they change as i want them to change (i'm showing only two lines, this "bateau" takes 5) :
Object { nom: "Porte-avion", taille: 5, positionX: 4, positionY: 2, direction: "droite" } test.js:100:5
Object { nom: "Porte-avion", taille: 5, positionX: 4, positionY: 3, direction: "droite" } test.js:100:5
In the console.log() of "$(bateau)", the positionY (or positionX, depending on the one i want to vary) remembers the last value it has taken. Here, positionY will be always 7 (cuz it starts at 2 and size is 5).
I'm trying to :
grille.plateau[x][y+i] = $(bateau);
grille.plateau[x][y+i].get(0).positionY = bateau.positionY;
$(bateau).get(0).positionY += 1;
I'm lost.. Hopefully I gave enough informations to get some help.. I wouldn't paste the whole code :/.
Here's a fiddle : https://jsfiddle.net/0jaL7svo/ Not really working, missing images that shows off when i click on a cell. What i'm doing is when i click on a cell, i take its id. Problem is, the id of some cells (which has an object in it) is wrong because it takes the bateau.positionX & bateau.positionY & bateau.numJoueur. (Looks like "441", for the cell (4,4) of the player 1.) Here's the full working project : (see comment below, cannot post two links). Just unzip and load locally (linux filesystem).
Cheers Krach