-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
137 lines (110 loc) · 3.89 KB
/
index.html
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
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Juliana</title>
<link rel="stylesheet" href="assets/css/style.css">
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Nunito:wght@600&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css"
integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">
</head>
<body>
<div class="container">
<div class="d-flex justify-content-center align-self-center">
<img src="imgs/logo-tigre.png" style="width: auto; height: 100px;" alt="tigre">
</div>
<div id="loser" class="d-flex justify-content-center mb-2">
</div>
<div class="d-flex justify-content-center">
<p id="alert"></p>
</div>
<div class="d-flex justify-content-between click" >
<button type="button" onClick="countClick()" class="btn btn-outline-dark">Pular</button>
<p id="counter">Total de pulos: 0</p>
<button type="button" onClick="countClick()" class="btn btn-outline-dark">Pular</button>
</div>
</div>
<div id="desert" class="">
<div class="grid">
<div class="dino"></div>
</div>
</div>
<script src="assets/js/app.js" charset="utf-8"></script>
<script type="text/javascript">
var isJumping = false;
var isGameOver = false;
var position = 0;
var count = 0;
const dino = document.querySelector('.dino');
const grid = document.querySelector('.grid');
const body = document.querySelector('body');
const alert = document.getElementById('alert');
function control(e) {
if (e === 1){
if (!isJumping) {
isJumping = true
jump();
}
}
}
// funcao que controla o pulo do tigrinho
function jump() {
let timerId = setInterval(function () {
if (position === 150) {
clearInterval(timerId);
let downTimerId = setInterval(function (){
if (position === 15) {
clearInterval(downTimerId)
isJumping = false;
}
position -= 15;
dino.style.bottom = position + 'px';
}, 35)
}
position += 15;
dino.style.bottom = position + 'px'
}, 35)
}
// funcao que gera os cano do tigrinho
function generateObstacles() {
let randomTime = Math.random() * 1300 + 750;
let obstaclePosition = 1000;
const obstacle = document.createElement('div');
if (!isGameOver)
obstacle.classList.add('obstacle');
grid.appendChild(obstacle);
obstacle.style.left = obstaclePosition + 'px';
let timerId = setInterval(function() {
if (obstaclePosition > 0 && obstaclePosition < 60 && position < 60) {
clearInterval(timerId);
alert.innerText = "Argh, você perdeu :(\nTente novamente!";
let loserButton = document.getElementById('loser');
loser.innerHTML = '<button type="button" onclick="resetGame()" class="btn btn-outline-danger">Restart</button>';
isGameOver = true;
grid.innerHTML = '<div class="dino"></div>';
}
obstaclePosition -= 10;
obstacle.style.left = obstaclePosition + 'px';
}, 30)
if (!isGameOver) setTimeout(generateObstacles, randomTime)
}
function resetGame() {
location.reload();
}
function countClick() {
if (!isGameOver) {
count += 1;
counter.innerText = `Total de pulos: ${count}`;
control(1);
}
}
document.addEventListener ('DOMContentLoaded', () => {
let counter = document.getElementById('counter');
generateObstacles();
count = 0;
});
</script>
</body>
</html>