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 34 35 36 37 38 39 40 41 42 43 44 45
| <script type="text/javascript">
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="+ this.wasFire;
};
}
function Matrice(){
this.tableau = null;
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=function(x,y){
return (this.tableau[x][y]);
}
}
var tableauSaisieBateau = new Matrice();
tableauSaisieBateau.init();
for ( i=0 ; i < 10 ; i++){
for ( j=0 ; j < 10 ; j++){
alert(tableauSaisieBateau.getCase(i,j).toString());
}
}
</script> |
Partager