Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="pt-br">
- <head>
- <meta charset="utf-8" />
- <style>
- #btnDica {
- position: absolute;
- top: 10px;
- left: 10px;
- }
- #cabeca {
- display: none;
- position: absolute;
- left: 180px;
- top: 40px;
- width: 55px;
- height: 55px;
- -webkit-border-radius: 25px;
- -moz-border-radius: 25px;
- border-radius: 25px;
- background: rgb(255, 230, 184);
- border: 1px solid black;
- }
- #braco_dir {
- display: none;
- position: absolute;
- left: 140px;
- top: 100px;
- width: 18px;
- height: 60px;
- background: rgb(255, 230, 184);
- border: 1px solid black;
- transform: rotate(30deg);
- }
- #braco_es {
- display: none;
- position: absolute;
- left: 260px;
- top: 100px;
- width: 18px;
- height: 60px;
- background: rgb(255, 230, 184);
- border: 1px solid black;
- transform: rotate(-30deg);
- }
- #perna_dir {
- display: none;
- position: absolute;
- left: 168px;
- top: 175px;
- width: 22px;
- height: 72px;
- background: cornflowerblue;
- border: 1px solid black;
- transform: rotate(15deg);
- }
- #perna_es {
- display: none;
- position: absolute;
- left: 228px;
- top: 175px;
- width: 22px;
- height: 72px;
- background: cornflowerblue;
- border: 1px solid black;
- transform: rotate(-15deg);
- }
- #corpo {
- display: none;
- position: absolute;
- left: 179px;
- top: 100px;
- width: 58px;
- height: 70px;
- background: #f70;
- border: 1px solid black;
- }
- #forca_poste {
- position: absolute;
- left: 310px;
- top: 3px;
- width: 50px;
- height: 480px;
- background: rgb(71, 13, 3);
- }
- #forca_aste {
- position: absolute;
- left: 150px;
- top: 3px;
- height: 30px;
- width: 200px;
- background: rgb(71, 13, 3);
- }
- #corda1 {
- position: absolute;
- left: 202px;
- top: 3px;
- height: 35px;
- width: 10px;
- background: rgb(221, 202, 115);
- }
- #corda2 {
- position: absolute;
- left: 183px;
- top: 45px;
- width: 40px;
- height: 40px;
- -webkit-border-radius: 25px;
- -moz-border-radius: 25px;
- border-radius: 25px;
- background: white;
- border: 5px solid rgb(221, 202, 115);
- }
- #main_container {
- position: absolute;
- left: 10px;
- top: 400px;
- border: 5px solid rgb(71, 13, 3);
- width: 600px;
- height: 360px;
- background-color: rgb(119, 45, 23);
- }
- .keyboard_container {
- position: absolute;
- display: block;
- left: 370px;
- top: 100px;
- border: 1px solid rgb(119, 45, 23);
- width: 200px;
- height: 250px;
- background-color: rgb(119, 45, 23);
- }
- #wordContainer {
- top: 10px;
- left: 10px;
- width: 355px;
- height: 345px;
- }
- #tries_container {
- left: 30px;
- }
- .btn_erro {
- background-color: red;
- }
- .btn_acerto {
- background-color: green;
- }
- .lbl_palavra {
- left: 15px;
- top: 10px;
- margin-left: 15px;
- text-align: center;
- color: rgb(221, 202, 115);
- font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
- font-size: 35px;
- font-weight: bolder;
- }
- .lbl_chances {
- left: 150px;
- top: 265px;
- position: absolute;
- text-align: center;
- color: orange;
- font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
- font-size: 40px;
- font-weight: bolder;
- }
- #lblChances1 {
- left: 10px;
- top: 230px;
- }
- .lbl_resultado {
- position: absolute;
- left: 240px;
- top: 40px;
- text-align: left;
- color: green;
- font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
- font-size: 55px;
- font-weight: bolder;
- }
- #welcomeScreen {
- position: absolute;
- left: 0px;
- top: 0px;
- width: 800px;
- height: 1000px;
- display: block;
- background-color: rgba(0, 0, 0, 0.89);
- }
- #lblDescription {
- margin-top: 80px;
- margin-left: 15px;
- margin-right: 15px;
- position: absolute;
- text-align: center;
- word-wrap: normal;
- font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
- font-size: 40px;
- color: #f70;
- }
- .btnGame {
- width: 80px;
- height: 50px;
- color: white;
- background-color: orangered;
- border: none;
- cursor: pointer;
- }
- #btnStart {
- width: 300px;
- height: 100px;
- position: absolute;
- left: 200px;
- top: 500px;
- }
- </style>
- <script>
- var palavras = ["PERIGO", "AMIZADE", "TROVÃO", "TENEBROSO",
- "TESTAMENTO", "MOSTARDA", "MORANGO", "IMPRESSORA", "AQUISIÇÃO", "EQUIVALÊNCIA",
- "HOMOSSEXUALIDADE", "MILÍCIA", "BRUSQUETA", "ALFAJOR", "CRUSTÁCEO", "PIPOCA", "HOMOGÊNEO",
- "FORÇA", "FORCA", "FACA", "ABACAXI", "INCOMPREESÍVEL", "TABULEIRO", "PARTICULAR", "ADIANTAMENTO", "TÉRMICA",
- "REGISTRADORAS", "DINHEIRO", "FOLHA", "CAMAFEU", "COELHO", "TÓTEM", "MOUSE", "CAVIDADES", "ORIFÍCIO", "EXPERIMENTOS",
- "SOBREVIVÊNCIA", "DITADURA", "VIBRAÇÃO", "PEGADAS", "MOSQUITO", "PÉROLA", "MANDIOCA", "BÚSSULA", "NOTÍCIA", "IMAGINAÇÃO",
- "PENDRIVE", "GATO", "FLUTUANDO", "BABACA", "VISCOSIDADE", "MUCO", "CATARRO", "GARGANTA", "BARRIGA", "PENAS", "CALCANHAR",
- "MANDALA", "MUDANÇA", "PESCADORES", "EMPREITADA", "PLAUSÍVEL"];
- var letras = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l",
- "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"];
- var sorteada, sorteadaCharArr;
- var chances = 6;
- function sortear() {
- var sort_num = Math.floor(Math.random() * palavras.length);
- return palavras[sort_num];
- }
- function muda_display(obj, deveMostrar) {
- if (deveMostrar == true) {
- obj.style.display = "block";
- } else {
- obj.style.display = "none";
- }
- }
- function muda_btn(btn, acertou, clicavel) {
- if (acertou == true) {
- if (btn.hasAttribute("class")) {
- btn.removeAttribute("class");
- }
- btn.setAttribute("class", "btn_acerto");
- } else {
- if (btn.hasAttribute("class")) {
- btn.removeAttribute("class");
- }
- btn.setAttribute("class", "btn_erro");
- }
- if (clicavel == true) {
- btn.style.pointerEvents = "visible";
- } else {
- btn.style.pointerEvents = "none";
- }
- }
- function retiraAcento(letra) {
- if (letra.toUpperCase() == "Ç") {
- return "C";
- }
- if (letra.toUpperCase() == "Ã" || letra.toUpperCase() == "Á" || letra.toUpperCase() == "Â" || letra.toUpperCase() == "À") {
- return "A";
- }
- if (letra.toUpperCase() == "É" || letra.toUpperCase() == "Ê") {
- return "E";
- }
- if (letra.toUpperCase() == "Í") {
- return "I";
- }
- if (letra.toUpperCase() == "Õ" || letra.toUpperCase() == "Ô" || letra.toUpperCase() == "Ó") {
- return "O";
- }
- if (letra.toUpperCase() == "Ú") {
- return "U";
- }
- return letra;
- }
- function diminuiAsChances() {
- chances--;
- let lblChances = document.getElementById("lblChances2");
- lblChances.innerText = chances;
- if (chances == 5) {
- let parte = document.getElementById("corpo");
- parte.style.display = "inline";
- } else if (chances == 4) {
- let parte = document.getElementById("braco_dir");
- parte.style.display = "inline";
- } else if (chances == 3) {
- let parte = document.getElementById("braco_es");
- parte.style.display = "inline";
- } else if (chances == 2) {
- let parte = document.getElementById("perna_dir");
- parte.style.display = "inline";
- } else if (chances == 1) {
- let parte = document.getElementById("perna_es");
- parte.style.display = "inline";
- } else {
- let parte = document.getElementById("cabeca");
- parte.style.display = "inline";
- let lblGanhou = document.getElementById("lblResult");
- lblGanhou.innerHTML = "PERDEU<br>A palavra era: <br>" + sorteada;
- lblGanhou.style.color = "#f00";
- showWelcome(false);
- }
- }
- function verificaVitoria() {
- let retorno = true;
- for (let index = 0; index < sorteadaCharArr.length; index++) {
- if (document.getElementById("id" + index).innerText == "-") {
- retorno = false;
- //alert("falso");
- }
- }
- return retorno;
- }
- function aLetraExiste(letr) {
- let retornoBool = false;
- for (let index = 0; index < sorteadaCharArr.length; index++) {
- let letra = retiraAcento(sorteadaCharArr[index]);
- if (letra == letr.toUpperCase()) {
- let theLbl = document.getElementById("id" + index);
- theLbl.innerText = sorteadaCharArr[index];
- retornoBool = true;
- }
- }
- return retornoBool;
- }
- function valida_click(btn) {
- if (aLetraExiste(btn.innerText)) {
- muda_btn(btn, true, false);
- if (verificaVitoria()) {
- let lblGanhou = document.getElementById("lblResult");
- lblGanhou.innerText = "GANHOU";
- showWelcome(false);
- }
- } else {
- muda_btn(btn, false, false);
- diminuiAsChances();
- }
- }
- function recria_teclado() {
- let keyboardContainer = document.getElementById("keyboardContainer");
- while (keyboardContainer.firstChild) {
- keyboardContainer.removeChild(keyboardContainer.firstChild);
- }
- for (let index = 0; index < letras.length; index++) {
- let curChar = letras[index];
- let btnNew = document.createElement("button");
- btnNew.style.width = "40px";
- btnNew.style.height = "40px";
- btnNew.style.top = "10px";
- btnNew.style.display = "inline";
- btnNew.addEventListener("click", function (event) {
- valida_click(btnNew);
- });
- btnNew.innerText = curChar.toUpperCase();
- keyboardContainer.appendChild(btnNew);
- if (curChar == "e" || curChar == "j" || curChar == "o" || curChar == "t" || curChar == "y") {
- keyboardContainer.appendChild(document.createElement("br"));
- }
- }
- }
- function recria_palavra() {
- sorteada = sortear();
- sorteadaCharArr = sorteada.split('');
- let container = document.getElementById("wordContainer");
- while (container.firstChild) {
- container.removeChild(container.firstChild);
- }
- for (let index = 0; index < sorteadaCharArr.length; index++) {
- let lblNew = document.createElement("label");
- lblNew.setAttribute("class", "lbl_palavra");
- lblNew.setAttribute("id", "id" + index);
- lblNew.innerText = "-";
- container.appendChild(lblNew);
- }
- }
- function showWelcome(primeiraVez) {
- if (!primeiraVez) {
- document.getElementById("lblDescription").style.display = "none";
- }
- document.getElementById("welcomeScreen").style.display = "block";
- }
- function hideWelcome() {
- document.getElementById("welcomeScreen").style.display = "none";
- }
- function start() {
- showWelcome(true);
- }
- function startGame() {
- hideWelcome();
- recria_palavra();
- recria_teclado();
- document.getElementById("lblChances2").innerText = chances = 6;
- document.getElementById("lblResult").innerText = "";
- document.getElementById("lblResult").style.color = "#0F0";
- let parte = document.getElementById("cabeca");
- parte.style.display = "none";
- parte = document.getElementById("braco_dir");
- parte.style.display = "none";
- parte = document.getElementById("braco_es");
- parte.style.display = "none";
- parte = document.getElementById("perna_dir");
- parte.style.display = "none";
- parte = document.getElementById("perna_es");
- parte.style.display = "none";
- parte = document.getElementById("corpo");
- parte.style.display = "none";
- }
- function darDica() {
- alert(sorteada);
- }
- window.addEventListener("load", start);
- </script>
- </head>
- <body>
- <label id="lblChances1" class="lbl_chances">Chances:</label>
- <label id="lblChances2" class="lbl_chances">6</label>
- <button id="btnDica" onclick="darDica()" class="btn_dica btnGame">Dica</button>
- <div id="forca_poste"></div>
- <div id="forca_aste"></div>
- <div id="corda1"></div>
- <div id="corda2"></div>
- <div id="corpo"></div>
- <div id="cabeca"></div>
- <div id="braco_dir"></div>
- <div id="braco_es"></div>
- <div id="perna_dir"></div>
- <div id="perna_es"></div>
- <div id="main_container">
- <div id="wordContainer" class="keyboard_container"></div>
- <div id="keyboardContainer" class="keyboard_container"></div>
- </div>
- <div id="welcomeScreen" class="welcome_screen">
- <label id="lblResult" class="lbl_resultado"></label>
- <label id="lblDescription">Seja bem-vindo ao jogo da forca!
- <br>Você terá 6 chances para acertar a palavra...
- <br>
- <br>Desenvolvido por Gustavo Kuze</label>
- <button id="btnStart" class="btnGame" onclick="startGame()">Jogar</button>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement