diff --git a/TP03/EX02/js/memory.js b/TP03/EX02/js/memory.js index c0f6df1..1598165 100644 --- a/TP03/EX02/js/memory.js +++ b/TP03/EX02/js/memory.js @@ -5,7 +5,6 @@ var perduView; var gagneView; var btnStart; var scoreView; - var listeEtatAmpouleInitiale = []; var listeEtatAmpoule = []; var ALLUMEE = 1; diff --git a/TP03/EX03/css/style.css b/TP03/EX03/css/style.css new file mode 100644 index 0000000..fb466ee --- /dev/null +++ b/TP03/EX03/css/style.css @@ -0,0 +1,46 @@ +.slot{ + width:52px; + height:52px; + padding:2px; + margin:11px; + border:1px solid #aaaaaa; + background-color:#ffffff; + display:inline-block; + vertical-align:middle; +} +.drag{ + width:50px; + height:50px; + border:1px solid #aaaaaa; + background-color:#eeeeee; + text-align:center; + font-size:25px; + line-height:52px; +} + +.ct{ + height:100px; + margin:10px; + line-height:100px; + text-align:center; + +} +.normal{ + + background-color:#1583CC; + +} + +.good{ + background-color:#00867F; + +} +.wrong{ + + background-color:#eeaaaa; +} + +[draggable=true] { + cursor: move; +} + diff --git a/TP03/EX03/js/tri.js b/TP03/EX03/js/tri.js new file mode 100644 index 0000000..3a47688 --- /dev/null +++ b/TP03/EX03/js/tri.js @@ -0,0 +1,72 @@ +document.addEventListener('DOMContentLoaded', chargementPage); +var listeChiffreView = []; +var listeChiffre = []; +var listeChiffreTriee = []; +var start; +var end; +var listeEnd; +var score = 0; + +function chargementPage(){ + listeChiffreView = document.getElementsByClassName("drag"); + start = document.getElementById("start"); + end = document.getElementById("end"); + listeEnd = end.getElementsByClassName("slot"); + + start.addEventListener("dragstart", drag); + end.addEventListener("dragover", allowDrop); + end.addEventListener("drop", drop); + + remplirChiffre(0,100); + trierChiffre(); +} + +function remplirChiffre(min,max){ + for (let i=0; i (a-b)); +} + +function getRandomInt(min, max) { + return Math.floor(Math.random() * (max - min)) + min +} + +function findIndex(tableau, element){ + for (var i = 0; i < tableau.length; i++) { + if (tableau[i] === element) { + return i; + } + } + return null; +} + +function allowDrop(event) { + event.preventDefault(); + } + + function drag(event) { + event.dataTransfer.setData("objet", event.target.id); + } + + function drop(event) { + var numSlot = findIndex(listeEnd, event.target); + if (numSlot !== null){ + event.preventDefault(); + var idObjet = event.dataTransfer.getData("objet"); + var objet = document.getElementById(idObjet); + event.target.appendChild(objet); + if (objet.textContent !== ""+listeChiffreTriee[numSlot]){ + score --; + } + if (score < 0){ + end.classList.replace("good", "normal") + if (score < -3){ + end.classList.replace("normal", "wrong") + } + } + } + } \ No newline at end of file diff --git a/TP03/EX03/tri.html b/TP03/EX03/tri.html new file mode 100644 index 0000000..b9b2980 --- /dev/null +++ b/TP03/EX03/tri.html @@ -0,0 +1,63 @@ + + + + + + + + + + +

Drag and Drop

+ + + +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ + + +
+
+
+
+
+
+
+
+
+
+
+
+ +