Ich erstelle ein Programm, mit dem Sie ein Spiel ähnlich wie Papier, Schere Rock spielen können.Mit While-Schleife in Programm
Das Spiel funktioniert, aber ich versuche, eine Schleife in den Code zu integrieren, der den Benutzer fragt, ob sie weiterspielen möchten.
Wenn ja, werden sie nach einem anderen Eingang gefragt. Wenn nein, wird das Programm einfach "Danke für die Wiedergabe von" state
Hier ist der Code:
import java.util.Scanner;
import java.util.Random;
public class OkekpeJMoropinzee
{
public static void main(String[]args)
{
String yourMove;
String compMove;
int compInt;
String[] characters = {"Monkey","Robot","Pirate","Ninja","Zombie"};
Scanner input = new Scanner(System.in);
Random rand = new Random(6);
compInt = rand.nextInt(5)+1;
if (compInt == 1)
compMove = "Monkey";
else if (compInt == 2)
compMove = "Robot";
else if (compInt == 3)
compMove = "Pirate";
else if (compInt == 4)
compMove = "Ninja";
else if (compInt == 5)
compMove = "Zombie";
System.out.println("What do you choose?: ");
yourMove = input.next();
//MONKEY
if(yourMove == "Monkey" || compInt == 1)
System.out.println("Tie");
else if (yourMove== "Monkey" || compInt == 2)
System.out.println("You Win! Monkey Unplugs Robot!");
else if (yourMove=="Monkey" || compInt == 3)
System.out.println("You Lose! Pirate Skewers Monkey!");
else if (yourMove == "Monkey" || compInt==4)
System.out.println("You Win! Monkey fools Ninja!");
else if (yourMove== "Monkey" || compInt==5)
System.out.println("You Lose! Zombie savages monkey!");
//RoBOT
else if(yourMove == "Robot" || compInt == 2)
System.out.println("Tie");
else if (yourMove== "Robot" || compInt == 1)
System.out.println("You Lose! Monkey Unplugs Robot!");
else if (yourMove=="Robot" || compInt == 3)
System.out.println("You Lose! Pirate Drowns Robot!!");
else if (yourMove == "Robot" || compInt==4)
System.out.println("You Win! Robot Chokes Ninja");
else if (yourMove== "Robot" || compInt==5)
System.out.println("You win! Robot Crushes Zombie!");
//PIRATE
else if(yourMove == "Pirate" || compInt == 3)
System.out.println("Tie");
else if (yourMove== "Pirate" || compInt == 1)
System.out.println("You Win! Pirate Skewers Monkey!");
else if (yourMove=="Pirate" || compInt == 2)
System.out.println("You Win! Pirate Drowns Robot!");
else if (yourMove == "Pirate" || compInt==4)
System.out.println("You Lose! Ninja Karate Chops Pirate!");
else if (yourMove== "Pirate" || compInt==5)
System.out.println("You Lose! Zombie Eats Pirate!");
//NINJA
else if(yourMove == "Ninja" || compInt == 4)
System.out.println("Tie");
else if (yourMove== "Ninja" || compInt == 1)
System.out.println("You Lose! Monkey Fools Ninja!");
else if (yourMove=="Ninja" || compInt == 2)
System.out.println("You Lose! Robot Chokes Ninja!");
else if (yourMove == "Ninja" || compInt==3)
System.out.println("You Win! Ninja Karate Chops Pirate!");
else if (yourMove== "Ninja" || compInt==5)
System.out.println("You Win! Ninja Decapitates Zombie!");
//ZOMBIE
else if(yourMove == "Zombie" || compInt == 5)
System.out.println("Tie");
else if (yourMove== "Zombie" || compInt == 1)
System.out.println("You Win! Zombie Savages Monkey!");
else if (yourMove=="Zombie" || compInt == 2)
System.out.println("You Lose! Robot Crushes Zombie!");
else if (yourMove == "Zombie" || compInt==3)
System.out.println("You Win! Zombie Eats Pirate!");
else if (yourMove== "Zombie" || compInt==4)
System.out.println("You Lose! Ninja Decapitates Zombie!");
}
}
Wow, das war extrem hilfreich. Vielen Dank! Ich dachte, dass mein Code funktionierte, bis ich tatsächlich versuchte, es zu spielen, und es funktionierte nicht, lol. Vielen Dank für Ihre Hilfe –