对于正在从事的Hangman游戏,我有以下while循环:
while(amountOfGuessesLeft > 0 || !wordComplete){
System.out.println("The word now looks like this: " + filteredWord);
System.out.println("You have " + amountOfGuessesLeft + " guesses left");
System.out.print("Your guess: ");
try {
guess = br.readLine();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(guess.length() == 0 || guess.length() > 1){
System.out.println("Please just type one letter. Try again.");
}else if(wordSelected.contains(guess) || wordSelected.contains(guess.toUpperCase())){
System.out.println("That guess is correct.");
filteredWord = showGuess(filteredWord, wordLetters, guess.toUpperCase().charAt(0));
if(!filteredWord.contains("_")){
wordComplete = true;
}
}else{
System.out.println("There are no " + guess.toUpperCase() + "'s in this word.");
amountOfGuessesLeft--;
}
}
当while循环条件为amountOfGuessesLeft> 0时,一切正常。但是,当我添加||时!wordComplete,将不应用任何条件,并且循环永远不会结束。它也不会引发任何错误。任何帮助将不胜感激。
答案 0 :(得分:3)
您需要使用#netbanking_branches {
margin: 0 0px 0 10px;
}
.netbanking_button {
background-position: -58px -643px;
height: 35px;
width: 200px;
}
#netbanking_branches,
.netbanking_button {
float: left;
}
.netbanking_button,
.netbanking_button_up {
background-image: url("https://corp.onlinesbi.com/personal/images/sprite_a.png") ! important;
background-repeat: no-repeat;
}
#netbanking_popup {
border-bottom: 5px solid #cbcbcb;
z-index: 1000;
left: 0px;
top: 0px;
background: #d9d9d9 url("https://corp.onlinesbi.com/personal/images/netbanking_repeat.png" repeat-x;
width: 100%;
}
#netbanking_content {
background: url("https://corp.onlinesbi.com/personal/images/netbanking_img.png") no-repeat left top;
height: 123px;
padding: 10px 0 0 255px;
color: #6f6f6f;
line-height: 20px;
}
#netbanking_content_heading {
color: #0197c0;
font-size: 15px;
font-weight: bold;
margin: 5px 0;
}
#netbanking_popup,
.product_content {
display: none;
}
#netbanking_popup {
position: absolute;
}
#netbanking_content_heading {
font-size: 13px;
}
。
只要有任何猜测,并且用户还没有找到单词,您就希望运行循环。
当前,如果您用尽了所有猜测而仍未找到该词,<!-- Header core info -->
<div id="netbanking_branches" class="netbanking_branches">
<a href="" class="netbanking_button" title="Netbanking Branches" tabindex="4"> </a>
<div id="netbanking_popup">
<div id="netbanking_content">
<div id="netbanking_content_heading">
<p>contant</p>
</div>
</div>
</div>
<!-- Header core info Ends-->
将得出&&
,并允许循环再次执行。