Ajout Fonction Création et afficher Carte dans main.js

Golfier
Yannis 5 years ago
parent d527f56e83
commit 91d3e4b20f

@ -99,9 +99,44 @@ function creecarte(){
divconteneur.id = "card"+j;
//div case
//ICI A VOIR POUR AJOUTER LES FORMES EN FONCTION DE LA MATRICE
var uneMatrice = creaMatrice();
for (var i = 0; i < 12; i++) {
var divcase = document.createElement('div');
divcase.className = "item-form";
// Point ou anneau trouvé => création
if (uneMatrice[i % 3][Math.floor(i / 3)] == 1) {
var divContainForm = document.createElement('div');
divContainForm.className = "containform";
var unRond = document.createElement('div');
unRond.className = "rond";
divContainForm.appendChild(unRond);
divcase.appendChild(divContainForm);
}
// Point ou anneau trouvé => création
if (uneMatrice[i % 3][Math.floor(i / 3)] == 2) {
var divContainForm = document.createElement('div');
divContainForm.className = "containform";
var unCercle = document.createElement('div');
unCercle.className = "anneau";
var unRond = document.createElement('div');
unRond.className = "rondinterieur inté";
unCercle.appendChild(unRond);
divContainForm.appendChild(unCercle);
divcase.appendChild(divContainForm);
}
//ajout de l'élément dans la carte
divconteneur.appendChild(divcase);
}
newlink.appendChild(divconteneur);
@ -109,8 +144,40 @@ function creecarte(){
}
}
function getRandom(min, max) {
return Math.round(Math.random() * (max - min) + min)
}
function creaMatrice() {
var cols = 3;
var rows = 4;
var myMatrice = new Array();
for (var i = 0; i < cols; i++) {
myMatrice[i] = new Array();
for (var j = 0; j < rows; j++) {
myMatrice[i][j] = 0;
}
}
var Cox1, Coy1, Cox2, Coy2;
Cox1 = getRandom(0, 2);
Coy1 = getRandom(0, 3);
myMatrice[Cox1][Coy1] = 1;
Cox2 = getRandom(0, 2);
Coy2 = getRandom(0, 3);
while (Cox2 == Cox1 && Coy1 == Coy2) {
Cox2 = getRandom(0, 2);
Coy2 = getRandom(0, 3);
}
myMatrice[Cox2][Coy2] = 2;
return myMatrice;
}

Loading…
Cancel
Save