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
   | nombre=0;
points=0;
tentatives=0;
function init(){
	img=new Array(20);
		for (i=0;i<10;i++){
			img[i]=i+1;
			img[i+10]=i+1;
		}
		for (i=0;i<20;i++){
			a=rnd(20);
			b=img[a];
			img[a]=img[i];
			img[i]=b;
		}
 
	points=0;
	tentatives=0;
	document.getElementById('affNbCoup').innerHTML='0'
	document.getElementById('cartepos00').src='0.png';
	document.getElementById('cartepos01').src='0.png';
	document.getElementById('cartepos02').src='0.png';
	document.getElementById('cartepos03').src='0.png';
	document.getElementById('cartepos04').src='0.png';
	document.getElementById('cartepos10').src='0.png';
	document.getElementById('cartepos11').src='0.png';
	document.getElementById('cartepos12').src='0.png';
	document.getElementById('cartepos13').src='0.png';
	document.getElementById('cartepos14').src='0.png';
	document.getElementById('cartepos20').src='0.png';
	document.getElementById('cartepos21').src='0.png';
	document.getElementById('cartepos22').src='0.png';
	document.getElementById('cartepos23').src='0.png';
	document.getElementById('cartepos24').src='0.png';
	document.getElementById('cartepos30').src='0.png';
	document.getElementById('cartepos31').src='0.png';
	document.getElementById('cartepos32').src='0.png';
	document.getElementById('cartepos33').src='0.png';
	document.getElementById('cartepos34').src='0.png';
}
 
 
 
function joue(i){
	if (img[i]!=-1){
		if (nombre==0){
			nombre=1;
			case1=i;
			change(i,img[i]+'.png',0);
		}else if (nombre==1){
			case2=i;
			change(i,img[i]+'.png',0);
			tentatives++;
			document.getElementById("affNbCoup").innerHTML=tentatives;
			if (img[case1]==img[case2]){
				points++;
				img[case1]=-1;
				img[case2]=-1;
				if (points==10){
					document.getElementById("affRecord").innerHTML=Math.min(tentatives);
					alert("Vous avez gagné");
				}
			}else{
				setTimeout("change("+case1+",'0.png',0);change("+case2+",'0.png',0);", 1000);
			}
			nombre=0;
		}
	}
}
function change(image, j, avancement)
{	
	document.images[image].src=j;
	avancement++;
	if (avancement<23)setTimeout("change("+image+", '"+j+"', "+avancement+");",10);
}
function rnd(n)
{
	var temp = Math.random();
	if (temp==1) temp=0.9;
	return Math.floor(temp * n);
}
function nouvellePartie(){
	init();
}
function tournerCarte(){
	var i = 0;
		for (i=0;i<=20;i++){
			document.getElementById('cartepos0'+i).src='0.png';
		}
}
onload=init; | 
Partager