Première version du Jeu Classique de Swich 60 cartes

master
yasevret 4 years ago
parent 437023ec09
commit 28b0a5a92f

@ -146,7 +146,7 @@
<div id="pageGame"> <div id="pageGame">
<div class="menuhaut"> <div class="menuhaut">
<div id="Redistribution"> <div id="Redistribution">
<a onclick="creePartieInfini()" id="relancerbtn"> <a onclick="redistribuer()" id="relancerbtn">
<div id="contourbuttonvalider"> <div id="contourbuttonvalider">
<div class="bouttonvalider"> <div class="bouttonvalider">
<h1 id="textjouer2">RELANCER</h1> <h1 id="textjouer2">RELANCER</h1>
@ -155,7 +155,7 @@
</a> </a>
</div> </div>
<div id="Redistribution2"> <div id="Redistribution2">
<a id="relancerbtn" onclick="test()"> <a id="relancerbtn" onclick="testPourJeuClassique()">
<div id="contourbuttonvalider"> <div id="contourbuttonvalider">
<div class="bouttonvalider2"> <div class="bouttonvalider2">
<h1 id="btnvalider2">VALIDER</h1> <h1 id="btnvalider2">VALIDER</h1>

@ -63,8 +63,11 @@ class Carte {
this.link.onclick = function selectioncarte() { this.link.onclick = function selectioncarte() {
var macarte = this.id; var macarte = this.id;
var lacarte = "card" + macarte; var lacarte = "card" + macarte;
for (var i = 0; i < deckPartie.length; i++) {
var laCarte = deckPartie[this.id - 1]; //Carte liée avec le code HTML if (this.id == deckPartie[i].identifiant) {
var laCarte = deckPartie[i];//Carte liée avec le code HTML
}
}
if (document.getElementById(lacarte).style.boxShadow != "") { if (document.getElementById(lacarte).style.boxShadow != "") {
var pos = carteselect.indexOf(laCarte); var pos = carteselect.indexOf(laCarte);
carteselect.splice(pos, 1); carteselect.splice(pos, 1);
@ -307,7 +310,7 @@ function journuit() {
function lancerpartie() { function lancerpartie() {
document.getElementById("pageAccueil").style.visibility = "hidden"; document.getElementById("pageAccueil").style.visibility = "hidden";
//fonction de création de partie à changer en fonction du test voulu //fonction de création de partie à changer en fonction du test voulu
genererTouteslesCartes3_4Possibles(); creePartieClassique();
document.getElementById("pageGame").style.visibility = "visible"; document.getElementById("pageGame").style.visibility = "visible";
} }
@ -324,46 +327,80 @@ function rechargerGAME() {
document.getElementById("containcards").appendChild(deckPartie[i].getHTML); document.getElementById("containcards").appendChild(deckPartie[i].getHTML);
} }
} }
function redistribuer() {
deckPartie = [];
for (var i = 0; i < 16; i++) {
var index = getRandom(0, TasDuJEU.length - 1)
var déjàPrésente = false;//Permet de savoir si la carte est déjà dans la liste
for (var j = 0; j < deckPartie.length; j++) {
if (TasDuJEU[index].identifiant == deckPartie[j].identifiant) {
déjàPrésente = true;
}
}
while (déjàPrésente == true) {
index = getRandom(0, TasDuJEU.length - 1)
déjàPrésente = false;//Permet de savoir si la carte est déjà dans la liste
for (var j = 0; j < deckPartie.length; j++) {
if (TasDuJEU[index].identifiant == deckPartie[j].identifiant) {
déjàPrésente = true;
}
}
}
deckPartie.push(copieCarte(TasDuJEU[index]));
}
afficherCartes(deckPartie);
}
//================================================================================================================================================================ //================================================================================================================================================================
//Fonction créations de game //Fonction créations de game
function genererTouteslesCartes3_4Possibles(){ function genererTouteslesCartes3_4Possibles() {
deckPartie = []; deckPartie = [];
carteselect = []; carteselect = [];
while (document.getElementById("containcards").firstElementChild != null) { while (document.getElementById("containcards").firstElementChild != null) {
document.getElementById("containcards").firstElementChild.remove(); document.getElementById("containcards").firstElementChild.remove();
} }
for (var k = 0; k < 2; k++) {
for (var j = 0; j < 2; j++) { for (var j = 0; j < 2; j++) {
for (var i = 0; i < 12; i++) { for (var i = 0; i < 12; i++) {
var AllFigure = []; var AllFigure = [];
AllFigure.push(new Figure(new Array(TypeFigure.Petit), FormeFigure.Rond, k, j)); AllFigure.push(new Figure(new Array(TypeFigure.Petit), FormeFigure.Rond, 0, j));
if (i != k + 3 * j) { if (i != 3 * j) {
if (k == 0) {
AllFigure.push(new Figure(new Array(TypeFigure.Moyen), FormeFigure.Rond, i % 3, Math.floor(i / 3))); AllFigure.push(new Figure(new Array(TypeFigure.Moyen), FormeFigure.Rond, i % 3, Math.floor(i / 3)));
var uneCarte = new Carte(deckPartie.length + 1, AllFigure); var uneCarte = new Carte(deckPartie.length + 1, AllFigure);
deckPartie.push(uneCarte);
if (!doublonInterdit(uneCarte)) { if (!doublonInterdit(uneCarte)) {
var unDoublon = copieCarte(uneCarte); AllFigure = [];
unDoublon.identifiant += 1; AllFigure.push(new Figure(new Array(TypeFigure.Petit), FormeFigure.Rond, 0, j));
AllFigure.push(new Figure(new Array(TypeFigure.Moyen), FormeFigure.Rond, i % 3, Math.floor(i / 3)));
var unDoublon = new Carte(deckPartie.length + 1, AllFigure);
deckPartie.push(unDoublon); deckPartie.push(unDoublon);
} }
deckPartie.push(uneCarte); }
} else if (i != 2 && i != 5 && i != 8 && i != 11) { }
}
for (var j = 0; j < 2; j++) {
for (var i = 0; i < 12; i++) {
var AllFigure = [];
AllFigure.push(new Figure(new Array(TypeFigure.Petit), FormeFigure.Rond, 1, j));
if (i != 3 * j + 1) {
if (i != 2 && i != 5 && i != 8 && i != 11) {
AllFigure.push(new Figure(new Array(TypeFigure.Moyen), FormeFigure.Rond, i % 3, Math.floor(i / 3))); AllFigure.push(new Figure(new Array(TypeFigure.Moyen), FormeFigure.Rond, i % 3, Math.floor(i / 3)));
var uneCarte = new Carte(deckPartie.length + 1, AllFigure); var uneCarte = new Carte(deckPartie.length + 1, AllFigure);
deckPartie.push(uneCarte);
if (!doublonInterdit(uneCarte)) { if (!doublonInterdit(uneCarte)) {
var unDoublon = copieCarte(uneCarte); AllFigure = [];
unDoublon.identifiant += 1; AllFigure.push(new Figure(new Array(TypeFigure.Petit), FormeFigure.Rond, 1, j));
AllFigure.push(new Figure(new Array(TypeFigure.Moyen), FormeFigure.Rond, i % 3, Math.floor(i / 3)));
var unDoublon = new Carte(deckPartie.length + 1, AllFigure);
deckPartie.push(unDoublon); deckPartie.push(unDoublon);
} }
deckPartie.push(uneCarte);
} }
} }
} }
} }
}
afficherCartes(deckPartie)
return deckPartie; return deckPartie;
} }
@ -394,6 +431,22 @@ function creePartieClassique() {
} }
for (var i = 0; i < 16; i++) { for (var i = 0; i < 16; i++) {
var index = getRandom(0, TasDuJEU.length - 1) var index = getRandom(0, TasDuJEU.length - 1)
var déjàPrésente = false;//Permet de savoir si la carte est déjà dans la liste
for (var j = 0; j < deckPartie.length; j++) {
if (TasDuJEU[index].identifiant == deckPartie[j].identifiant) {
déjàPrésente = true;
}
}
while (déjàPrésente == true) {
index = getRandom(0, TasDuJEU.length - 1)
déjàPrésente = false;//Permet de savoir si la carte est déjà dans la liste
for (var j = 0; j < deckPartie.length; j++) {
if (TasDuJEU[index].identifiant == deckPartie[j].identifiant) {
déjàPrésente = true;
}
}
}
deckPartie.push(copieCarte(TasDuJEU[index])); deckPartie.push(copieCarte(TasDuJEU[index]));
} }
afficherCartes(deckPartie); afficherCartes(deckPartie);
@ -432,7 +485,41 @@ function creePartieInfini() {
} }
//======================================================================================================================================================== //========================================================================================================================================================
//Changer les cartes //Changer les cartes et Changer les cartes de Tas de jeu
function changerlesCartesDeTasDeJeu() {
while (carteselect.length != 0) {
var unIndex = TasDuJEU.indexOf(carteselect[0]);
TasDuJEU.splice(unIndex, 1);
if (TasDuJEU.length > 16) {
var index2 = getRandom(0, TasDuJEU.length - 1)
var déjàPrésente = false;//Permet de savoir si la carte est déjà dans la liste
for (var j = 0; j < deckPartie.length; j++) {
if (TasDuJEU[index2].identifiant == deckPartie[j].identifiant) {
déjàPrésente = true;
}
}
while (déjàPrésente == true) {
index2 = getRandom(0, TasDuJEU.length - 1)
déjàPrésente = false;//Permet de savoir si la carte est déjà dans la liste
for (var j = 0; j < deckPartie.length; j++) {
if (TasDuJEU[index2].identifiant == deckPartie[j].identifiant) {
déjàPrésente = true;
}
}
}
unIndex = deckPartie.indexOf(carteselect[0]);
deckPartie[unIndex] = TasDuJEU[index2];
} else {
unIndex = deckPartie.indexOf(carteselect[0]);
deckPartie.splice(unIndex, 1);
}
carteselect.shift();
}
afficherCartes(deckPartie);
}
function changerlesCartes() { function changerlesCartes() {
while (carteselect.length != 0) { while (carteselect.length != 0) {
@ -569,7 +656,7 @@ function chercheCombi2() {
} }
if (!solution) { if (!solution) {
Cptsolution++; Cptsolution++;
window.alert("Combinaison a 2 trouvé: " + (i+1) + " " + (i + j + 2)); window.alert("Combinaison a 2 trouvé: " + (i + 1) + " " + (i + j + 2));
} }
} }
} }
@ -638,24 +725,21 @@ function chercheCombi3() {
//================================================================================= //=================================================================================
//FONCTION DE TEST => permet de tester des fonctionnalité via le bouton VALIDER //FONCTION DE TEST => permet de tester des fonctionnalité via le bouton VALIDER
function test() { function testPourJeuInfini() {
try { try {
if (carteselect.length == 0) { if (carteselect.length == 0) {
window.alert("Selection Vide"); window.alert("Selection Vide");
return; return;
} else if (carteselect.length < 2) { } else if (carteselect.length < 2) {
//window.alert("Selection Trop Petite"); window.alert("Selection Trop Petite");
var leCarte = copieCarte(carteselect[0]);
document.getElementById("containcards").appendChild(leCarte.link);
return; return;
} else { } else {
var copie = []; var copie = [];
for (var i = 0; i < carteselect.length; i++) { for (var i = 0; i < carteselect.length; i++) {
copie.push(carteselect[i]); copie.push(copieCarte(carteselect[i]));
} }
var tab = []; var tab = [];
tab = AssemblageARBRE(copieListeDeCarte(copie), carteselect[0]); tab = AssemblageARBRE(copieListeDeCarte(copie), copieCarte(carteselect[0]));
var solution = true; var solution = true;
var tabCode = []; var tabCode = [];
for (var i = 0; i < tab.length; i++) { for (var i = 0; i < tab.length; i++) {
@ -680,6 +764,47 @@ function test() {
} }
} }
//Fonction de test mias pour le jeu classique
function testPourJeuClassique() {
//try {
if (carteselect.length == 0) {
window.alert("Selection Vide test pour jeu classique");
return;
} else if (carteselect.length < 2) {
window.alert("Selection Trop Petite");
return;
} else {
var copie = [];
for (var i = 0; i < carteselect.length; i++) {
copie.push(copieCarte(carteselect[i]));
}
var tab = [];
tab = AssemblageARBRE(copie, copieCarte(carteselect[0]));
var solution = true;
var tabCode = [];
for (var i = 0; i < tab.length; i++) {
tabCode.push(tab[i].code);
}
for (var i = 0; i < tab.length; i++) {
if (tab[i].code == carteselect.length) {
solution = false;
changerlesCartesDeTasDeJeu();
}
}
if (solution) {
window.alert("Rien trouvé chef !!!");
}
if (!solution) {
window.alert("J'ai une solution chef !!!!");
}
window.alert(TasDuJEU.length)
}
/*} catch (e) {
window.alert(e);
}*/
}
//=================================================================================== //===================================================================================
//Function de copie diverse //Function de copie diverse

Loading…
Cancel
Save