|
|
|
@ -12,16 +12,20 @@ var deckPartie = []; //Ensemble des cartes affichées à l'écran
|
|
|
|
|
|
|
|
|
|
class Carte {
|
|
|
|
|
|
|
|
|
|
constructor(id) {
|
|
|
|
|
constructor(id/*,row,column,nbForme*/) { //à décommenter quand il y aura des prametres de partie
|
|
|
|
|
//Attribut de Classe
|
|
|
|
|
this.identifiant = id;
|
|
|
|
|
this.Matrice = creaMatrice();
|
|
|
|
|
this.row = 4 /*row*/;
|
|
|
|
|
this.column = 3 /*column*/;
|
|
|
|
|
this.Matrice = creaMatrice(this.row, this.column);
|
|
|
|
|
|
|
|
|
|
//lien clicable
|
|
|
|
|
this.link = document.createElement('a');
|
|
|
|
|
this.link.id = this.identifiant;
|
|
|
|
|
//fonction de selection
|
|
|
|
|
this.link.onclick = function selectioncarte() {
|
|
|
|
|
/*this.link.onclick = function selectioncarte() {
|
|
|
|
|
window.alert(this.getFigureCreuse)
|
|
|
|
|
window.alert(this.getFigureCreuse)
|
|
|
|
|
var macarte = this.id;
|
|
|
|
|
var lacarte = "card" + macarte;
|
|
|
|
|
if (document.getElementById(lacarte).style.boxShadow != "") {
|
|
|
|
@ -37,7 +41,8 @@ class Carte {
|
|
|
|
|
else
|
|
|
|
|
window.alert("Bonjour !");
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
};*/
|
|
|
|
|
|
|
|
|
|
//div carte
|
|
|
|
|
var divconteneur = document.createElement('div');
|
|
|
|
|
divconteneur.className = "flex-item";
|
|
|
|
@ -51,29 +56,89 @@ class Carte {
|
|
|
|
|
// Point ou anneau trouvé => création
|
|
|
|
|
if (this.Matrice[i % 3][Math.floor(i / 3)] == 1) {
|
|
|
|
|
|
|
|
|
|
var divContainForm = document.createElement('div');
|
|
|
|
|
divContainForm.className = "containform";
|
|
|
|
|
//TEST : CRéation d'une figure Pleine => Rond
|
|
|
|
|
var uneFigure = new Figure(TypeFigure.Pleine, FormeFigure.Rond, i % 3, Math.floor(i / 3));
|
|
|
|
|
this.FigPleine = uneFigure;
|
|
|
|
|
|
|
|
|
|
var unRond = document.createElement('div');
|
|
|
|
|
unRond.className = "rond";
|
|
|
|
|
//unRond.style.backgroundColor = "#000DFF";
|
|
|
|
|
divconteneur.appendChild(uneFigure.getHTML);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else if (this.Matrice[i % 3][Math.floor(i / 3)] == 2) { // Point ou anneau trouvé => création
|
|
|
|
|
|
|
|
|
|
//TEST : CRéation d'une figure Pleine => Anneau
|
|
|
|
|
|
|
|
|
|
var uneFigure = new Figure(TypeFigure.Creuse, FormeFigure.Rond, i % 3, Math.floor(i / 3));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.FigCreuse = uneFigure;
|
|
|
|
|
|
|
|
|
|
divconteneur.appendChild(uneFigure.getHTML);
|
|
|
|
|
|
|
|
|
|
} else divconteneur.appendChild(divcase);
|
|
|
|
|
|
|
|
|
|
if (i == 0 || i == 2 || i == 9 || i == 11) {
|
|
|
|
|
unRond.style.backgroundColor = "#00CBFF";
|
|
|
|
|
}
|
|
|
|
|
if (i == 1 || i == 10) {
|
|
|
|
|
unRond.style.backgroundColor = "#00FF6E";
|
|
|
|
|
|
|
|
|
|
this.link.appendChild(divconteneur);
|
|
|
|
|
//fonction de selection
|
|
|
|
|
this.link.onclick = function selectioncarte() {
|
|
|
|
|
var macarte = this.id;
|
|
|
|
|
var lacarte = "card" + macarte;
|
|
|
|
|
|
|
|
|
|
var laCarte = deckPartie[this.id - 1]; //Carte liée avec le code HTML
|
|
|
|
|
|
|
|
|
|
if (document.getElementById(lacarte).style.boxShadow != "") {
|
|
|
|
|
var pos = carteselect.indexOf(laCarte);
|
|
|
|
|
carteselect.splice(pos, 1);
|
|
|
|
|
document.getElementById(lacarte).style.boxShadow = "";
|
|
|
|
|
}
|
|
|
|
|
if (i == 4 || i == 7) {
|
|
|
|
|
unRond.style.backgroundColor = "#C800FF";
|
|
|
|
|
else {
|
|
|
|
|
if (carteselect.length < 5) {
|
|
|
|
|
carteselect.push(laCarte);
|
|
|
|
|
document.getElementById(lacarte).style.boxShadow = "0 0 1vw red, 0 0 1vw red";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
window.alert("Bonjour !");
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
divContainForm.appendChild(unRond);
|
|
|
|
|
divcase.appendChild(divContainForm);
|
|
|
|
|
|
|
|
|
|
get getHTML() {
|
|
|
|
|
return this.link;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Point ou anneau trouvé => création
|
|
|
|
|
if (this.Matrice[i % 3][Math.floor(i / 3)] == 2) {
|
|
|
|
|
get getIdentifiant() {
|
|
|
|
|
return this.identifiant;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get getMatrice() {
|
|
|
|
|
return this.Matrice;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get getFigurePleine() {
|
|
|
|
|
return this.FigPleine;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get getFigureCreuse() {
|
|
|
|
|
return this.FigCreuse;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class Figure {
|
|
|
|
|
|
|
|
|
|
constructor(type, forme, Cox, Coy) {
|
|
|
|
|
this.X = Cox;
|
|
|
|
|
this.Y = Coy;
|
|
|
|
|
this.type = type;
|
|
|
|
|
this.forme = forme;
|
|
|
|
|
var pos = this.X + this.Y * 3;
|
|
|
|
|
var divcase = document.createElement('div');
|
|
|
|
|
divcase.className = "item-form";
|
|
|
|
|
switch (this.forme) {
|
|
|
|
|
case FormeFigure.Rond:
|
|
|
|
|
switch (this.type) {
|
|
|
|
|
|
|
|
|
|
case TypeFigure.Creuse:
|
|
|
|
|
|
|
|
|
|
var divContainForm = document.createElement('div');
|
|
|
|
|
divContainForm.className = "containform";
|
|
|
|
@ -81,13 +146,13 @@ class Carte {
|
|
|
|
|
var unCercle = document.createElement('div');
|
|
|
|
|
unCercle.className = "anneau";
|
|
|
|
|
|
|
|
|
|
if (i == 0 || i == 2 || i == 9 || i == 11) {
|
|
|
|
|
if (pos == 0 || pos == 2 || pos == 9 || pos == 11) {
|
|
|
|
|
unCercle.style.backgroundColor = "#00CBFF";
|
|
|
|
|
}
|
|
|
|
|
if (i == 1 || i == 10) {
|
|
|
|
|
if (pos == 1 || pos == 10) {
|
|
|
|
|
unCercle.style.backgroundColor = "#00FF6E";
|
|
|
|
|
}
|
|
|
|
|
if (i == 4 || i == 7) {
|
|
|
|
|
if (pos == 4 || pos == 7) {
|
|
|
|
|
unCercle.style.backgroundColor = "#C800FF";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -97,24 +162,69 @@ class Carte {
|
|
|
|
|
unCercle.appendChild(unRond);
|
|
|
|
|
divContainForm.appendChild(unCercle);
|
|
|
|
|
divcase.appendChild(divContainForm);
|
|
|
|
|
this.CodeHTML = divcase;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case TypeFigure.Pleine:
|
|
|
|
|
|
|
|
|
|
var divContainForm = document.createElement('div');
|
|
|
|
|
divContainForm.className = "containform";
|
|
|
|
|
|
|
|
|
|
var unRond = document.createElement('div');
|
|
|
|
|
unRond.className = "rond";
|
|
|
|
|
//unRond.style.backgroundColor = "#000DFF";
|
|
|
|
|
if (pos == 0 || pos == 2 || pos == 9 || pos == 11) {
|
|
|
|
|
unRond.style.backgroundColor = "#00CBFF";
|
|
|
|
|
}
|
|
|
|
|
//ajout de l'élément dans la carte
|
|
|
|
|
divconteneur.appendChild(divcase);
|
|
|
|
|
if (pos == 1 || pos == 10) {
|
|
|
|
|
unRond.style.backgroundColor = "#00FF6E";
|
|
|
|
|
}
|
|
|
|
|
if (pos == 4 || pos == 7) {
|
|
|
|
|
unRond.style.backgroundColor = "#C800FF";
|
|
|
|
|
}
|
|
|
|
|
divContainForm.appendChild(unRond);
|
|
|
|
|
divcase.appendChild(divContainForm);
|
|
|
|
|
this.CodeHTML = divcase;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
this.link.appendChild(divconteneur);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get HTML() {
|
|
|
|
|
return this.link;
|
|
|
|
|
get getHTML() {
|
|
|
|
|
return this.CodeHTML;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get getIdentifiant() {
|
|
|
|
|
return this.identifiant;
|
|
|
|
|
get getX() {
|
|
|
|
|
return this.X;
|
|
|
|
|
}
|
|
|
|
|
get getY() {
|
|
|
|
|
return this.Y;
|
|
|
|
|
}
|
|
|
|
|
get getType() {
|
|
|
|
|
return this.type;
|
|
|
|
|
}
|
|
|
|
|
get getForme() {
|
|
|
|
|
return this.forme;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const FormeFigure = {
|
|
|
|
|
Rond: 'rond',
|
|
|
|
|
Carre: 'carre',
|
|
|
|
|
Triangle: 'triangle',
|
|
|
|
|
Pentagone: 'pentagone',
|
|
|
|
|
Losange: 'Losange'
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const TypeFigure = {
|
|
|
|
|
Pleine: 'pleine',
|
|
|
|
|
Creuse: 'creuse'
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function journuit() {
|
|
|
|
|
//mode jour
|
|
|
|
|
if (mode % 2 == 0) {
|
|
|
|
@ -185,7 +295,7 @@ function creePartie() {
|
|
|
|
|
|
|
|
|
|
deckPartie.push(uneCarte);
|
|
|
|
|
|
|
|
|
|
document.getElementById("containcards").appendChild(uneCarte.HTML);
|
|
|
|
|
document.getElementById("containcards").appendChild(uneCarte.getHTML);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -220,13 +330,11 @@ function getRandom(min, max) {
|
|
|
|
|
return Math.round(Math.random() * (max - min) + min)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function creaMatrice() {
|
|
|
|
|
var cols = 3;
|
|
|
|
|
var rows = 4;
|
|
|
|
|
function creaMatrice(row, column) {
|
|
|
|
|
var myMatrice = new Array();
|
|
|
|
|
for (var i = 0; i < cols; i++) {
|
|
|
|
|
for (var i = 0; i < column; i++) {
|
|
|
|
|
myMatrice[i] = new Array();
|
|
|
|
|
for (var j = 0; j < rows; j++) {
|
|
|
|
|
for (var j = 0; j < row; j++) {
|
|
|
|
|
myMatrice[i][j] = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -251,6 +359,52 @@ function creaMatrice() {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//FONCTION DE TEST => permet de tester des fonctionnalité via un bouton
|
|
|
|
|
function test() {
|
|
|
|
|
|
|
|
|
|
if (carteselect.length < 2) {
|
|
|
|
|
window.alert("Selection trop petite");
|
|
|
|
|
return;
|
|
|
|
|
} else {
|
|
|
|
|
var Code = comparaisonDeCarte(carteselect[0], carteselect[1]);
|
|
|
|
|
window.alert(Code);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function comparaisonDeCarte(CarteMere, CarteFille) {
|
|
|
|
|
var Code = 0;
|
|
|
|
|
if (CarteMere == null) {
|
|
|
|
|
return 2;
|
|
|
|
|
}
|
|
|
|
|
var matCarteMere = CarteMere.getMatrice;
|
|
|
|
|
//CAS 1 : Il existe déja un ensemble( point <=> cercle ) sur CarteMere là où CarteFille possède un point ou un cercle
|
|
|
|
|
if ((matCarteMere[CarteFille.FigCreuse.X][CarteFille.FigCreuse.Y] == 3) || (matCarteMere[CarteFille.FigPleine.X][CarteFille.FigPleine.Y] == 3)) {
|
|
|
|
|
//Impossible d'empiler
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
//CAS 2 : L'emplassement est parfait ! Les Coordonnées sont bonnes
|
|
|
|
|
if (matCarteMere[CarteFille.FigCreuse.X][CarteFille.FigCreuse.Y] == 1) {
|
|
|
|
|
if (matCarteMere[CarteFille.FigPleine.X][CarteFille.FigPleine.Y] == 2) {
|
|
|
|
|
//Coordonnées parfaites
|
|
|
|
|
return 2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
//CAS 3 : une seule liaison est possible
|
|
|
|
|
if ((matCarteMere[CarteFille.FigCreuse.X][CarteFille.FigCreuse.Y] == 1) || (matCarteMere[CarteFille.FigPleine.X][CarteFille.FigPleine.Y] == 2)) {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
//Dernier cas : on ne peut rien faire avec ces cartes
|
|
|
|
|
return Code;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function ChoisirPseudo() {
|
|
|
|
|
let nom = localStorage.getItem('nom');
|
|
|
|
|
if (nom == null) {
|
|
|
|
|