//兩人決鬥
public class TestDuel {
public static void main(String[] args)throws InterruptedException {
//宣告陣列並設初始值
boolean[] flags = {true,false};
int totalRound = 20;
int theRed = 0; //TheRed 累進步數
int theBule = 0; //TheBule
*** int[] tenRound = {true,false};
System.out.println("<< 雙方決鬥開始 >>");
while(theRed<totalRound && theBule<totalRound){
Thread.sleep(1000); //要處理 InterruptedExcetion(check exception)
theRed++; //代表紅方攻一回合
System.out.printf("紅方攻了%2d 回合...%n",theRed);
boolean isBuleStay = flags[((int)(Math.random()*10))%2];
**** boolean One hit kill =tenRound[((int)(Math.random()*(20-10+1)+10))];
if(isBuleStay){
System.out.println("藍方恍神 @ @ @ @ @ @");
**** }else if(One hit kill){
System.out.println("藍方失血過多死亡~~我竟然敗了~~");
break;
}
else{
theBule += 2; //代表藍方攻擊兩次
System.out.printf("藍方攻了%2d 回合....%n",theBule);
}
}//end of while
System.out.println("<<決鬥結束>>\n");
//三元條件運算子(比較條件 ? ture:false)
String win = theRed > theBule ?"菜鳥":"高手";
System.out.println(win+"=>獲得勝利了...");
}
}//end of Dule
帶*號的就是我要問的問題
我想寫一個可以在10回合後對手有可能會被一擊必殺,但是用if寫一直提示要boolean型別才能,不知道該怎麼寫
有誰可以幫幫我
This entry passed through the Full-Text RSS service — if this is your content and you're reading it on someone else's site, please read the FAQ at fivefilters.org/content-only/faq.php#publishers.
留言列表