Passage de paramètre dans un objet
Bonjour a tous ,
voici mon problème j'ai deux objets:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| function Case(){
this.hasShip = false;
this.wasFire = false;
this.tirer = function(){
if (this.wasFire == false){
this.wasFire = true;
return true;
}
return false;
}
this.toString = function(){
return "hS="+this.hasShip+" WF="+wasFire;
}
}
function Matrice(){
this.tableau;
this.init = function(){
// Initialisation des données
this.tableau = new Array(10);
for ( i=0 ; i < 10 ; i++){
this.tableau[i] = new Array(10);
}
for ( i=0 ; i < 10 ; i++){
for ( j=0 ; j < 10 ; j++){
this.tableau[i][j] = new Case();
}
}
}
this.getCase = new function(x,y){
return (this.tableau[x][y]);
}
} |
L'objectif est d'avoir une matrice de case.
Pour l'initialisation tout se passe bien apparemment, mais quand je souhaite
appeler la fonction getCase ça foire , mon erreur: "x indéfini"
Je ne comprends pas pourquoi puisque x et y sont passé en paramètre ... peut être ais-je loupé un détail mais lequel ???
voici l'action qui génère l'erreur:
Code:
1 2 3 4 5 6 7
|
tableauSaisieBateau.init();
for ( i=0 ; i < 10 ; i++){
for ( j=0 ; j < 10 ; j++){
alert(tableauSaisieBateau.getCase(i,j).toString());
}
} |
Merci d'avance pour le coup de main !!