no save
Assistance
Achat
News

Forum | programmation
Vache taureau ??!!
bubuche87, le mar. 27 mars 2007 à 20:43:37
bon, je viens d'arriver, et je n'ai pa eut le temps deregarder ton code, mais je t'ai pondu ça ^^
(bien sur, il te faut un interpreteur de php pour l'utiliser)


<?php
//type de création: logiciel/jeu
//début de création : mardi 27 mars 2007 a 19:02
$vache = 'vaches';
$taureau = 'taureaux';
$titre = 'KIM - jeu de la vache';
$fichier = 'kim_jeu.php';
$couleur['w'] = '#ffffff';
$couleur['b'] = '#000000';
$couleur['g'] = '#ff00ff';
$fond = 'red';
$style= 'body {background-color:#eeffff}
h1 {text-align:center}
.titre {text-align:center;font-weight:bold}';

if (isset($_GET['action']))
{
if($_GET['action'] == 'depart')
{
session_start ();
unset ($_SESSION);
$_SESSION['nb_coups'] = $_POST['nb_coups']+2;
$_SESSION['nb_pions'] = $_POST['nb_pions'];
$_SESSION['numero_du_coup'] = 0;
$_SESSION['reponse'] = '';
$_SESSION['coup'] = array ();
$nb_couleur = count ($couleur);
$_SESSION['bonne_rep'] = '';
for ($x = 0; $x < $_POST['nb_pions']; $x++)
{
$_SESSION['bonne_rep'] .= array_rand($couleur);
}
$_SESSION['afficher'] = '<select name="rep[]">
';
foreach ($couleur as $key => $value)
{
$_SESSION['afficher'] .= ' <option value="'.$key.'">'.$key.'</option>
';
}
$_SESSION['afficher'] .= '</select>
';
header ('location:'.$fichier.'?action=afficher');
}
elseif ($_GET['action'] == 'afficher')
{
session_start ();
echo '<!DOCTYPE HTML PUBLIC \'-//W3C//DTD HTML 4.01 Transitional//EN\' \'http://www.w3.org/TR/html4/loose.dtd\'>
<html>
<head>
<title>'.$titre.'</title>
<style>'.$style.'</style>
</head>
<body>';

if ($_SESSION['nb_coups'] != 0)
{
$_SESSION['nb_coups']--;
if (isset ($_SESSION['nb_restant']) and $_SESSION['nb_restant'] == 0)
{
echo '<h1>',$_SESSION['bonne_rep'],'</h1>
<p>Vous avez gagné!!!!!!!!</p>
<div><a href="',$fichier,'">Voulez vous recommencer</a>
</div>';
}
else
{
echo '
<form action="',$fichier,'?action=coup" method="post">
<table>
<tr class="titre">
<td>Coup N°</td>
<td>Combinaison testée</td>
<td>Résultat</td>
</tr>';
$x = 0;
foreach ($_SESSION['coup'] as $key => $value)
{
echo '
<tr>
<td>',$key,'</td>
<td>', $_SESSION['reponse'][$x], '</td>
<td>',$value,'</td>
</tr>';
$x++;
}
echo '</table><table>';
echo '<tr>';
for ($x = 0; $x < $_SESSION['nb_pions']; $x++)
{
echo '<td>', $_SESSION['afficher'], '</td>
';
}
echo '</tr>';

echo '</table>
<div><input type="submit" value="essayer" /></div>
</form>';
}
}
else
{
echo '</table>
<p>Vous avez perdu: la bonne combinaison était: '.$_SESSION['bonne_rep'].'</p>
<div><a href="'.$fichier.'">Voulez vous recommencer?</a></div>';
}

echo '
</body>
</html>';
}
elseif ($_GET['action'] == 'coup')
{
session_start ();
$nb_vache = 0;
$nb_taureau = 0;
$test = $_SESSION['nb_pions'];
if ($test != $_SESSION['nb_pions']) header ('location:'.$fichier.'?erreur=1');
foreach ($_POST['rep'] as $value)
{
if (!preg_match_all('/:digit:/', $value, $test) != strlen ($value)) header ('location:'.$fichier.'?erreur=type');
}
$reponse = implode ($_POST['rep']);
$compare = $_SESSION['bonne_rep'];
$taille = strlen ($_SESSION['bonne_rep']);
$nb_vache = 0;
for ($x = 0; isset($reponse[$x]); $x++)
{
if ($reponse[$x] == $compare[$x])
{
$nb_vache++;
$reponse[$x] = '';
$compare[$x] = '';
}
}
$nombre = 0;
for ($a = 0; isset($reponse[$a]); $a++)
{
$kim = strpos ($compare, $reponse[$a]);
if ($kim != 0)
{
$nombre++;
$compare[$kim] = '';
}
}
$nb_taureau = &$nombre;
$nb_restant = $taille - $nb_taureau - $nb_vache;
$_SESSION['nb_restant'] = $nb_restant;
$_SESSION['reponse'][$_SESSION['numero_du_coup']] = implode (' - ', $_POST['rep']);
$_SESSION['coup'][$_SESSION['numero_du_coup']] = 'Vous avez '.$nb_vache.' '.$vache.' et '.$nb_taureau.' '.$taureau.' et '.$nb_restant.' pions mal plaçés';
$_SESSION['numero_du_coup']++;
header ('location:'.$fichier.'?action=afficher');
}
elseif ($_GET['action'] == 'css')
{
echo 'body {background-color:'.$fond.'}';
}

}
else
{
echo '<!DOCTYPE HTML PUBLIC \'-//W3C//DTD HTML 4.01 Transitional//EN\' \'http://www.w3.org/TR/html4/loose.dtd\'>
<html>
<head>
<title>', $titre, '</title>
<style>'.$style.'</style>
</head>
<body>
<form action="'.$fichier.'?action=depart" method="post">
<table>
<tr>
<td>Nombre de coups autorisés <input type="text" name="nb_coups" value="5" /></td>
<td>Nombre de pions <input type="text" name="nb_pions" value="5" /></td>
</tr>
</table>
<input type="submit" value="commencer" />
</form>
</body>
</html>';
}
//fin de création : mardi 27 mars 2007 a 20:06
?>



tu peux paramétrer pas mal de truc dans l'en-tête, notamment les couleurs / pions utilisé

il n'est pas fini, bien sur ^^.

je ne sais pas si il plante, mais il ne m'a pas semblé :D

amicalement

bubuche1987
Précédentnatasha
mars 07
natasha
mars 07
Suivant
REPONSES
bubuche87
mars 07
natasha
mars 07
natasha
mars 07
lirey83
mars 07
natasha
mars 07
bubuche87
mars 07
natasha
mars 07
princesse
mars 07
lirey83
mars 07
natasha
mars 07
Version Web
Réalisé par RedShift
no save