KEXEL commited on
Commit
c03f6c3
·
verified ·
1 Parent(s): eda6403

Upload 11 files

Browse files
hangman-game/img1.png ADDED
hangman-game/img2.png ADDED
hangman-game/img3.png ADDED
hangman-game/img4.png ADDED
hangman-game/img5.png ADDED
hangman-game/img6.png ADDED
hangman-game/img7.png ADDED
hangman-game/index.html ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta http-equiv="X-UA-Compatible" content="IE=edge">
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
+ <title>Jogo da forca</title>
8
+ <link rel="stylesheet" href="style.css">
9
+ </head>
10
+ <body>
11
+ <header>
12
+ <h1>Jogo da Forca</h1>
13
+ </header>
14
+ <button class="new">Novo Jogo</button>
15
+ <main>
16
+ <article class="content-img">
17
+ <img src="img1.png" width="250px" alt="Jogo da forca">
18
+ </article>
19
+ <article class="content">
20
+ <div class="guess-word"></div>
21
+ <div class="clue"></div>
22
+ <div class="btns"></div>
23
+ </article>
24
+ </main>
25
+
26
+ <script src="script.js" type="module"></script>
27
+ </body>
28
+ </html>
hangman-game/script.js ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import getWord from "./words.js";
2
+
3
+ const contentBtns = document.querySelector(".btns");
4
+ const contentGuessWord = document.querySelector(".guess-word");
5
+ const img = document.querySelector("img");
6
+ const contentClue = document.querySelector(".clue");
7
+ const btnNew = document.querySelector(".new");
8
+ btnNew.onclick = () => init();
9
+ let indexImg;
10
+
11
+ init();
12
+
13
+ function init() {
14
+ indexImg = 1;
15
+ img.src = `img1.png`;
16
+
17
+ generateGuessSection();
18
+ generateButtons();
19
+ }
20
+
21
+ function generateGuessSection() {
22
+ contentGuessWord.textContent = "";
23
+
24
+ const { word, clue } = getWord();
25
+ const wordWithoutAccent = word
26
+ .normalize("NFD")
27
+ .replace(/[\u0300-\u036f]/g, "");
28
+
29
+ Array.from(wordWithoutAccent).forEach((letter) => {
30
+ const span = document.createElement("span");
31
+
32
+ span.textContent = "_";
33
+ span.setAttribute("word", letter.toUpperCase());
34
+ contentGuessWord.appendChild(span);
35
+ });
36
+
37
+ contentClue.textContent = `Dica: ${clue}`;
38
+ }
39
+
40
+ function wrongAnswer() {
41
+ indexImg++;
42
+ img.src = `img${indexImg}.png`;
43
+
44
+ if (indexImg === 7) {
45
+ setTimeout(() => {
46
+ alert("Perdeu :/");
47
+ init();
48
+ }, 100);
49
+ }
50
+ }
51
+
52
+ function verifyLetter(letter) {
53
+ const arr = document.querySelectorAll(`[word="${letter}"]`);
54
+
55
+ if (!arr.length) wrongAnswer();
56
+
57
+ arr.forEach((e) => {
58
+ e.textContent = letter;
59
+ });
60
+
61
+ const spans = document.querySelectorAll(`.guess-word span`);
62
+ const won = !Array.from(spans).find((span) => span.textContent === "_");
63
+
64
+ if (won) {
65
+ setTimeout(() => {
66
+ alert("Ganhou!!!");
67
+ init();
68
+ }, 100);
69
+ }
70
+ }
71
+
72
+ function generateButtons() {
73
+ contentBtns.textContent = "";
74
+
75
+ for (let i = 97; i < 123; i++) {
76
+ const btn = document.createElement("button");
77
+ const letter = String.fromCharCode(i).toUpperCase();
78
+ btn.textContent = letter;
79
+
80
+ btn.onclick = () => {
81
+ btn.disabled = true;
82
+ btn.style.backgroundColor = "gray";
83
+ verifyLetter(letter);
84
+ };
85
+
86
+ contentBtns.appendChild(btn);
87
+ }
88
+ }
hangman-game/style.css ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ * {
2
+ margin: 0;
3
+ padding: 0;
4
+ box-sizing: border-box;
5
+ }
6
+
7
+ body {
8
+ display: flex;
9
+ align-items: center;
10
+ justify-content: center;
11
+ flex-direction: column;
12
+ min-height: 100vh;
13
+ font-family: Arial, Helvetica, sans-serif;
14
+ }
15
+
16
+ main {
17
+ display: flex;
18
+ align-items: center;
19
+ gap: 30px;
20
+ }
21
+
22
+ .content {
23
+ display: flex;
24
+ flex-direction: column;
25
+ gap: 30px;
26
+ height: 200px;
27
+ max-width: 400px;
28
+ }
29
+
30
+ .guess-word {
31
+ display: flex;
32
+ gap: 10px;
33
+ font-size: 50px;
34
+ flex-wrap: wrap;
35
+ }
36
+
37
+ .btns {
38
+ display: flex;
39
+ gap: 5px;
40
+ flex-wrap: wrap;
41
+ }
42
+
43
+ button {
44
+ height: 30px;
45
+ font-size: 20px;
46
+ cursor: pointer;
47
+ color: white;
48
+ border: none;
49
+ border-radius: 3px;
50
+ }
51
+
52
+ .btns button {
53
+ width: 30px;
54
+ background-color: #0ea989;
55
+ }
56
+
57
+ .new {
58
+ width: 120px;
59
+ background-color: #3ba128;
60
+ margin: 20px;
61
+ }
62
+
63
+ button:hover {
64
+ opacity: 0.8;
65
+ }
66
+
67
+ .clue {
68
+ font-size: 18px;
69
+ }
70
+
71
+ @media (max-width:650px) {
72
+ main {
73
+ flex-direction: column;
74
+ padding: 10px;
75
+ }
76
+ }
hangman-game/words.js ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const words = [
2
+ { word: "abacaxi", clue: "Fruta tropical" },
3
+ { word: "elefante", clue: "Animal de grande porte com tromba longa" },
4
+ { word: "computador", clue: "Dispositivo eletrônico" },
5
+ { word: "girafa", clue: "Animal alto, com pescoço longo" },
6
+ { word: "chocolate", clue: "Doce feito de cacau" },
7
+ { word: "piano", clue: "Instrumento musical com teclas" },
8
+ { word: "tigre", clue: "Felino selvagem" },
9
+ { word: "esmeralda", clue: "Tipo de pedra preciosa" },
10
+ { word: "navio", clue: "Embarcação no mar" },
11
+ { word: "telefone", clue: "Dispositivo de comunicação" },
12
+ { word: "floresta", clue: "Área com muitas árvores" },
13
+ { word: "quadrado", clue: "Figura geométrica de quatro lados" },
14
+ { word: "foguete", clue: "Veículo espacial" },
15
+ { word: "sorvete", clue: "Doce gelado" },
16
+ { word: "bicicleta", clue: "Veículo de duas rodas" },
17
+ { word: "avião", clue: "Meio de transporte aéreo" },
18
+ { word: "macaco", clue: "Primate arbóreo" },
19
+ { word: "raios", clue: "Descargas elétricas na atmosfera" },
20
+ { word: "montanha", clue: "Elevação natural da terra" },
21
+ { word: "vela", clue: "Objeto para iluminação" },
22
+ ];
23
+
24
+ export default function getWord() {
25
+ const index = Math.floor(Math.random() * words.length);
26
+ return words[index];
27
+ }