-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjogo.js
96 lines (81 loc) · 2.21 KB
/
jogo.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
var altura = 0
var largura = 0
var vidas = 1
var tempo = 15
var criaMosquitoTempo = 1500
var nivel = window.location.search
nivel = nivel.replace('?', '')
if (nivel === 'normal') {
criaMosquitoTempo = 1500
}
else if (nivel === 'dificil') {
criaMosquitoTempo = 1000
}
else if (nivel === 'chucknorris') {
criaMosquitoTempo = 750
}
function ajustaTamanhoPalcoJogo() {
altura = window.innerHeight
largura = window.innerWidth
}
ajustaTamanhoPalcoJogo()
var cronometro = setInterval(function() {
tempo--
if (tempo < 0) {
clearInterval(cronometro)
clearInterval(criaMosquito)
window.location.href = 'vitoria.html'
}
else {
document.getElementById('cronometro').innerHTML = tempo
}
}, 1000)
function posicaoRandomica() {
//remover o mosquito anterior caso exista
if (document.getElementById('mosquito')) {
document.getElementById('mosquito').remove()
if (vidas > 3) {
window.location.href = 'fim_de_jogo.html'
}
else {
document.getElementById('v' + vidas).src = "imagens/coracao_vazio.png"
vidas++;
}
}
var posicaoX = Math.floor(Math.random() * largura) - 90
var posicaoY = Math.floor(Math.random() * altura) - 90
posicaoX = posicaoX < 0 ? 0 : posicaoX
posicaoY = posicaoY < 0 ? 0 : posicaoY
//criar o elemento html
var mosquito = document.createElement('img')
mosquito.src = 'imagens/mosquito.png'
mosquito.className = tamanhoRandomico() + ' ' + ladoRandomico()
mosquito.style.left = posicaoX + 'px'
mosquito.style.top = posicaoY + 'px'
mosquito.style.position = 'absolute'
mosquito.id = 'mosquito'
mosquito.onclick = function () {
this.remove()
}
document.body.appendChild(mosquito)
}
function tamanhoRandomico() {
var classe = Math.floor(Math.random() * 3)
switch(classe) {
case 0:
return 'mosquito1'
case 1:
return 'mosquito2'
case 2:
return 'mosquito3'
}
}
function ladoRandomico() {
var classe = Math.floor(Math.random() * 2)
switch(classe) {
case 0:
return 'ladoA'
case 1:
return 'ladoB'
}
}