0
我需要幫助使我的猜謎遊戲給你選擇哪個難度,有人可以修復我的代碼並重新發布,因爲我現在有點迷路了!需要幫助修復在java中猜謎遊戲的難度選擇
import java.util.*;
public class GuessingGame
{
public static void main(String[] args)
{
boolean play = true;
String input1;
while(play == true){
Scanner input = new Scanner(System.in);
Random rand = new Random();
int counter = 0;
int guess = -1;
int dif = 0;
int easy = rand.nextInt(10) + 1, med = rand.nextInt(1000) + 1, hard = rand.nextInt(10000) + 1;
System.out.println("Difficulty Select");
System.out.println("=================");
System.out.print("1) Easy 2) Medium 3) Hard :");
dif = input.nextInt();
switch (dif)
{
case 1:
if (dif == 1)
System.out.println ("Random number between 1 and 10 selected." + easy);
else if (dif == 3)
System.out.println ("Random number between 1 and 10000 selected.");
break;
}
while (guess != med)
{
System.out.print ("|" + med + "|" + "Random number between 1 and 1000 selected.");
guess = input.nextInt();
counter = counter + 1;
if (guess == med)
System.out.println ("YOU WIN MOFO!");
else if (guess < med)
System.out.println ("You're to cold!");
else if (guess > med)
System.out.println ("You're to hot!");
}
System.out.println ("It took you " + counter + " guess(es) to get it correct");
System.out.print ("Do you want to play again? (y/n): ");
input1 = input.nextLine(); // absorb enter key from integer
input1 = input.nextLine();
if (input1.equals("y"))
play = true;
else
play = false;
}
}
}
你的問題應該總是包括你的程序應該做什麼以及它目前做什麼。如果他們必須猜測所有這些,那麼這裏的用戶將不會樂意幫助你。 –
如果發生崩潰,堆棧跟蹤將幫助 –
*「有人可以修復我的代碼並重新發布,因爲我現在有點迷路了!」* SO不是'完成我的作業'服務。問一個更具體的問題,因爲這個問題可能會被關閉。 –