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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
|
function decompte() //De 3 à 1
{
//Choix du fond image
var fond = getCookie("fond");
if(fond != "Simple (sans son)"){
if(fond == "Kingdom Heart"){
$("body").css("background-image","url('Image/fond-KH.png')").fadeIn(6000);
}
if(fond == "Final Fantasy 9"){
$("body").css("background-image","url('Image/fond-FF9.jpeg')").fadeIn(6000);
}
if(fond == "Final Fantasy 10-2"){
$("body").css("background-image","url('Image/fond-FF10-2.png')").fadeIn(6000);
}
if(fond == "Zelda"){
$("body").css("background-image","url('Image/fond-Zelda.png')").fadeIn(6000);
}
if(fond == "Tekken"){
$("body").css("background-image","url('Image/fond-Tekken.png')").fadeIn(6000);
}
if(fond == "Tetris"){
$("body").css("background-image","url('Image/fond-Tetris.png')").fadeIn(6000);
}
if(fond == "Sonic"){
$("body").css("background-image","url('Image/fond-Sonic.png')").fadeIn(6000);
}
if(fond == "Mega Man"){
$("body").css("background-image","url('Image/fond-MegaMan.png')").fadeIn(6000);
}
}
if(cpt>=1) //Ne passe pas par zéro
{
$("#Chrono").html(cpt).fadeOut(200).fadeIn(100); //écriture
cpt-- ; //décompte
x = setTimeout(decompte,1000); //Retire 1 sec
}
else
{
clearTimeout(x) ;
$("#Chrono").html("C'est parti !").fadeOut(200).fadeIn(100); //Ecriture
jQuery('#Chrono').fadeTo("slow", 0, function(){
$("#Chrono").hide();
$("#Calcul").css({'align':'center'});
$("#reponse").css({'align':'center'});
chrono();
music();
Calcul();
});
}
}
function chargerXML(){
// Routine de vérification si le navigateur gêre la méthode utilisée
if (document.implementation && document.implementation.createDocument) {
docXml = document.implementation.createDocument('', '', null);
}
else if (window.ActiveXObject){
// déclaration pour IE
docXml = new ActiveXObject("Microsoft.XMLDOM");
}
else {
alert('Navigateur pas adapte.');
return NULL;
}
docXml.load("Niveau.xml");
return docXml;
}
function Calcul(){
//chargement du doc xml Niveau.xml
var docXml=chargerXML();
var niveau = getCookie("Niveau");
var typesigne = getCookie("Signe");
var nbcalc = getCookie("Nb");
var timer = getCookie("timer");
var score = getCookie('score');
var nb = 0;
//Si typesigne = 2, c'est les 2 signes, donc on génére un nombre pour le rendre aléatoire.
//Si typesigne = 0, c'est +, donc signe = +
//Si typesigne = 1, c'est -, donc signe = -
//variable pour deplacement dans les blocs du xml
var n = niveau -1;
var signuse = "";
if(typesigne == 0){
signuse = "+";
}
else if (typesigne == 1){
signuse = "-";
n=n+8;
}
var i = getCookie('nbCourant');
//for(i=1; i<=nbcalc; i++){
if(typesigne == 2){
nb = Math.round(Math.random()*1); //Génére un nombre compris entre 0 et 1
//respect des données xml si c'est une + ou une -
if(nb==0){
n=niveau-1;
signuse="+";
}
else{
n=(niveau-1)+8;
signuse="-";
}
}
//alert(signuse);
//on recupere toutes les infos des 3 balises (sous forme de tableau)
var nbOps = docXml.getElementsByTagName('operande');
var minima = docXml.getElementsByTagName('resMin');
var maxima = docXml.getElementsByTagName('resMax');
//on prend les 3 elements a l'indice n (suivant le niveau)
//et conversion en entier
var nbChiffre = parseInt(nbOps[n].firstChild.nodeValue);
var min = parseInt(minima[n].firstChild.nodeValue);
var max = parseInt(maxima[n].firstChild.nodeValue);
//on convertit le nb d'operande en nombre de chiffre dans le calcul
nbChiffre+=1;
//alert("NbChiffre: "+nbChiffre+" min:"+min+" max:"+max );
var chiffre1 = Math.round(Math.random()*(max-1))+1;
var chiffre2 = Math.round(Math.random()*(max-1))+1;
var chiffre3 = Math.round(Math.random()*(max-1))+1;
var chiffre4 = Math.round(Math.random()*(max-1))+1;
var chiffre5 = Math.round(Math.random()*(max-1))+1;
var calcul = "";
if(nbChiffre==2){
calcul=chiffre1+signuse+chiffre2;
}
else if(nbChiffre==3){
calcul=chiffre1+signuse+chiffre2+signuse+chiffre3;
}
else if(nbChiffre==4){
calcul=chiffre1+signuse+chiffre2+signuse+chiffre3+signuse+chiffre4;
}
else if(nbChiffre==5){
calcul=chiffre1+signuse+chiffre2+signuse+chiffre3+signuse+chiffre4+signuse+chiffre5;
}
var result=eval(calcul);//Va résoudre le calcul
//Tant que le résultat n'est pas situé entre min et max
while(result < max && result > min){
chiffre1 = Math.round(Math.random()*(max-1))+1;
chiffre2 = Math.round(Math.random()*(max-1))+1;
chiffre3 = Math.round(Math.random()*(max-1))+1;
chiffre4 = Math.round(Math.random()*(max-1))+1;
chiffre5 = Math.round(Math.random()*(max-1))+1;
if(nbChiffre==2){
calcul=chiffre1+signuse+chiffre2;
}
else if(nbChiffre==3){
calcul=chiffre1+signuse+chiffre2+signuse+chiffre3;
}
else if(nbChiffre==4){
calcul=chiffre1+signuse+chiffre2+signuse+chiffre3+signuse+chiffre4;
}
else if(nbChiffre==5){
calcul=chiffre1+signuse+chiffre2+signuse+chiffre3+signuse+chiffre4+signuse+chiffre5;
}
result=eval(calcul);//Va résoudre le calcul
}
alert("Calcul: "+calcul+" Res:"+result);
//Affichage du calcul sur la page ( + visibility true !)
//document.getElementById("reponse").style.visibility = 'visible';
$("#reponse").css({'visibility':'visible'});
$("#Calcul").html(calcul);
$("#reponse").val('');
setCookie('resultatCalc',result,1);
} |
Partager