I created second method named displayOption2(); So I want to concentrate my displayOption2(); As you see i have new three options at ("1. Previous Game.") I need to go back my last chosen option. while at ("2. Starting New Game"); starts the game again, and at ("3. Exit the Game"); will only the option can end the game.
public static void main(String[] args) { Scanner reading = new Scanner(System.in); System.out.println(" Welcome UCT beginers Game we will test your IQ "); displayOption(); int input = reading.nextInt();
switch (input){
case 3:
System.out.println(" Welcome You will have three chances to play; Please Guess my number");
break;
case 5:
System.out.println(" Welcome You will have Five chances to play; Please Guess my number");
break;
case 10:
System.out.println(" Welcome You will have Ten chances to play; Please Guess my number");
break;
case 4:
System.out.println("Game-kii waad ka baxday, Macsalaamo!");
System.exit(0);
break;
default:
System.out.println("Lambar Khaldan ayaa galisay, Please try again");
System.exit(0);
break;
}
int randomNumber = (int) (Math.random() * 50 - 1);
int guessNumber = reading.nextInt();
for (int a = 1; a < input; a++) {
if (randomNumber == guessNumber ){
System.out.println(" Congratulation; You have earned "+input+" coins");
break;
}
else if (randomNumber > guessNumber ){
System.out.println(" Sorry Low number ("+ a + "/"+input+")");
}
else if (randomNumber < guessNumber){
System.out.println(" Sorry High number ("+ a + "/"+input+")");
}
guessNumber = reading.nextInt();
}
if(randomNumber != guessNumber) {
System.out.println("Sorry! we can't help you any more, You failed *****The number was "+ randomNumber);
}
}
public static void displayOptions(){
System.out.println("");
System.out.println("");
System.out.println(" Please select your level Game ");
System.out.println("3. Three chances to play.");
System.out.println("5. Five chances to play");
System.out.println("10. Ten chances to play");
System.out.println("4. Exit the Game");
}
public static void displayOptions(){
System.out.println("");
System.out.println("");
System.out.println(" We offered you these new options, please make your choice! ");
System.out.println("1. Previous Game.");
System.out.println("2. Starting New Game");
System.out.println("3. Exit the Game");
}
}
Aucun commentaire:
Enregistrer un commentaire