Download: cliquer ici
Retour vers: rubrique "Gag"
JOUEZ AU PENDU...

Cliquez sur "download" pour télécharger le kit nécessaire.
Compatible IE et NS. L'ordinateur choisit un mot. Cherchez à le reconstituer en proposant un caractère à la fois. Personnalisable: les mots disponibles, les messages affichés en cas d'erreur, les images utilisées pour le pendu etc.

L'ORDINATEUR
A CHOISI UN MOT :



Proposer un caractère :



Caractères joués :




©Cyril Pannetier La Petite Boutique JavaScript


1/ Insérez entre HEAD et /HEAD :
ou entre BODY et /BODY...
<SCRIPT LANGUAGE="JavaScript">
	<!--
	// 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);
	
	Pieces[0] = 'KITWEBpendu01/pied.gif';
	Pieces[1] = 'KITWEBpendu01/mat.gif';
	Pieces[2] = 'KITWEBpendu01/potence.gif';
	Pieces[3] = 'KITWEBpendu01/tete.gif';
	Pieces[4] = 'KITWEBpendu01/bras.gif';
	Pieces[5] = 'KITWEBpendu01/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('KITWEBpendu01/help.html','Aide','width=400,height=300,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 = "KITWEBpendu01/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.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;
		}
		else {
			if (table.join() == affiche.join()) {
				window.alert("Vous avez gagné!");
			}
		}
	}
	
	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] = 'KITWEB a sélectionné pour vous...';
		commentaires[2] = 'scripts, backgrounds, visuels, conseils etc...';
	
		window.status = commentaires[Num];
	}
	//-->
	</SCRIPT>

2/ Insérez dans le corps de la page :
à l'emplacement où doit apparaître l'effet.
<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0>
<!-- potence -->
<TR>
	<TD ROWSPAN=5 ALIGN="CENTER" VALIGN="TOP" BGCOLOR="Yellow">
<FORM NAME="PENDU">
<SUB><b>L'ORDINATEUR
<br>A CHOISI UN MOT :</b></SUB><BR>
<INPUT TYPE="TEXT" NAME="MotCache" SIZE=12 MAXLENGTH=10><BR><BR>
Proposer un caractère :<br>
<INPUT TYPE="TEXT" NAME="Caractere" SIZE=2 MAXLENGTH=1><BR>
<INPUT TYPE="BUTTON" VALUE="Valider" onClick="TestCar();"><BR><BR>
<SUB>Caractères joués :</SUB><BR>
<TEXTAREA NAME="CarJoues" ROWS=2 COLS=20></TEXTAREA><BR><BR>
<INPUT TYPE="BUTTON" VALUE="Rejouer" onClick="Initialise();"><BR><BR>
<INPUT TYPE="BUTTON" VALUE="Aide ?" onClick="Help();">
</FORM>
<SUB><font size=1>©<A HREF="mailto:pannetie@mygale.org">Cyril Pannetier</A> 
<A HREF="http://www.mygale.org/08/pannetie/" TARGET="_top">La Petite Boutique JavaScript</A></font></SUB>
	</TD>
	<TD> </TD>
	<TD COLSPAN=4 ALIGN="LEFT" VALIGN="BOTTOM"><IMG SRC="KITWEBpendu01/dot.gif" WIDTH=113 HEIGHT=14 BORDER=0 NAME="PENDU2"></TD>
</TR>
<!-- tête -->
<TR>
	<TD> </TD>
	<TD ROWSPAN=3 ALIGN="CENTER" VALIGN="MIDDLE" HEIGHT=193><IMG SRC="KITWEBpendu01/dot.gif" WIDTH=27 HEIGHT=193 BORDER=0 NAME="PENDU1"></TD>
	<TD ALIGN="CENTER" HEIGHT=61><IMG SRC="KITWEBpendu01/dot.gif" WIDTH=102 HEIGHT=62 BORDER=0 NAME="PENDU3"></TD>
	<TD> </TD>
	<TD> </TD>
</TR>
<!-- bras -->
<TR>
	<TD WIDTH=100> </TD>
	<TD ALIGN="CENTER" HEIGHT=38><IMG SRC="KITWEBpendu01/dot.gif" WIDTH=102 HEIGHT=39 BORDER=0 NAME="PENDU4"></TD>
	<TD> </TD>
	<TD> </TD>
</TR>
<!-- jambes -->
<TR>
	<TD> </TD>
	<TD ALIGN="CENTER" VALIGN="TOP" HEIGHT=84><IMG SRC="KITWEBpendu01/dot.gif" WIDTH=102 HEIGHT=70 BORDER=0 NAME="PENDU5"></TD>
	<TD> </TD>
	<TD> </TD>
</TR>
<!-- pieds -->
<TR>
	<TD COLSPAN=4 ALIGN="CENTER" VALIGN="TOP" HEIGHT=150><IMG SRC="KITWEBpendu01/dot.gif" WIDTH=183 HEIGHT=23 BORDER=0 NAME="PENDU0"></TD>
	<TD> </TD>
</TR>
</TABLE>

3/ Insérez DANS la balise BODY:
<BODY onLoad="Initialise();">