Skip to content

Instantly share code, notes, and snippets.

@ctroncoso
Created December 14, 2010 04:02
Show Gist options
  • Save ctroncoso/739990 to your computer and use it in GitHub Desktop.
Save ctroncoso/739990 to your computer and use it in GitHub Desktop.
document.onkeypress=Keypress
function Keypress(e){
var KeyID = (window.event) ? event.keyCode : e.keyCode;
switch(KeyID)
{
case(109):
subeEbUno();
break;
case(110):
dispara();
break;
}
}
String.prototype.trim = function() {
return this.replace(/^\s+|\s+$/g,"");
}
function clsNumeros(pasoTiempo,pasoPuntaje,semilla,balaInicial,numerossTope)
{
this.statusContinue=1;
this.largoString = 0 ;
this.arreglo=new Array();
this.deltaTiempo=pasoTiempo;
this.puntaje=pasoPuntaje;
this.numeroRnd=semilla;
this.disparador=balaInicial;
this.maxNumeros=numerossTope;
}
clsNumeros.prototype.genRnd=function()
{
this.numeroRnd = Math.random()*9;
this.numeroRnd = Math.round(this.numeroRnd);
}
clsNumeros.prototype.addNumeros=function(){
this.arreglo.push(this.numeroRnd);
}
clsNumeros.prototype.addPuntaje=function(addPuntos){
this.puntaje+=addPuntos;
}
clsNumeros.prototype.increTime=function(dTiempo){
this.deltaTiempo+=dTiempo;
}
clsNumeros.prototype.decreTime=function(dTiempo){
this.deltaTiempo-=dTiempo;
}
clsNumeros.prototype.muestraArr=function(){
var mensaje = this.arreglo.join("");
mensaje = mensaje.trim();
this.largoString=mensaje.length;
$('#aquiVaTexto').replaceWith('<p id="aquiVaTexto">' + mensaje + '</p>');
//$('#statusLargo').replaceWith('<h2 id="statusLargo">' + this.largoString + '</h2>');
}
clsNumeros.prototype.sacaNumero=function(){
for (var i=0;i<this.arreglo.length;i++)
{
if (this.arreglo[i] == this.disparador)
{
delete this.arreglo[i];
this.puntaje++;
break;
}
}
}
clsNumeros.prototype.incrementaDisparador=function()
{
if (this.statusContinue==0) break;
if (this.disparador==9)
{
this.disparador=0;
}
else
{
this.disparador++;
}
}
clsNumeros.prototype.muestraBala =function()
{
$('#Bala').replaceWith('<h3 id="Bala">' + this.disparador + '</h3>');
}
clsNumeros.prototype.muestraPuntaje=function()
{
$('#Puntaje').replaceWith('<h3 id="Puntaje">' + this.puntaje + '</h3>');
}
clsNumeros.prototype.elJuegoTermino=function()
{
if (this.largoString>=this.maxNumeros)
{
var mensajeFin="Lo Siento perdiste :-( ";
$('#mensaje').replaceWith('<h3 id="mensaje">' + mensajeFin + '</h3>');
this.statusContinue=0;
}
}
var ObjJuego = new clsNumeros(1000,0,0,0,10);
function colocaNumero()
{
if (ObjJuego.statusContinue==1){
ObjJuego.genRnd();
ObjJuego.addNumeros();
ObjJuego.muestraArr();
ObjJuego.elJuegoTermino();
}
}
function escribe(paramPaso)
{
$("#paso").append(paramPaso + ", ")
}
function generaNumeros(cantidad)
{
var i=0;
for (var i=0;i<1000;i++)
{
setTimeout('colocaNumero()',1000*i)
}
}
function subeEbUno()
{
ObjJuego.incrementaDisparador();
ObjJuego.muestraBala();
}
function dispara()
{
if (this.statusContinue==0) break;
ObjJuego.sacaNumero();
ObjJuego.muestraPuntaje();
}
function numGenera()
{
Concurrent.Thread.create(generaNumeros,100);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment