Ver Mensaje Individual
  #1 (permalink)  
Antiguo 15/04/2008, 14:04
Avatar de pato12
pato12
 
Fecha de Ingreso: septiembre-2007
Ubicación: Salta
Mensajes: 1.620
Antigüedad: 17 años
Puntos: 101
APORTE: Crear un juego en php

Hola,
Cree un juego de preguntas y respuestas en php.
El juego esta compuesto de:
  • config.ini.php
  • inst.php
  • log.php
  • logoup.php
  • perfil.php
  • preg.php
  • reg.php
  • RES.php
  • ver_user.php
  • install.php
En el archivo config.ini.php:
Código PHP:
<?
$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
Código PHP:
<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.";
}
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
Código PHP:
<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{ 
$query mysql_query("SELECT * FROM ".$info['table2']." WHERE nick = '$username'") or die(mysql_error()); 
$data mysql_fetch_array($query); 
if(
$data['nick'] != $username) { 
echo 
"Nick mal."
}elseif(
$data['clave'] != $password){
echo 
"Clave mal.";
}else{ 
$query mysql_query("SELECT * FROM ".$info['table2']." WHERE nick = '$username'") or die(mysql_error()); 
$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
Código PHP:
<?   
session_start
();
session_unset();   
session_destroy();   
header("location: log.php");   
?>
perfil.php
Código PHP:
<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()); 
/////////////////////////////////////////////
$query2 mysql_query("SELECT * FROM ".$info['table2']." WHERE nick = '".$_SESSION['login']."'") or 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">&lt;&lt; Atras </a></td>
  </tr>
</table>
preg.php
Código PHP:
<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">';
$query mysql_query("SELECT * FROM ".$info['table']." WHERE id = '".$_SESSION['id']."'") or die(mysql_error()); 
$data mysql_fetch_array($query);

$query2 mysql_query("SELECT * FROM ".$info['table2']." WHERE nick = '".$_SESSION['login']."'") or 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>
Continua-->>>>
__________________
Half Music - www.halfmusic.com