Un juego creado en php1. Un juego creado en PHP, espero que les guste (NO ES MIO).
config.ini.php
dijo:
<?
$info['host']='localhost';
$info['user']='root';
$info['pass']='';
$info['bd']='bd';
$info['table']='preguntas';
$info['table2']='user';
$info['link_preg']='preg.php';
//////////////////////////////
$ad[]="pato12"; // Para agregar pron: $ad[]="usuario";
?>
inst.php
dijo:
<style type="text/css">
<!--
body {
background-color: #F0F0F0;
}
a:link {
color: #000000;
}
a:visited {
color: #000000;
}
a:hover {
color: #333333;
}
a:active {
color: #FF0000;
}
-->
</style>
<table width="209" border="2" align="center" cellpadding="2" cellspacing="1" bordercolor="#000000"
bgcolor="#FFFFFF">
<?php
@session_start();
include('config.ini.php');
foreach($ad as $adm){
if($_SESSION['login'] != $adm) exit();
}
if($_POST){
/////////////////////////////////////////////
$conn=mysql_connect ($info['host'],$info['user'],$info['pass'])or die("Error3:<br>".mysql_error());
mysql_select_db($info['bd'],$conn)or die("Error1:<br>".mysql_error());
/////////////////////////////////////////////
echo '<tr><td width="1329" height="2">';
$p=$_POST['p'];
$r=$_POST['r'];
$pma=$_POST['p+'];
$pme=$_POST['p-'];
if(empty($p) || empty($r) || empty($pma) || empty($pme)){
echo "Un campo esta vacio.";
}
else
{
$insertSQL="INSERT INTO ".$info['table']." (pregunta,respuesta,puntosmas,puntosmenos) VALUES
('$p','$r','$pma','$pme')";
$insert=mysql_query($insertSQL) or die(mysql_error());
if($insert){
echo "pregunta colocada correctamente.";
2. }
else
{
echo "Errpr ".mysql_error();
}
echo '</td></tr>';
}
}
?><tr><td width="1329" height="2">
<form name="form1" method="post" action="">
Pregunta:<br>
<label for="textfield"></label>
<input name="p" type="text" id="p" value="<?=$p?>">
<br>
Respuesta:<br>
<input name="r" type="text" id="r" value="<?=$r?>">
<br>
Punto si asierta: <br>
<input name="p+" type="text" id="p+" value="<?=$pma?>" />
<br>
Puntos que se le restaran si no asierta: <br>
<input name="p-" type="text" id="p-" value="">
<br>
<input type="submit" name="Submit" value="Agregar">
</form></td></tr>
<tr>
<td height="2"><a href="logoup.php">Salir</a> | <a href="perfil.php">Perfil</a></td>
</tr>
</table>
log.php
dijo:
<style type="text/css">
<!--
body {
background-color: #F0F0F0;
}
a:link {
color: #000000;
}
a:visited {
color: #000000;
}
a:hover {
color: #333333;
}
a:active {
color: #FF0000;
}
-->
</style>
<table width="209" border="2" align="center" cellpadding="2" cellspacing="1" bordercolor="#000000"
bgcolor="#FFFFFF">
<?php
echo '<tr><td width="1329" height="2">';
@session_start();
session_register();
include('config.ini.php');
/////////////////////////////////////////////
$conn=mysql_connect ($info['host'],$info['user'],$info['pass'])or die("Error3:<br>".mysql_error());
mysql_select_db($info['bd'],$conn)or die("Error1:<br>".mysql_error());
/////////////////////////////////////////////
if ($_POST) {
//Comprobacion del envio del nombre de usuario y password
$username=$_POST['nick'];
$password=$_POST['clave'];
if($username==NULL){
echo "Nick vacio";
}elseif ($password==NULL) {
echo "Clave vacia.";
}else{
6. $row = mysql_fetch_array($query);
$_SESSION['login']=$row['nick'];
$_SESSION['id']=$row['nivel'];
echo "<script>location='preg.php'</script>";
}
}
echo '</td></tr>';
}
?>
<?
if(!isset($_SESSION['login'])){
?>
<tr><td width="197" height="2" align="center">
<form name="form2" method="post" action="">Nick:<br>
<input name="nick" type="text" id="nick" value="<?=$_POST['nick'];?>">
<br>Clave:<br>
<input name="clave" type="password" id="clave"><br>
<input type="submit" name="Submit" value="-- Entrar --">
</form></td></tr>
<tr>
<td height="2" align="center"><a href="reg.php">REGISTRAR</a></td>
</tr>
<?
}
else
{
echo "Logeado";
}
?>
</table>
logoup.php
dijo:
<?
session_start();
session_unset();
session_destroy();
8. ?>
perfil.php
Citar
<style type="text/css">
<!--
body {
background-color: #F0F0F0;
}
a:link {
color: #000000;
}
a:visited {
color: #000000;
}
a:hover {
color: #333333;
}
a:active {
color: #FF0000;
}
-->
</style>
<table width="909" border="2" align="center" cellpadding="2" cellspacing="1" bordercolor="#000000"
bgcolor="#FFFFFF">
<?php
@session_start();
if(!isset($_SESSION['login']))exit('Mal');
include('config.ini.php');
/////////////////////////////////////////////
mysql_connect ($info['host'],$info['user'],$info['pass'])or die("Error:<br>".mysql_error());
mysql_select_db($info['bd'])or die("Error:<br>".mysql_error());
/////////////////////////////////////////////
10. die(mysql_error());
$row = mysql_fetch_array($query2);
?>
<tr>
<td height="2"><strong>Nick:</strong>
<?=$row['nick'];?>
<br>
<strong>Puntos:</strong>
<?=$row['puntos'];?>
<br>
<strong>Nivel:</strong>
<?=$row['nivel'];?>
<br>
<strong>Email:</strong>
<?=$row['email'];?></td>
</tr>
<tr>
<td height="2"><a href="preg.php"><< Atras </a></td>
</tr>
</table>
preg.php
dijo:
<style type="text/css">
<!--
body {
background-color: #F0F0F0;
}
a:link {
color: #000000;
}
a:visited {
color: #000000;
}
a:hover {
color: #333333;
}
a:active {
color: #FF0000;
}
-->
</style>
<table width="909" border="2" align="center" cellpadding="2" cellspacing="1" bordercolor="#000000"
bgcolor="#FFFFFF">
<?php
@session_start();
if(!isset($_SESSION['login']))exit('Mal');
include('config.ini.php');
/////////////////////////////////////////////
mysql_connect ($info['host'],$info['user'],$info['pass'])or die("Error:<br>".mysql_error());
mysql_select_db($info['bd'])or die("Error:<br>".mysql_error());
/////////////////////////////////////////////
echo '<tr><td width="1329" height="2">';
14. die(mysql_error());
$row = mysql_fetch_array($query2);
$aas = mysql_db_query($info['bd'],"SELECT count(*) FROM ".$info['table']) or die(mysql_error());
$cont=mysql_fetch_row($aas);
echo $data['pregunta'];
echo '</td></tr>';
?>
<tr>
<td height="2">
<?php
if($row['nivel'] > $cont[0]){
echo "Fin del juego";
}else{
?>
<form name="form1" method="post" action="RES.php">
<label for="textfield"></label>
<input type="text" name="res" id="res">
<label for="Submit"></label>
<input type="submit" name="Submit" value="Contestar" id="Submit">
</form><? }?></td>
</tr>
<tr>
<td height="1">Puntos: <?=$row['puntos']." | Nivel: ".$row['nivel'];?> | <a href="logoup.php">Salir</a> | <a
href="perfil.php">Perfil</a> | Total de niveles: <?=$cont[0];?><?php
foreach($ad as $adm){
if($_SESSION['login'] == $adm) echo ' | <a href="inst.php">Administrar</a>';
}
?> </td> </tr>
</table>
reg.php
Citar
<style type="text/css">
<!--
body {
background-color: #F0F0F0;
}
a:link {
color: #000000;
}
a:visited {
color: #000000;
}
a:hover {
color: #333333;
}
a:active {
color: #FF0000;
}
-->
</style>
<table width="273" border="2" align="center" cellpadding="2" cellspacing="1" bordercolor="#000000"
bgcolor="#FFFFFF">
<?php
// Preguntaremos si se han enviado ya las variables necesarias
if ($_POST) {
include('config.ini.php');
echo '<tr><td width="1329" height="2">';
/////////////////////////////////////////////
$conn=mysql_connect ($info['host'],$info['user'],$info['pass'])or die("Error3:<br>".mysql_error());
mysql_select_db($info['bd'],$conn)or die("Error1:<br>".mysql_error());
/////////////////////////////////////////////
$username = $_POST["nick"];
$password = $_POST["clave"];
$cpassword = $_POST["cpclave"];
$email = $_POST["email"];
// Hay campos en blanco
if($username==NULL|$password==NULL|$cpassword==NULL|$email==NULL) {
echo "Un campo está vacio.";
}else{
// ¿Coinciden las contraseñas?
if($password!=$cpassword) {
echo "Las clave no coinciden";
19. $email_exist = mysql_num_rows($checkemail);
if ($email_exist>0|$username_exist>0) {
echo "EL nombre de usuario o la cuenta de correo estan ya en uso";
}else{
//Todo parece correcto procedemos con la inserccion
$query = "INSERT INTO ".$info['table2']." (nick, clave, email, nivel, puntos) VALUES('$username','$password','$email',
'1','0')";
mysql_query($query) or die(mysql_error());
echo "El usuario $username ha sido registrado de manera satisfactoria.";
}
}
}
echo '</td></tr>';
}
?>
<tr><td width="1329" height="2">
<form name="form1" method="post" action="">
Nick<br>
<INPUT maxLength="25" size="15" name="nick"><br>
Clave:<br>
<INPUT type="password" maxLength="25" size="15" value="" name="clave"><br>
Repita la clave:<br>
<INPUT type="password" maxLength="25" size="15" value="" name="cpclave"><br>
Email:<br>
<INPUT maxLength="25" size="15" name="email"><br>
<INPUT name="submit" type="submit" value="Registro">
</form>
</td></tr>
<tr>
<td height="2"><a href="log.php">LOGIN</a></td>
</tr>
</table>
RES.php
Citar
<style type="text/css">
<!--
body {
background-color: #F0F0F0;
}
a:link {
color: #000000;
}
a:visited {
color: #000000;
}
a:hover {
color: #333333;
}
a:active {
color: #FF0000;
}
-->
</style>
<table width="909" border="2" align="center" cellpadding="2" cellspacing="1" bordercolor="#000000"
bgcolor="#FFFFFF">
<?php
@session_start();
if(!isset($_SESSION['login']))exit();
include('config.ini.php');
if(!$_POST) exit();
echo '<tr><td width="1329" height="2">';
/////////////////////////////////////////////
$conn=mysql_connect ($info['host'],$info['user'],$info['pass'])or die("Error3:<br>".mysql_error());
mysql_select_db($info['bd'],$conn)or die("Error1:<br>".mysql_error());
/////////////////////////////////////////////
$res=$_POST['res'];
if($res == NULL){
echo "La respuesta esta vacia.";
echo "<br><a href='".$info['link_preg']."'>.Regresar.</a>";
}
else
{
23. die(mysql_error());
$data2 = mysql_fetch_array($query2);
if($data['respuesta'] == $res){
echo "Bien, ganaste ".$data['puntosmas'];
$puntos_total=$data['puntosmas'] + $data2['puntos'];
$sql = "UPDATE ".$info['table2']." SET puntos='$puntos_total' Where nick = '".$_SESSION['login']."'";
$result2 = mysql_query($sql);
$id2=$_SESSION['id']+1;
$_SESSION['id']=$id2;
$sql = "UPDATE ".$info['table2']." SET nivel='$id2' Where nick = '".$_SESSION['login']."'";
$result2 = mysql_query($sql);
echo "<br><a href='".$info['link_preg']."'>.Proxima pregunta.</a>";
}
else
{
echo "Mal,perdiste ".$data['puntosmenos']." por equivocarte";
$puntos_total=$data2['puntos'] - $data['puntosmenos'];
$sql = "UPDATE ".$info['table2']." SET puntos='$puntos_total' Where nick = '".$_SESSION['login']."'";
$result2 = mysql_query($sql);
echo "<br><a href='".$info['link_preg']."'>.Regresar.</a>";
}
echo '</td></tr>';
}
25. die(mysql_error());
$row = mysql_fetch_array($query2);
$aas = mysql_db_query($info['bd'],"SELECT count(*) FROM ".$info['table']) or die(mysql_error());
$cont=mysql_fetch_row($aas);
?>
<tr>
<td height="2">Puntos: <?=$row['puntos']." | Nivel: ".$row['nivel'];?> | <a href="logoup.php">Salir</a> | <a
href="perfil.php">Perfil</a> | Total de niveles: <?=$cont[0];?><?php
foreach($ad as $adm){
if($_SESSION['login'] == $adm) echo ' | <a href="inst.php">Administrar</a>';
}
?> </td> </tr>
</table>
ver_user.php
Citar
<style type="text/css">
<!--
body {
background-color: #F0F0F0;
}
a:link {
color: #000000;
}
a:visited {
color: #000000;
}
a:hover {
color: #333333;
}
a:active {
color: #FF0000;
}
-->
</style>
<table width="909" border="2" align="center" cellpadding="2" cellspacing="1" bordercolor="#000000"
bgcolor="#FFFFFF">
<?php
@session_start();
if(!$_GET) exit('Error');
if(!isset($_SESSION['login']))exit();
include('config.ini.php');
echo '<tr><td width="1329" height="2">';
/////////////////////////////////////////////
$conn=mysql_connect ($info['host'],$info['user'],$info['pass'])or die("Error3:<br>".mysql_error());
mysql_select_db($info['bd'],$conn)or die("Error1:<br>".mysql_error());
/////////////////////////////////////////////
$user=$_GET['user'];
29. $row = mysql_fetch_array($query2);
?>
<tr>
<td height="2"><strong>Nick:</strong>
<?=$row['nick'];?>
<br>
<strong>Puntos:</strong>
<?=$row['puntos'];?>
<br>
<strong>Nivel:</strong>
<?=$row['nivel'];?></td>
</tr>
<tr>
<td height="2"><a href="preg.php"><< Atras </a></td>
</tr>
</table>
<?php
}
?>
install.php
dijo:
<?
if($_POST){
// Configura los datos de tu cuenta
$dbhost=$_POST['ser'];
$dbusername=$_POST['us'];
$dbuserpass=$_POST['pass'];
$dbname=$_POST['bd'];
// Conexión a la base de datos
mysql_connect ($dbhost, $dbusername, $dbuserpass);
// Seleccion de la base de datos
mysql_select_db($dbname) or die('Cannot select database');
// Creacion de la tabla (puedes elegir otros nombres para los campos)
$query = 'CREATE TABLE `preguntas` (
`id` int(4) NOT NULL auto_increment,
`pregunta` varchar(300) NOT NULL,
`respuesta` varchar(30) NOT NULL,
`puntosmas` varchar(30) NOT NULL,
`puntosmenos` varchar(30) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=4 ;';
$result = @mysql_query($query);
if($result){
echo "Tabal de preguntas creada correctamente.";
}else{
echo "Error al crear tabla de preguntas.";
}
$query2='CREATE TABLE `user` (
`id` int(4) NOT NULL auto_increment,
`nick` varchar(30) NOT NULL,
`clave` varchar(30) NOT NULL,
`email` varchar(30) NOT NULL,
`site` varchar(30) NOT NULL,
`puntos` varchar(30) NOT NULL,
`nivel` int(4) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=5 ;';
$result2 = @mysql_query($query2);
if($result2){
echo "<br>Tabal de user creada correctamente.";
}else{
echo "<br>Error al crear tabla de user.";
}
}
?><br>
<form name="form1" method="post" action="">
Servidor:<br>
<input name="ser" type="text" id="ser" value="localhost">
<br>
Usuario:<br>
<input name="us" type="text" id="us">