第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Hangman 游戲相同的字母驗證僅 javascript

Hangman 游戲相同的字母驗證僅 javascript

Smart貓小萌 2022-12-29 09:35:44
我需要我的幫助,hangman game如果玩家之前猜了重復的字母,我如何阻止生命下降,至于現(xiàn)在如果我運行它并且玩家猜測相同的字母,它會輸出他已經(jīng)做出了這個猜測但生命也在下降. 另外,如果玩家一直輸入相同的正確字母,它會輸出他已經(jīng)猜對了,但在輸入相同的字母 4-5 次后會說他贏了。第一個錯誤:lives dropping even if players use letter that is guessed before第二個錯誤:players input the same correct letter guessed and game will say he won after inputting 4-5 times代碼guesses = [];// Show player their progress | .join returned answer as a stringwhile (remainingLetters > 0 && lives > 0) {    (answerArray.join(""));    guess = readline.question(name+"'s guess (Enter 9 for lifelines or 0 to pass): ");    guess = guess.toUpperCase();    //if guess is more than 1 letter or no letter, alert player to guess 1 letter only    if (guess.length !== 1) {        console.log("Please enter 1 letter only.");    }    //if valid guess    else {        correctGuess = 0;        for (var j = 0; j < Word.length; j++) {            if (Word[j] == guess) {                answerArray[j] = guess;                remainingLetters--;                correctGuess = 1;            }        }        if (correctGuess == 1) {                console.log("\nGood job! "+guess+" is one of the letters!\n");                console.log(JSON.stringify(answerArray)+"\n");                console.log(JSON.stringify(alphabets)+"\n");        } else {            lives -= 1;            console.log("\nSorry. "+guess+" is not a part of the word.\n");            console.log(JSON.stringify(answerArray)+"\n");            console.log(JSON.stringify(alphabets)+"\n");            console.log("You have "+lives+" lives remaining.\n");        }                if (guesses.includes(guess)) {            console.log("You have already made this guess, please try another letter!\n");        } else {            guesses.push(guess)        }    }    if (remainingLetters == 0) {        console.log("Congratulation! You managed to guess the word!\n");        break;    }        if (lives == 0) {        console.log("Game Over... You failed to guess the word. The word is "+Word+".\n")    }    }
查看完整描述

1 回答

?
ibeautiful

TA貢獻1993條經(jīng)驗 獲得超6個贊

Insideelse用于valid guess將您的整個代碼移動else到if (guesses.includes(guess)) {. 它將解決您的兩個問題。


// Show player their progress | .join returned answer as a string

while (remainingLetters > 0 && lives > 0) {

  (answerArray.join(""));


  guess = readline.question(name + "'s guess (Enter 9 for lifelines or 0 to pass): ");

  guess = guess.toUpperCase();


  //if guess is more than 1 letter or no letter, alert player to guess 1 letter only

  if (guess.length !== 1) {

    console.log("Please enter 1 letter only.");

  }


  //if valid guess

  else {

    if (guesses.includes(guess)) {

      console.log("You have already made this guess, please try another letter!\n");

    } else {

      guesses.push(guess);

      correctGuess = 0;

      for (var j = 0; j < Word.length; j++) {

        if (Word[j] == guess) {

          answerArray[j] = guess;

          remainingLetters--;

          correctGuess = 1;

        }

      }


      if (correctGuess == 1) {

        console.log("\nGood job! " + guess + " is one of the letters!\n");

        console.log(JSON.stringify(answerArray) + "\n");

        console.log(JSON.stringify(alphabets) + "\n");

      } else {

        lives -= 1;

        console.log("\nSorry. " + guess + " is not a part of the word.\n");

        console.log(JSON.stringify(answerArray) + "\n");

        console.log(JSON.stringify(alphabets) + "\n");

        console.log("You have " + lives + " lives remaining.\n");

      }

    }

  }


  if (remainingLetters == 0) {

    console.log("Congratulation! You managed to guess the word!\n");

    break;

  }

  

  if (lives == 0) {

    console.log("Game Over... You failed to guess the word. The word is " + Word + ".\n")

  }


}


查看完整回答
反對 回復 2022-12-29
  • 1 回答
  • 0 關注
  • 95 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號