-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
111 lines (82 loc) · 2.39 KB
/
script.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
var alturaTela = 0
var laguraTela = 0
var vidas = 3
var tempo = 20
var criarMosquitoTempo
var nivel = window.location.search
nivel = nivel.replace('?', '')
if(nivel == 'normal'){
criarMosquitoTempo = 1500
}else if(nivel == 'dificil'){
criarMosquitoTempo = 1000
}else if(nivel == 'chucknorris'){
criarMosquitoTempo = 750
}
var cronometro = setInterval(function(){
if(tempo < 0){
clearInterval(cronometro)
clearInterval(criarMosca)
window.location.href = './vitoria.html'
}else{
document.getElementById("cronometro").innerHTML = tempo
}
tempo--
},1000)
function ajustaTamanhoPalcoJogo(){
alturaTela = window.innerHeight
laguraTela = window.innerWidth
console.log(alturaTela, laguraTela)
}
ajustaTamanhoPalcoJogo()
function possicaoRandomica(){
//remover o mosquito anterior
if (document.getElementById('mosquito')){
document.getElementById('mosquito').remove()
if (vidas > 0){
document.getElementById('v'+vidas).src = "./imagens/coracao_vazio.png"
vidas--
}else{
window.location.href = './fim_do_jogo.html'
}
}
var possicaoX = Math.floor(Math.random() * laguraTela) - 90
var possicaoY = Math.floor(Math.random() * alturaTela) - 90
possicaoY = possicaoY < 0 ? 0: possicaoY
possicaoX = possicaoX < 0 ? 0: possicaoX
console.log(possicaoX, possicaoY)
//criar o elemento html
var mosquito = document.createElement('img')
mosquito.src = './imagens/mosca.png'
mosquito.className = tamanhoAleatorio() +' '+ ladoAleatorio()
mosquito.style.left = possicaoX +'px'
mosquito.style.top =possicaoY +'px'
mosquito.style.position = 'absolute'
mosquito.id ="mosquito"
mosquito.onclick = function(){
this.remove()
}
document.body.appendChild(mosquito)
}
function tamanhoAleatorio(){
var classe = Math.floor(Math.random() * 3)
switch(classe){
case 0:
return 'mosquito1'
case 1:
return 'mosquito2'
case 2:
return 'mosquito3'
}
}
function ladoAleatorio(){
var classe = Math.floor(Math.random() * 2)
switch(classe){
case 0:
return 'ladoA'
case 1:
return 'ladoB'
}
}
var criarMosca = setInterval(function(){
possicaoRandomica()
},criarMosquitoTempo)