script de Bingo incompleto
Publicado por jearj (9 intervenciones) el 31/03/2017 15:19:44
Hola a todos, soy nuevo en este foro y os traigo este script de bingo que me gustaría mejorar dotándolo de reproducción automática, control de velocidad y reproducción de audio que diga el numero que salga al pulsar el boton-sortear.
El caso es que yo estoy muy verde en el javascript y no se como hacerlo. ¿Alguien puede ayudarme?
El caso es que yo estoy muy verde en el javascript y no se como hacerlo. ¿Alguien puede ayudarme?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
var Bingo = {
min: 1,
max: 90,
numerosSorteados: new Array(),
windowDocument: null,
init: function(parent){
this.windowDocument = parent;
this.bind();
},
bind: function(){
$("#boton-borrar-todo").click(function(){
Bingo.botonBorrarTodoAction();
});
$("#boton-jugar").click(function(){
Bingo.botonJugarAction();
});
$(".texto").click(function(){
Bingo.seleccionarTipoJuego(this);
});
$("#boton-sortear").click(function(){
Bingo.jugar();
});
$(".wp-pagenavi-span").click(function(){
Bingo.seleccionarBolaAction($('#' + this.id));
});
},
seleccionarTipoJuego: function(boton){
if(!$(boton).hasClass( "texto-seleccionado" )){
$(boton).addClass('texto-seleccionado', 1000, 'easeOutQuart');
var aux = $(boton).attr('id');
switch(aux){
case 'boton-terna':
$('#boton-linea').removeClass('texto-seleccionado', 500, 'easeOutQuart');
$('#boton-bingo').removeClass('texto-seleccionado', 500, 'easeOutQuart');
break;
case 'boton-linea':
$('#boton-terna').removeClass('texto-seleccionado', 500, 'easeOutQuart');
$('#boton-bingo').removeClass('texto-seleccionado', 500, 'easeOutQuart');
break;
case 'boton-bingo':
$('#boton-terna').removeClass('texto-seleccionado', 500, 'easeOutQuart');
$('#boton-linea').removeClass('texto-seleccionado', 500, 'easeOutQuart');
break;
}
} else {
$(boton).removeClass('texto-seleccionado', 1000, 'easeOutQuart');
}
},
botonBorrarTodoAction: function(){
window.top.location.reload();
},
botonJugarAction: function(){
bootbox.dialog({
message: "<p>Quiere que el sistema genere automaticamente los números sorteados?<br/> (Esta opción es muy util cuando usted no dispone de bolillero para realizar el sorteo)</p>",
title: "Seleccione una opción para iniciar el Juego",
buttons: {
danger: {
label: "No",
className: "btn-danger",
callback: function() {
}
},
main: {
label: "Si, generar",
className: "btn-primary",
callback: function() {
bootbox.hideAll();
Bingo.numerosSorteados = new Array();
Bingo.jugar();
}
}
}
});
},
anularBola: function(numero){
$('#bola-actual').html('-');
$('#bola-salio-'+numero).remove();
$('#bola-'+numero).removeClass('wp-pagenavi-span-bola-salio');
$('#bola-'+numero).addClass('wp-pagenavi-span');
},
seleccionarBolaAction: function(bola){
if(bola.hasClass( "wp-pagenavi-span-bola-salio" )){
console.log("La bola seleccionada YA SALIO!");
}
else{
var n = bola.html();
console.log('Numero marcado: ' + n);
this.generarBolaGigante(n);
this.marcarBolaYaSalio(bola);
this.numerosSorteados.push(n);
console.log(this.numerosSorteados);
}
},
marcarBolaYaSalio: function(bola){
bola.addClass('wp-pagenavi-span-bola-salio', 3000, 'easeOutExpo',
function(){
bola.removeClass('wp-pagenavi-span');
var numero = bola.html();
$('#bola-actual-flotante').remove();
$('#ultimas-6').prepend('<span class="wp-pagenavi-span-bola-salio" onclick="Bingo.anularBola(\''+numero+'\');" id="bola-salio-'+numero+'">'+numero+'</span>');
}
);
},
generarBolaGigante: function(numero){
$('#bola-actual').html(numero);
$( window.document.body ).prepend('<span class="bola-actual-flotante" id="bola-actual-flotante">'+numero+'</span>');
$( ".bola-actual-flotante" ).position({
of: $('#left-content')
});
},
generarNumeroAleatorio: function() {
//http://stackoverflow.com/questions/1527803/generating-random-numbers-in-javascript-in-a-specific-range
var n = Math.floor(Math.random() * (Bingo.max - Bingo.min + 1)) + Bingo.min;
if(n < 10){
n = "0" + n.toString();
}
console.log('Numero generado: ' + n.toString());
return n.toString();
},
jugar: function(){
console.log(_.size(Bingo.numerosSorteados));
if(_.size(Bingo.numerosSorteados) >= (Bingo.max)){
Bingo.showMensajeJuegoFinalizado();
return;
}
var n = Bingo.generarNumeroAleatorio();
if(_.contains(Bingo.numerosSorteados, n)){
// controlar que aca si ya tiene todos los numeros no genere infinitamente
console.log('Numero sorteado ya salio: ' + n);
Bingo.jugar();
}
else{
Bingo.seleccionarBolaAction($('#bola-' + n));
}
},
showMensajeJuegoFinalizado: function(){
bootbox.dialog({
message: "<p>Todos los números ya fueron sorteados.<br/>Desea LIMPIAR la pizarra?</p>",
title: "El Juego a finalizado",
buttons: {
danger: {
label: "No",
className: "btn-danger",
callback: function() {
}
},
main: {
label: "Si, limpiar",
className: "btn-primary",
callback: function() {
bootbox.hideAll();
Bingo.botonBorrarTodoAction();
}
}
}
});
}
};
$( window.document ).ready(function() {
Bingo.init(this);
});
Valora esta pregunta


0