import java.util.Scanner;
import java.util.Random;
public class Gungame{
static Scanner sr=new Scanner(System.in);
static int a1=3;
static int a2=3;
static String player1,player2;
static String[] dao={"香烟","上帝的帮助","手铐","汽水","放大镜","小刀"};
static public void main(String[] args)throws InterruptedException{
System.out.println("欢迎来到俄罗斯转盘赌!每人有三条命");
System.out.println("输入玩家1名字");
player1=sr.nextLine();
System.out.println("输入玩家2名字");
player2=sr.nextLine();
while(a1!=0||a2!=0){
System.out.print("现在开始装弹");
for(int i=1;i<=3;i++){
Thread.sleep(500);
System.out.print(".");
Thread.sleep(500);
System.out.print(".");
Thread.sleep(500);
System.out.print(".");
Thread.sleep(500);
System.out.print("\n\n\n\n\n\n\n\n\n\n\n");
System.out.println("欢迎来到俄罗斯转盘赌!每人有三条命");
}
System.out.println("装弹完毕,五发实弹-五发虚弹");
double s=10,d=5,t=1;
double k=d*1.0/s*100.0;
do{
Random rand=new Random();
int h=rand.nextInt(100);
boolean flag=true;
System.out.println(player1+"的生命数:"+a1+" "+player2+"的生命数:"+a2);
if(t==1){System.out.println(player1+"要打谁?\n1:自己\n2:对方");}
else {System.out.println(player2+"要打谁?\n1:自己\n2:对方");}
int dan=sr.nextInt();
if(dan==1){flag=false;}
if((t==1&&h<=k&&dan==1)||(t==0&&h<=k&&dan==2)){
System.out.println(player1+"的生命数减一");
s--;
d--;
a1--;
if(a1==0){System.out.print(player2+"胜利,得到了10000000000美元,"+player1+"则化为了地狱的亡魂。");return;}
}else if((t==0&&h<=k&&dan==1)||(t==1&&h<=k&&dan==2)){
System.out.println(player2+"的生命数减一");
s--;
d--;
a2--;
if(a2==0){System.out.print(player1+"胜利,得到了10000000000美元,"+player2+"则化为了地狱的亡魂。");return;}
}else{
System.out.println("大家都安然无恙");
s--;
}
Thread.sleep(1500);
System.out.println("\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
if(flag){
if(t==1){t=0;}
else {t=1;}
}
if(s==0){break;}
k=d/s*100;
}while(a1!=0||a2!=0);
if(a2==0){
System.out.print(player2+"胜利,得到了10000000000美元,"+player1+"则化为了地狱的亡魂。");
return;
}else{
System.out.print(player1+"胜利,得到了10000000000美元,"+player2+"则化为了地狱的亡魂。");
return;
}
Random ran = new Random();\\!!!!!!!!!!!!!!!!??????????他一直显示 错误: 无法访问的语句
int d_num=ran.nextInt(5);
System.out.println(player1+"获得了道具:"+dao[d_num]);
ran=new Random();
d_num=ran.nextInt(5);
System.out.println(player2+"获得了道具:"+dao[d_num]);
}
}
}
各位,请问这是为什么,本人已经想了三天三夜了。
附:编译器为 Visual Studio Code