/* auteur: Gilles Lévesque */
/* Date de création: 04-03-25 */

	// JS-Pendu JavaScript (C)1997 Cyril Pannetier - La Petite Boutique JavaScript -
	// web : http://www.mygale.org/08/pannetie
	// e-mail : pannetie@mygale.org
	// Ce script est librement utilisable. Merci de ne pas effacer ces commentaires.
	
	var listemot = new Array(50);
	var motcache = "";
	var playedchar = new Array(26);
	var played = 0;
	var nbplayed = 0;
	var Pieces = new Array(6);
	var table = new Array(motcache.length);
	var affiche = new Array(motcache.length);
	var pt=0;
	var essai=0;
	
	Pieces[0] = 'images/pendu/pied.gif';
	Pieces[1] = 'images/pendu/mat.gif';
	Pieces[2] = 'images/pendu/potence.gif';
	Pieces[3] = 'images/pendu/tete.gif';
	Pieces[4] = 'images/pendu/bras.gif';
	Pieces[5] = 'images/pendu/jambes.gif';
	
	listemot[00] = "ALEATOIRE"; listemot[01] = "TORTUE"; listemot[02] = "PINGOUIN"; listemot[03] = "MAISON"; listemot[04] = "ERSATZ";
	listemot[05] = "VOITURE"; listemot[06] = "COPAIN"; listemot[07] = "EOLIENNE"; listemot[08] = "MASQUE"; listemot[09] = "SOURIRE";
	listemot[10] = "WAGON"; listemot[11] = "HYENE"; listemot[12] = "RIVIERE"; listemot[13] = "PROVINCE"; listemot[14] = "DIALOGUE";
	listemot[15] = "EXEMPLE"; listemot[16] = "RIDEAUX"; listemot[17] = "RAMONER"; listemot[18] = "MYSTERE"; listemot[19] = "QUILLE";
	listemot[20] = "USINE"; listemot[21] = "FERMIER"; listemot[22] = "TOUPIE"; listemot[23] = "HEXAGONE"; listemot[24] = "PHYSIQUE";
	listemot[25] = "COLLEGUE"; listemot[26] = "PRATICIEN"; listemot[27] = "CLAMEUR"; listemot[28] = "JUSTIFIER"; listemot[29] = "SANTE";
	listemot[30] = "AMICAL"; listemot[31] = "BOUTIQUE"; listemot[32] = "MERVEILLE"; listemot[33] = "CLASSIQUE"; listemot[34] = "FORMULE";
	listemot[35] = "CYCLONE"; listemot[36] = "VIOLET"; listemot[37] = "ELEPHANT"; listemot[38] = "PIGNON"; listemot[39] = "BALAYER";
	listemot[40] = "ENIGME"; listemot[41] = "SOLUTION"; listemot[42] = "FRANCHISE"; listemot[43] = "SENTIMENT"; listemot[44] = "COLLOQUE";
	listemot[45] = "YACHT"; listemot[46] = "VARICE"; listemot[47] = "COQUIN"; listemot[48] = "VOYOU"; listemot[49] = "SUCETTE";
	
	function Help() {
		window.open('help.htm','Aide','width=400,height=350,scrollbars=1');
	}
	function Aleatoire(mini,maxi) {
		var x = -1;
		while (x < mini) {
			x = Math.round(Math.random() * maxi);
		}
		return x;
	}
	function Initialise() {
		motcache = listemot[Aleatoire(0,49)];
		table = new Array(motcache.length);
		affiche = new Array(motcache.length);
		played = 0;
		nbplayed = 0;
		for (var x = 0; x < motcache.length; x++) {
			table[x] = motcache.charAt(x);
			affiche[x] = "- ";
		}
		for (var x = 0; x < 6; x++) {
			document.images[x].src = "images/pendu/dot.gif";
		}
		out = "";
		for (var x = 0; x < motcache.length; x++) {
			out = out + affiche[x];
		}
		for (var x = 0; x <= nbplayed; x++) {
			playedchar[x] = "";
		}
		document.PENDUP.Point.value = pt;
		document.PENDUP.Essai.value = essai;
		document.PENDU.MotCache.value = out;
		document.PENDU.Caractere.value = "";
		document.PENDU.CarJoues.value = "";
		document.PENDU.Caractere.focus();
	}
	function Continue() {
		if (played == 6) {
			window.alert("Vous avez perdu!");
			out = "";
			for (var x = 0; x < motcache.length; x++) {
				out = out + table[x];
			}
			document.PENDU.MotCache.value = out;
			if(pt>=1)
			   pt-=1;
			essai+=1; 
		}
		else {
			if (table.join() == affiche.join()) {
				window.alert("Vous avez gagné!");
		        pt+=1;
				essai+=1; 
			}
		}
		document.PENDUP.Point.value = pt;
		document.PENDUP.Essai.value = essai;
	}
	function OKToPlay(carac) {
		if (played == 6) {
			return 1;
		}
		else {
			if (table.join() == affiche.join()) {
				return 2;
			}
			else {
				if (carac == "") {
					return 3;
				}
				else {
					var exist = false;
					for (var x = 0; x < nbplayed; x++) {
						if (playedchar[x] == carac) {
							exist = true;
						}
					}
					if (exist) {
						return 4;
					}		
				}
			}
		}
		return 0;
	}
	function TestCar() {
		var good = false;
		propose = document.PENDU.Caractere.value;
		propose = propose.toUpperCase();
		var test = OKToPlay(propose);
		if (test == 0) {
			playedchar[nbplayed] = propose;
			for (var x = 0; x < motcache.length; x++) {
				if (propose == table[x]) {
					affiche[x] = propose;
					good = true;
				}
			}
			if (good) {
				out = "";
				for (var x = 0; x < motcache.length; x++) {
					out = out + affiche[x];
				}
				document.PENDU.MotCache.value = out;
			}
			else {
				document.images["PENDU"+played].src = Pieces[played];
				played++;
			}
			out = "";
			for (var x = 0; x <= nbplayed; x++) {
				out = out + playedchar[x];
			}
			nbplayed++;
			document.PENDU.CarJoues.value = out;
			document.PENDU.Caractere.value = "";
			Continue();
		}
		else {
			if (test == 1) {
				window.alert("Vous avez perdu!");
				document.PENDU.Caractere.value = "";
			}
			if (test == 2) {
				window.alert("Vous avez gagné!");
				document.PENDU.Caractere.value = "";
			}
			if (test == 3) {
				window.alert("Vous devez saisir un caractère!");
				document.PENDU.Caractere.value = "";
			}
			if (test == 4) {
				window.alert("Caractère déjà proposé!");
				document.PENDU.Caractere.value = "";
			}
		}
		document.PENDU.Caractere.focus();
	}
	// Fin du script du pendu
	function UpdateStatusBar(Num) {
		commentaires = new Array(3);
		commentaires[0] = '';
		commentaires[1] = 'Ecrivez-moi';
		commentaires[2] = 'La Petite Boutique : des scripts de toutes sortes...';
		window.status = commentaires[Num];
	}
