-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsketch.js
644 lines (535 loc) · 18.6 KB
/
sketch.js
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
function validateInput(){
let inputNumber = parseInt(this.value());
if(!Number.isInteger(inputNumber)){
this.value("");
}
if(inputNumber > 99){
this.value("");
}
}
function drawCardInputs(){
noFill();
stroke(255);
strokeWeight(3);
rect(100, 20, 330, 300);
stroke(0);
strokeWeight(1);
//Primeira fileira
number1Input = createInput('');
number1Input.position(172, 100);
number1Input.style("width", "25px");
number1Input.style("height", "20px");
number1Input.value(1);
number1Input.input(validateInput);
number2Input = createInput('');
number2Input.position(210, 100);
number2Input.style("width", "25px");
number2Input.style("height", "20px");
number2Input.value(21);
number2Input.input(validateInput);
number3Input = createInput('');
number3Input.position(250, 100);
number3Input.style("width", "25px");
number3Input.style("height", "20px");
number3Input.value(39);
number3Input.input(validateInput);
number4Input = createInput('');
number4Input.position(290, 100);
number4Input.style("width", "25px");
number4Input.style("height", "20px");
number4Input.value(58);
number4Input.input(validateInput);
number5Input = createInput('');
number5Input.position(330, 100);
number5Input.style("width", "25px");
number5Input.style("height", "20px");
number5Input.value(81);
number5Input.input(validateInput);
//Segunda Fileira
number6Input = createInput('');
number6Input.position(172, 125);
number6Input.style("width", "25px");
number6Input.style("height", "20px");
number6Input.value(4);
number6Input.input(validateInput);
number7Input = createInput('');
number7Input.position(210, 125);
number7Input.style("width", "25px");
number7Input.style("height", "20px");
number7Input.value(23);
number7Input.input(validateInput);
number8Input = createInput('');
number8Input.position(250, 125);
number8Input.style("width", "25px");
number8Input.style("height", "20px");
number8Input.value(41);
number8Input.input(validateInput);
number9Input = createInput('');
number9Input.position(290, 125);
number9Input.style("width", "25px");
number9Input.style("height", "20px");
number9Input.value(59);
number9Input.input(validateInput);
number10Input = createInput('');
number10Input.position(330, 125);
number10Input.style("width", "25px");
number10Input.style("height", "20px");
number10Input.value(83);
number10Input.input(validateInput);
//Terceira Fileira
number11Input = createInput('');
number11Input.position(172, 150);
number11Input.style("width", "25px");
number11Input.style("height", "20px");
number11Input.value(5);
number11Input.input(validateInput);
number12Input = createInput('');
number12Input.position(210, 150);
number12Input.style("width", "25px");
number12Input.style("height", "20px");
number12Input.value(24);
number12Input.input(validateInput);
number13Input = createInput('');
number13Input.position(250, 150);
number13Input.style("width", "25px");
number13Input.style("height", "20px");
number13Input.value(45);
number13Input.input(validateInput);
number14Input = createInput('');
number14Input.position(290, 150);
number14Input.style("width", "25px");
number14Input.style("height", "20px");
number14Input.value(61);
number14Input.input(validateInput);
number15Input = createInput('');
number15Input.position(330, 150);
number15Input.style("width", "25px");
number15Input.style("height", "20px");
number15Input.value(85);
number15Input.input(validateInput);
//Quarta Fileira
number16Input = createInput('');
number16Input.position(172, 175);
number16Input.style("width", "25px");
number16Input.style("height", "20px");
number16Input.value(7);
number16Input.input(validateInput);
number17Input = createInput('');
number17Input.position(210, 175);
number17Input.style("width", "25px");
number17Input.style("height", "20px");
number17Input.value(25);
number17Input.input(validateInput);
number18Input = createInput('');
number18Input.position(250, 175);
number18Input.style("width", "25px");
number18Input.style("height", "20px");
number18Input.value(46);
number18Input.input(validateInput);
number19Input = createInput('');
number19Input.position(290, 175);
number19Input.style("width", "25px");
number19Input.style("height", "20px");
number19Input.value(63);
number19Input.input(validateInput);
number20Input = createInput('');
number20Input.position(330, 175);
number20Input.style("width", "25px");
number20Input.style("height", "20px");
number20Input.value(86);
number20Input.input(validateInput);
//Quinta Fileira
number21Input = createInput('');
number21Input.position(172, 200);
number21Input.style("width", "25px");
number21Input.style("height", "20px");
number21Input.value(8);
number21Input.input(validateInput);
number22Input = createInput('');
number22Input.position(210, 200);
number22Input.style("width", "25px");
number22Input.style("height", "20px");
number22Input.value(26);
number22Input.input(validateInput);
number23Input = createInput('');
number23Input.position(250, 200);
number23Input.style("width", "25px");
number23Input.style("height", "20px");
number23Input.value(47);
number23Input.input(validateInput);
number24Input = createInput('');
number24Input.position(290, 200);
number24Input.style("width", "25px");
number24Input.style("height", "20px");
number24Input.value(66);
number24Input.input(validateInput);
number25Input = createInput('');
number25Input.position(330, 200);
number25Input.style("width", "25px");
number25Input.style("height", "20px");
number25Input.value(88);
number25Input.input(validateInput);
//Sexta Fileira
number26Input = createInput('');
number26Input.position(172, 225);
number26Input.style("width", "25px");
number26Input.style("height", "20px");
number26Input.value(10);
number26Input.input(validateInput);
number27Input = createInput('');
number27Input.position(210, 225);
number27Input.style("width", "25px");
number27Input.style("height", "20px");
number27Input.value(30);
number27Input.input(validateInput);
number28Input = createInput('');
number28Input.position(250, 225);
number28Input.style("width", "25px");
number28Input.style("height", "20px");
number28Input.value(49);
number28Input.input(validateInput);
number29Input = createInput('');
number29Input.position(290, 225);
number29Input.style("width", "25px");
number29Input.style("height", "20px");
number29Input.value(67);
number29Input.input(validateInput);
number30Input = createInput('');
number30Input.position(330, 225);
number30Input.style("width", "25px");
number30Input.style("height", "20px");
number30Input.value(90);
number30Input.input(validateInput);
//Setima Fileira
number31Input = createInput('');
number31Input.position(172, 250);
number31Input.style("width", "25px");
number31Input.style("height", "20px");
number31Input.value(12);
number31Input.input(validateInput);
number32Input = createInput('');
number32Input.position(210, 250);
number32Input.style("width", "25px");
number32Input.style("height", "20px");
number32Input.value(31);
number32Input.input(validateInput);
number33Input = createInput('');
number33Input.position(250, 250);
number33Input.style("width", "25px");
number33Input.style("height", "20px");
number33Input.value(50);
number33Input.input(validateInput);
number34Input = createInput('');
number34Input.position(290, 250);
number34Input.style("width", "25px");
number34Input.style("height", "20px");
number34Input.value(73);
number34Input.input(validateInput);
number35Input = createInput('');
number35Input.position(330, 250);
number35Input.style("width", "25px");
number35Input.style("height", "20px");
number35Input.value(92);
number35Input.input(validateInput);
//Oitava Fileira
number36Input = createInput('');
number36Input.position(172, 275);
number36Input.style("width", "25px");
number36Input.style("height", "20px");
number36Input.value(15);
number36Input.input(validateInput);
number37Input = createInput('');
number37Input.position(210, 275);
number37Input.style("width", "25px");
number37Input.style("height", "20px");
number37Input.value(32);
number37Input.input(validateInput);
number38Input = createInput('');
number38Input.position(250, 275);
number38Input.style("width", "25px");
number38Input.style("height", "20px");
number38Input.value(51);
number38Input.input(validateInput);
number39Input = createInput('');
number39Input.position(290, 275);
number39Input.style("width", "25px");
number39Input.style("height", "20px");
number39Input.value(74);
number39Input.input(validateInput);
number40Input = createInput('');
number40Input.position(330, 275);
number40Input.style("width", "25px");
number40Input.style("height", "20px");
number40Input.value(95);
number40Input.input(validateInput);
//Nona Fileira
number41Input = createInput('');
number41Input.position(172, 300);
number41Input.style("width", "25px");
number41Input.style("height", "20px");
number41Input.value(16);
number41Input.input(validateInput);
number42Input = createInput('');
number42Input.position(210, 300);
number42Input.style("width", "25px");
number42Input.style("height", "20px");
number42Input.value(33);
number42Input.input(validateInput);
number43Input = createInput('');
number43Input.position(250, 300);
number43Input.style("width", "25px");
number43Input.style("height", "20px");
number43Input.value(52);
number43Input.input(validateInput);
number44Input = createInput('');
number44Input.position(290, 300);
number44Input.style("width", "25px");
number44Input.style("height", "20px");
number44Input.value(75);
number44Input.input(validateInput);
number45Input = createInput('');
number45Input.position(330, 300);
number45Input.style("width", "25px");
number45Input.style("height", "20px");
number45Input.value(96);
number45Input.input(validateInput);
//Decima Fileira
number46Input = createInput('');
number46Input.position(172, 325);
number46Input.style("width", "25px");
number46Input.style("height", "20px");
number46Input.value(17);
number46Input.input(validateInput);
number47Input = createInput('');
number47Input.position(210, 325);
number47Input.style("width", "25px");
number47Input.style("height", "20px");
number47Input.value(38);
number47Input.input(validateInput);
number48Input = createInput('');
number48Input.position(250, 325);
number48Input.style("width", "25px");
number48Input.style("height", "20px");
number48Input.value(56);
number48Input.input(validateInput);
number49Input = createInput('');
number49Input.position(290, 325);
number49Input.style("width", "25px");
number49Input.style("height", "20px");
number49Input.value(80);
number49Input.input(validateInput);
number50Input = createInput('');
number50Input.position(330, 325);
number50Input.style("width", "25px");
number50Input.style("height", "20px");
number50Input.value(98);
number50Input.input(validateInput);
textSize(16);
fill(255);
text("Minha Cartela", 210, 305);
}
function drawButtons(){
//Buttons Jogar/Auto
buttonPlay = createButton('JOGAR');
buttonPlay.position(110, 400);
buttonPlay.style("width", "140px");
buttonPlay.style("height", "50px");
buttonPlay.style("background-color", "green");
buttonPlay.style("color", "white");
buttonPlay.mousePressed(play);
buttonAutoPlay = createButton('Auto');
buttonAutoPlay.position(270, 400);
buttonAutoPlay.style("width", "140px");
buttonAutoPlay.style("height", "50px");
buttonAutoPlay.style("background-color", "blue");
buttonAutoPlay.style("color", "white");
buttonAutoPlay.mousePressed(autoPlay);
}
function gerarCartelas(quantCartelas, quantNumerosSortidosPorCartela){
var sorteio = [];
//Cria as cartelas com a quantidade de numeros solicitada.
for(var iteracoes = 0; iteracoes < quantCartelas; iteracoes++){
for(var i = 0; i < quantNumerosSortidosPorCartela; i++){
sorteio.push(floor(random(0, 100)));
}
}
//O random deve ir de 1 - 26, por que ele vai ignorar o ultimo digito no caso o (26).
//Limpa os numeros repetidos das cartelas.
var repetir = false;
do{
for(var x = 0; x < sorteio.length; x++){
repetir = false;
for(var c = 0; c < sorteio.length; c++){
if(sorteio[x] === sorteio[c] && x !== c){
sorteio.splice(x, 1);
var novoValor = floor(random(1, 26));
sorteio.push(novoValor);
repetir = true;
x = sorteio.length;
break;
}
}
}
}while(repetir);
//Para ordenar os numeros dentro da cartela.
sorteio.sort(function(a, b) {
return a - b;
});
return sorteio;
}
function atualizarMinhaCartela(){
minhaCartela = [
parseInt(number1Input.value()), parseInt(number2Input.value()), parseInt(number3Input.value()), parseInt(number4Input.value()), parseInt(number5Input.value()),
parseInt(number6Input.value()), parseInt(number7Input.value()), parseInt(number8Input.value()), parseInt(number9Input.value()), parseInt(number10Input.value()),
parseInt(number11Input.value()), parseInt(number12Input.value()), parseInt(number13Input.value()), parseInt(number14Input.value()), parseInt(number15Input.value()),
parseInt(number16Input.value()), parseInt(number17Input.value()), parseInt(number18Input.value()), parseInt(number19Input.value()), parseInt(number20Input.value()),
parseInt(number21Input.value()), parseInt(number22Input.value()), parseInt(number23Input.value()), parseInt(number24Input.value()), parseInt(number25Input.value()),
parseInt(number26Input.value()), parseInt(number27Input.value()), parseInt(number28Input.value()), parseInt(number29Input.value()), parseInt(number30Input.value()),
parseInt(number31Input.value()), parseInt(number32Input.value()), parseInt(number33Input.value()), parseInt(number34Input.value()), parseInt(number35Input.value()),
parseInt(number36Input.value()), parseInt(number37Input.value()), parseInt(number38Input.value()), parseInt(number39Input.value()), parseInt(number40Input.value()),
parseInt(number41Input.value()), parseInt(number42Input.value()), parseInt(number43Input.value()), parseInt(number44Input.value()), parseInt(number45Input.value()),
parseInt(number46Input.value()), parseInt(number47Input.value()), parseInt(number48Input.value()), parseInt(number49Input.value()), parseInt(number50Input.value()),
];
}
var number1Input;
var number2Input;
var number3Input;
var number4Input;
var number5Input;
var number6Input;
var number7Input;
var number8Input;
var number9Input;
var number10Input;
var number11Input;
var number12Input;
var number13Input;
var number14Input;
var number15Input;
var buttonPlay;
var buttonAutoPlay;
var minhaCartela = [];
var acertoNumeros = 0;
var valorFaturado = 0;
var valorAposta = 2.50;
var valorInvestido = 0;
var acertoJogos = 0;
var quantJogadas = 0;
var mediaAcertos = 0;
var velocidadeDoJogo = 1;
var toggle = false;
var autoPlaying = false;
var playing = true;
function setup() {
createCanvas(windowWidth, 400);
frameRate(velocidadeDoJogo);
background(51);
drawCardInputs();
drawButtons();
atualizarMinhaCartela();
}
function draw() {
atualizarMinhaCartela();
if(autoPlaying){
jogar();
}
}
function jogar(){
background(51);
quantJogadas++;
var cartelaPremiada = gerarCartelas(1, 20);
for(var i = 0; i < minhaCartela.length; i++){
for(var x = 0; x < cartelaPremiada.length; x++){
if(minhaCartela[i] === cartelaPremiada[x]){
acertoNumeros++;
}
}
}
switch(acertoNumeros){
case 0:
valorFaturado += 119906.97;
acertoJogos++;
break;
case 15:
valorFaturado += 4.97;
acertoJogos++;
break;
case 16:
valorFaturado += 21.08;
acertoJogos++;
break;
case 17:
valorFaturado += 123.11;
acertoJogos++;
break;
case 18:
valorFaturado += 1561.50;
acertoJogos++;
break;
case 19:
valorFaturado += 95605.51;
acertoJogos++;
break;
case 20:
valorFaturado += 5000000.00;
acertoJogos++;
break;
}
mediaAcertos = acertoJogos/quantJogadas;
valorInvestido = valorAposta * quantJogadas;
textSize(16);
fill(255);
text("Valor Faturado: R$ "+valorFaturado.toFixed(2), 500, 30);
text("Qtd Apostas Ganhadoras: "+acertoJogos, 500, 51);
text("Qtd Apostas Feitas: "+quantJogadas, 500, 72);
text("Média de Apostas Ganhadoras: "+mediaAcertos.toFixed(2), 800, 52 );
text("Valor investido: R$ "+valorInvestido.toFixed(2), 800, 72);
fill(255, 255, 0);
var posicaoXx = 700, posicaoYy = 129;
for(x = 0; x < cartelaPremiada.length; x++){
if(cartelaPremiada[x] < 10){
text("0"+cartelaPremiada[x], posicaoXx, posicaoYy);
}else{
text(cartelaPremiada[x], posicaoXx, posicaoYy);
}
if(posicaoYy < height - 198){
posicaoYy+=33;
}else if(posicaoXx < width - 20){
posicaoYy = 129;
posicaoXx += 39;
}
}
noFill();
stroke(255);
strokeWeight(3);
rect(100, 20, 330, 300);
stroke(0);
strokeWeight(1);
fill(255);
text("Minha Cartela", 210, 305);
noFill();
stroke(255, 255, 0);
strokeWeight(3);
rect(640, 100, 290, 280);
stroke(0);
strokeWeight(1);
fill(255, 255, 0);
text("Cartela Premiada", 720, 260);
textSize(20);
text("Acertos nessa cartela", 690, 321);
textSize(40);
text(acertoNumeros, 780, 370);
acertoNumeros = 0;
}
function autoPlay(){
if(!autoPlaying){
autoPlaying = false;
}else{
autoPlaying = true;
}
autoPlaying = !autoPlaying;
}
function play(){
jogar();
autoPlaying = false;
}