我需要帮助 我是 Java 编程新手,但我不知道如何修复我的代码。
我正在尝试制作007游戏。我已经创建了if
语句并且它没有循环。如果我在-循环!
中的每个语句前面添加一个,它会导致一个无限循环。do
while
我怎样才能修复我的编程。
import java.util.Scanner;
import java.util.Random;
public class DoubleOSeven {
public static void main(String[] args) {
System.out.println("Let's Play a game of 007 ");
System.out.println("You can SHOOT, BLOCK, AND RELOAD");
System.out.println("Both you and I start with one bullet");
Scanner input = new Scanner(System.in);
System.out.println("Let's Start, Enter (shoot, reload , or block) ");
String INput = input.nextLine();
//User and Computer ammo
int Userammo = 1;
int ammo = 1;
//Creates a random number between 1 and 3
Random rand = new Random();
int output = rand.nextInt(3) + 1;
do{
//User chooses shoot
if(INput.equals("shoot")){
Userammo --;
System.out.println("You took a shot, Your ammo count is at: " + Userammo);
//User chooses reload
}else if (INput.equals("reload")){
Userammo ++;
System.out.println("You reloaded, Your ammo count is at: " + Userammo);
//User chooses block
}else if(INput.equals("block")){
System.out.println("You blocked, Your ammo count is at: " + Userammo);
//If random is 1 shoot
}if(output == 1){
ammo ++;
System.out.println("I took a shot at you, My ammo count is at: " + ammo);
//If random is 2 block
}else if(output == 2){
System.out.println("I blocked, My ammo count is at: " + ammo);
//If random is 3 reload
}else if(output == 3){
ammo ++;
System.out.println("I reloaded, My ammo count is at: " + ammo);
//If both User and Computer shoot
}if(output == 1 && INput == "shoot"){
System.out.println("It's a tie you we both die");
}
}while((output == 3 && INput == "shoot") && (output == 1 && INput == "reload") && (output == 1 && INput == "shoot"));
}
}