Estoy haciendo el juego tipico de la culebra, que va creciendo a me medida que come cuadrados. En verdad no es totalmente mio, porque el "nucleo" del juego lo encontre en internet, yo solo estoy agregandole más cosas. Por ejemplo le puse gráficos y la opción de elegir la velocidad.
Ahora quiero hacer que despues de perder ( la funcion "fin()" ) se habra una nueva ventana que va a tener cierta información. Busque en internet y me salio que esto podría servir:
window.open("pagina.htm" , "ventana1" , "scrollbars=NO");
En otras paginas me funciona sin problemas, pero cuando lo quiero incluir al juego, en la función "fin()", no sirve. Intenté ponerlo en otras partes pero tampoco funcionó.
Que podría ser?
De paso podrían hacer algunos comentarios del codigo por favor.
De ante mano muchas gracias
Código:
<html>
<head>
<title>Culebra</title>
<style type = text/css>
.cul {position:absolute;top:40;left:40;width:20;height:20;
background-image: url(culd.gif) }
.tab1 {position:absolute;top:20;left:20;width:50;height:50}
.tabla {position:absolute;top:19;left:19;}
</style>
<script>
window.document.onkeydown = tecla;
var posy = 0;
var y = 40;
var posx = 0;
var randomx;
var randomy;
var x = 40;
var cola = 3;
var v = 2;
var divi = document.all.tags('div');
var tempo;
var Tenter = 0;
var randomcom;
var tiempo;
var tempos;
var tempos2;
//FUNCION MOV
function mov()
{
movCulebra();
document.all.div0.style.top = y = y + posy;
document.all.div0.style.left = x = x + posx;
if (y+'px' == divi[cola].style.top && x+'px' ==
divi[cola].style.left)
{
Random();
}
if (y < 0 || y/20 > 24)
{fin();
}
if (x/20 < 0 || x > 620)
{fin();
}
for (i=2;i<cola-1;i++)
{
if (y+'px' == divi[i].style.top && x+'px' ==
divi[i].style.left)
{fin();
}
}
}
// FUNCION TECLA: EVENT ONKEYDOWN
function tecla()
{ //alert(window.event.keyCode);
switch (window.event.keyCode)
{
case 13://ENTER
if (Tenter==0)
{
Random();
vel();
tempo = window.setInterval('mov()',tempos);
tiempo = window.setInterval('ptj()',tempos);
posx = 20;
posy = 0;
Tenter = 2;
g.value = "Continuar"
g.disabled=1;
h.disabled=0;
velocidad.f.disabled=1
}
else if (Tenter == 1)
{
tempo = window.setInterval('mov()',tempos);
tiempo = window.setInterval('ptj()',tempos);
Tenter = 2;
g.disabled=1;
h.disabled=0;
}
break;
case 37://FLECHA IZQUIERDA
if (posx ==0){
posy = 0;
posx = -20;
if (Tenter==2){
document.getElementById('div0').style.background='url(culi.gif)';
}
}
break;
case 38://FLECHA ARRIVA
if (posy ==0){
posy = -20;
posx = 0;
if (Tenter==2){
document.getElementById('div0').style.background='url(cula.gif)';
}
}
break;
case 39://FLECHA DERECHA
if (posx==0){
posy = 0;
posx = 20;
if (Tenter==2){
document.getElementById('div0').style.background='url(culd.gif)';
}
}
break;
case 40://FLECHA ABAJO
if (posy ==0){
posy = 20;
posx = 0;
if (Tenter==2){
document.getElementById('div0').style.background='url(culb.gif)';
}
}
break;
case 80://TECLA P PAUSA
window.clearInterval(tempo);
Tenter = 1;
g.disabled=0;
h.disabled=1;
break;
case 67://TECLA C CARGAR
Random();
break;
}
}
//FUNCION RANDOM--
function Random()
{
cola= cola+1;
randomy = (Math.round(Math.random()*24));
randomx = (Math.round(Math.random()*24));
document.all.area.insertAdjacentHTML("beforeEnd","<div
id=div"+cola+" style =
'position:absolute;width:20;height:20;top:"+randomy*20+";left:"+rand
omx*20+";background-image:url(col.gif)'></div>");
}
//FUNCION MOVCULEBRA--
function movCulebra()
{
v = v + 1;
if (v >= cola)
{
v = 2;
}
if(v<cola){
divi[v].style.left = x;
divi[v].style.top = y;
}
}
function fin()
{
alert('Perdiste!!');
window.clearInterval(tempo);
window.clearInterval(tiempo);
}
function ptj()
{
d.value=cola -4;
}
function vel()
{
var indice = document.velocidad.f.selectedIndex
tempos = document.velocidad.f.options[indice].value ;
e.value=tempos;
}
function inicio()
{
if (Tenter==0)
{
Random();
vel();
tempo = window.setInterval('mov()',tempos);
tiempo = window.setInterval('ptj()',tempos);
posx = 20;
posy = 0;
Tenter = 2;
g.value = "Continuar"
g.disabled=1;
h.disabled=0;
velocidad.f.disabled=1
}
else if (Tenter ==1)
{
tempo = window.setInterval('mov()',tempos);
tiempo = window.setInterval('ptj()',tempos);
Tenter = 2;
g.disabled=1;
h.disabled=0;
}
}
function pausa()
{
window.clearInterval(tempo);
Tenter = 1;
g.disabled=0;
h.disabled=1;
}
</script>
</head>
<body>
<table width="643" height="503" border="3" class="tabla">
<tr>
<td>
</td>
</tr>
</table>
<div id=area class="tab1">
<div id=div0 class=cul>
</div>
<div id=div1 style =
'position:absolute;width:20;height:20;top:"40";left:"20";background-
image:url(col.gif)'>
</div>
<div id=div2 style =
'position:absolute;width:20;height:20;top:"40";left:"0";background-i
mage:url(col.gif)'>
</div>
</div>
<p style=position:absolute;top:"20";left:"670">Puntaje:<br>
<input type="text" name="d" value="" disabled=1>
<hr style=position:absolute;top:"70";left:"670";width:320>
</p>
<p style=position:absolute;top:"80";left:"670">
<form name="velocidad">
Velocidad:<br>
<select name="f">
<option value="100">Lento</option>
<option value="50">Rapido</option>
</select>
</form>
<input type="text" name="e" value="" disabled=1>
<hr style=position:absolute;top:"170";left:"670";width:320>
<p/>
<p style=position:absolute;top:"180";left:"670">
<input value="Inicio" type="button" name="g" onclick="inicio()">
</p>
<p style=position:absolute;top:"205";left:"670">
<input value="Pausa" disabled="1" type="button" name="h"
onclick="pausa()">
</p>
</script>
</body>
</html>