Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var trattini,word,hidden;
- var tot = 0;
- var errori = 0;
- var montepremi = document.getElementById("montepremi");
- var lettere = 0;
- function setWord(){
- word = document.getElementById("word").value;
- hidden = document.getElementById("hidden");
- trattini = word.replace(/./g, "-");
- hidden.innerHTML = trattini;
- }
- function checkWord(){
- var wordInput = document.getElementById("guess").value;
- var ciclo = 0;
- var indovinato = false;
- if(errori <= 10)
- {
- for(var i=0;i<word.length;i++)
- {
- if(trattini.indexOf("-") < 0)
- {
- while(!confirm("Hai vinto! Premi OK per una nuova partita"));
- location.reload();
- break;
- }
- else if(word.indexOf(wordInput, i) > -1)
- {
- trattini = replaceCharAt(trattini,wordInput,word.indexOf(wordInput, i));
- if(ciclo === 0)
- {
- premio();
- lettere++;
- }
- indovinato = true;
- ciclo++;
- }
- else{
- if(indovinato === false)
- {
- errori++;
- sbagliato(errori);
- }
- ciclo++;
- return;
- }
- hidden.innerHTML = trattini;
- }
- }
- }
- function premio(){
- var random = Math.floor((Math.random() * 100) + 1);
- alert("Hai indovinato! Guadagni "+random+" Euro!");
- tot += random;
- montepremi.innerHTML = "Il tuo montepremi ammonta a "+tot+" Euro!";
- }
- function sbagliato(errori){
- var random = Math.floor((Math.random() * 100) + 1);
- var immagine = document.getElementById("impiccato");
- tot -= random;
- var impiccato = ["./img/0.bmp","./img/1.bmp","./img/2.bmp","./img/3.bmp","./img/4.bmp","./img/5.bmp","./img/6.bmp","./img/7.bmp","./img/8.bmp","./img/9.bmp","./img/10.bmp"];
- alert("Mi dispiace, hai sbagliato. Perdi "+random+" Euro");
- if(errori <= 10)
- {
- immagine.src = impiccato[errori];
- }
- else
- {
- while(!confirm("Hai perso! Premi OK per una nuova partita"));
- location.reload();
- }
- montepremi.innerHTML = "Il tuo montepremi ammonta a "+tot+" Euro";
- }
- function replaceCharAt(string,letter,index){
- return string.substring(0, index) + letter + string.substring(index + 1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement