Foros del Web » Programando para Internet » PHP »

Problema con juego php

Estas en el tema de Problema con juego php en el foro de PHP en Foros del Web. Tengo un juego en donde se da un numero al azar y debe ser encontrado por la pagina juegos/boletos/index.php cuando es encontrado se envia via ...
  #1 (permalink)  
Antiguo 02/03/2009, 11:55
 
Fecha de Ingreso: julio-2006
Mensajes: 254
Antigüedad: 17 años, 10 meses
Puntos: 0
Problema con juego php

Tengo un juego en donde se da un numero al azar y debe ser encontrado por la pagina juegos/boletos/index.php cuando es encontrado se envia via formulario. En index.php se crea si no existe una session llamada jugada_b y en index2.php se procesa si el numero seleccionado es igual al dado al azar, y si es asi, se ejecutan unas acciones.
Aqui pongo el codigo y mas abajo el error:
INDEX.php
Código PHP:

<?php

//CONEXION
 
?>
        
<?php


if (!function_exists("GetSQLValueString")) {
function 
GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
{
  if (
PHP_VERSION 6) {
    
$theValue get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  
$theValue function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch (
$theType) {
    case 
"text":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;    
    case 
"long":
    case 
"int":
      
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case 
"double":
      
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case 
"date":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;
    case 
"defined":
      
$theValue = ($theValue != "") ? $theDefinedValue $theNotDefinedValue;
      break;
  }
  return 
$theValue;
}
}

mysql_select_db($database_Noone$Noone);
$query_bote "SELECT * FROM pozo WHERE pozo = 'boletos'";
$bote mysql_query($query_bote$Noone) or die(mysql_error());
$row_bote mysql_fetch_assoc($bote);
$totalRows_bote mysql_num_rows($bote);mysql_select_db($database_Noone$Noone);
$query_bote "SELECT * FROM pozo WHERE pozo = 'boletos'";
$bote mysql_query($query_bote$Noone) or die(mysql_error());
$row_bote mysql_fetch_assoc($bote);
$totalRows_bote mysql_num_rows($bote);

$colname_banco "-1";
if (isset(
$_SESSION['MM_Username'])) {
  
$colname_banco $_SESSION['MM_Username'];
}
mysql_select_db($database_Noone$Noone);
$query_banco sprintf("SELECT * FROM banco WHERE usuario = %s"GetSQLValueString($colname_banco"text"));
$banco mysql_query($query_banco$Noone) or die(mysql_error());
$row_banco mysql_fetch_assoc($banco);
$totalRows_banco mysql_num_rows($banco);
 
?>
        
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

</head>

<body>
<div align="left" class="Estilo1 Estilo3">Encuentra el boleto!</div>
<p align="center" class="Estilo2"><em>A Nooni se le cayó el boleto de su tren! El esta buscando por toda la estacion, pero hay muchos boletos! ¿Lo ayudas a encontrar el suyo?</em></p>
<p align="center" class="Estilo2">¿Podrás encontrar el boleto que le corresponde a Nooni? Su boleto era el numero <b><u><? $azar rand(1,10); echo"$azar";  ?></u></b></p>
<p align="center" class="Estilo2"><strong><span class="important">Debes encontrar el </span><span class="important"> boleto con la identificacion </span></strong><b><u><b><u>
  <? echo "$azar" ;  ?></u></b></u></b><br />
<span class="cxhiqi"><span class="cxhiqi">(sean</span> los que sean)</span></p>
<p align="center" class="Estilo2"><em><strong>A veces, puede que no puedas ayudar a Nooni y no pueda tomarse el tren.</strong></em><br />
¡Agarraste 100 boletos del suelo! ¿Podrás encontrar a el  correcto?<br />
<a href="/juegos/boleto/index.php">ACTUALIZAR </a><br />
</p>
<p align="center" class="Estilo2"><? if($row_banco['nooney'] < 150)
{
    echo 
"No tienes suficientes nooney";
}
else
{
    
        
/* Se descuentan 150 Nooney */
$user $_SESSION['MM_Username'];
    
$precio 150;
    
$restar $row_banco['nooney'] - $precio;
    
$hacer mysql_query("UPDATE banco SET nooney = $restar WHERE usuario = '$user'") or die(mysql_error());
    echo 
"¡Se te descontaron 150 Nooney!" ;

    
/* Agregar al pozo */
$pozo $row_bote['nooney'];
$sumar $pozo $precio;
$sumari mysql_query("UPDATE pozo SET nooney = $sumar WHERE pozo = 'boletos'") or die(mysql_error());
echo 
" ¡Y se agregaron al pozo! ";
if(isset(
$_SESSION['jugada_b']))
{
    echo 
" ¡Juega! ";
    echo 
" $_SESSION[jugada_b] ";
}
else
{
    
$_SESSION['jugada_b'] = 0;
}



}
 
?><br />
  <br />
<em><strong>Bote actual:</strong></em><strong></strong> <?php echo $row_bote['nooney']; ?> Nooney<br />
<br />
Selecciona 4 veces seguidas el boleto correcto y ganaras el pozo<br />
</p><?
//FORMULARIO PARA ELEGIR EL MISMO NUMERO QUE EL DADO AL AZAR
?>
INDEX2.PHP
Código PHP:


<?php
//CONEXION
?>
<?php
if (!function_exists("GetSQLValueString")) {
function 
GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
{
  if (
PHP_VERSION 6) {
    
$theValue get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  
$theValue function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch (
$theType) {
    case 
"text":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;    
    case 
"long":
    case 
"int":
      
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case 
"double":
      
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case 
"date":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;
    case 
"defined":
      
$theValue = ($theValue != "") ? $theDefinedValue $theNotDefinedValue;
      break;
  }
  return 
$theValue;
}
}

$colname_datos "-1";
if (isset(
$_SESSION['MM_Username'])) {
  
$colname_datos $_SESSION['MM_Username'];
}
mysql_select_db($database_Noone$Noone);
$query_datos sprintf("SELECT juego, usuario, data1 FROM juegos WHERE usuario = %s"GetSQLValueString($colname_datos"text"));
$datos mysql_query($query_datos$Noone) or die(mysql_error());
$row_datos mysql_fetch_assoc($datos);
$totalRows_datos mysql_num_rows($datos);

$colname_Recordset1 "-1";
if (isset(
$_SESSION['MM_Username'])) {
  
$colname_Recordset1 $_SESSION['MM_Username'];
}
mysql_select_db($database_Noone$Noone);
$query_Recordset1 sprintf("SELECT * FROM banco WHERE usuario = %s"GetSQLValueString($colname_Recordset1"text"));
$Recordset1 mysql_query($query_Recordset1$Noone) or die(mysql_error());
$row_Recordset1 mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 mysql_num_rows($Recordset1);

mysql_select_db($database_Noone$Noone);
$query_Recordset2 "SELECT * FROM pozo WHERE pozo = 'boletos'";
$Recordset2 mysql_query($query_Recordset2$Noone) or die(mysql_error());
$row_Recordset2 mysql_fetch_assoc($Recordset2);
$totalRows_Recordset2 mysql_num_rows($Recordset2);


$id $_POST['azar']; 
 
$elegido $_POST['elegido'];  ?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento sin t&iacute;tulo</title>

</head>

<body>
<div align="left" class="Estilo1 Estilo3">Jugando a ¡Encuentra el boleto!</div>
<p align="center" class="Estilo2"><em>El numero de boleto era <? echo " $id " ?> </em></p>
<p align="center" class="Estilo2"><span class="contenido">Tu has marcado el boleto numero: </span><br />
<? echo " $elegido $_SESSION[jugada_b] "?>
</p>
<p align="center" class="Estilo2"><?
//VERIFICO SE CONCUERDAN
if($id == $elegido)
//SI CONCUERDAN PASA ESTO
{
    echo 
" Los numeros concuerdan, has ganado ";
//SI SESSION ESTA EN 0
if(isset($_SESSION[jugada_b]))
                   {
                       if(
$_SESSION[jugada_b] == 0)
                       {
                           echo 
" Esta es tu primer jugada acertada ";
                           
$_SESSION[jugada_b] = 1;
                       }
                   }
//SI ESTA EN 1
if(isset($_SESSION[jugada_b]))
                   {
                       if(
$_SESSION[jugada_b] == 1)
                       {
                           echo 
" Esta es tu segunda jugada acertada ";
                           
$_SESSION[jugada_b] = 2;
                       }
                   }
//SI ESTA EN 2
if(isset($_SESSION[jugada_b]))
                   {
                       if(
$_SESSION[jugada_b] == 2)
                       {
                           echo 
" Esta es tu tercera jugada acertada ";
                           
$_SESSION[jugada_b] = 3;
                       }
                   }
//SI ESTA EN 3
if(isset($_SESSION[jugada_b]))
                   {
                       if(
$_SESSION[jugada_b] == 3)
                       {
                           echo 
" HAS GANADO EL BOTE!!!!!!!!!!!!!! ";
                           
                           
//DAR BOTE
                           
$bote $row_Recordset2['nooney'];
                           
$atual $row_Recordset1['nooney'];
                           
$suma $atual $bote;
                           
$upd mysql_query("UPDATE banco SET nooney = $suma WHERE usuario = $_SESSION[MM_Username] ");
                           
$_SESSION[jugada_b] = 0;
                       }
                   }
                   
                   
//SI NO EXISTE SSION
                   
if(isset($_SESSION[jugada_b]))
                   {
                      echo 
"Gracias por jugar" ;
                      }
                      else
                      {
                          echo 
" Ocurrio un error ";
                      }
//SINO ESTO
}
else
{
    echo 
" Los numeros que has elegido no concuerdan... ";
}

echo 
" $_SESSION[jugada_b]";



















?>
<p align="center" class="Estilo2">&nbsp; </p>
<p align="center" class="Estilo2"><a href="/juegos/boleto/index.php">Volver a jugar</a></p>
</body>
</html>
<?php
mysql_free_result
($datos);

mysql_free_result($Recordset1);

mysql_free_result($Recordset2);
?>
El error sucede en index2.php
cuando me imprime esto:
Cita:
Los numeros concuerdan, has ganado Esta es tu primer jugada acertada Esta es tu segunda jugada acertada Esta es tu tercera jugada acertada HAS GANADO EL BOTE!!!!!!!!!!!!!! Gracias por jugar 0
Osea, me imprime TODO , y luego la variable vuelve a 0.
¿Alguien sabe porque me sucede esto?
  #2 (permalink)  
Antiguo 02/03/2009, 12:21
 
Fecha de Ingreso: julio-2006
Mensajes: 254
Antigüedad: 17 años, 10 meses
Puntos: 0
Respuesta: Problema con juego php

Solucionado
  #3 (permalink)  
Antiguo 02/03/2009, 12:24
okram
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: Problema con juego php

Bueno, no sé que esperas obtener, si cada vez que una condición se cumple cambias el valor de la variable de sesión y haces que la siguiente tambiñen se cumpla. Al final, pones la variable a 0.

En tu script dice que haga eso, por lo tanto no veo dónde pueda haber un error.

Código php:
Ver original
  1. if(isset($_SESSION[jugada_b]))
  2.                    {
  3.                        if($_SESSION[jugada_b] == 0)
  4.                        {
  5.                            $_SESSION[jugada_b] = 1;
  6.                        }
  7.                    }
  8. if(isset($_SESSION[jugada_b]))
  9.                    {
  10.                        if($_SESSION[jugada_b] == 1)
  11.                        {
  12.                            $_SESSION[jugada_b] = 2;
  13.                        }
  14.                    }
  15. if(isset($_SESSION[jugada_b]))
  16.                    {
  17.                        if($_SESSION[jugada_b] == 2)
  18.                        {
  19.                            $_SESSION[jugada_b] = 3;
  20.                        }
  21.                    }
  22. if(isset($_SESSION[jugada_b]))
  23.                    {
  24.                        if($_SESSION[jugada_b] == 3)
  25.                        {
  26.                            $_SESSION[jugada_b] = 0;
  27.                        }
  28.                    }
  29.                    
  30. }
Entiendes lo que pasa, no? Si var es igual a 0, entonces la cambio a 1. Sigue el proceso. Si var es igual a 1, la cambio a 2, así con 3. Si var es igual 3, la cambio a 0. No habrás querido usar tal vez if... elseif... elseif... else.. ?

  #4 (permalink)  
Antiguo 02/03/2009, 12:50
 
Fecha de Ingreso: julio-2006
Mensajes: 254
Antigüedad: 17 años, 10 meses
Puntos: 0
Respuesta: Problema con juego php

Sí, ya entendi y lo solucione, gracias.
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Tema Cerrado




La zona horaria es GMT -6. Ahora son las 22:26.