随机游戏
只是用输赢计算修改了一下。
导入Java . util . random;
导入Java . util . scanner;
公共类游戏{
私有静态int win = 0;
私有静态int fail = 0;
private static int pi = 0;
私有静态void检查(int cpu,int pe){
int t = 0;
if(PE-CPU = = 2)t =-1;
else if(PE-CPU = =-2)t = 1;
else t = PE-CPU;
if(t & gt;0) {System.out.println("你赢了!");win++;}
Elseif (t = = 0) {system。out.println("我们扯平了!");pi++;}
Else {System.out.println("你输了!");fail++;}
}
公共静态void main(String[] args) {
字符串输入= " ";
字符串cpuStr =
Random rand = new Random();
int CPU = 0;
int PE = 0;
while(true){
系统。out . println(" * * * * * * * * * * * * * * * * * * * * * * * * *);
System.out.println("请选择你想要的?f-剪刀(forfex)、S-石头(stone)、C-布(cloth)”);
扫描仪扫描=新扫描仪(system . in);
input = scan . nextline();
CPU = rand . nextint(3);
If(cpu==0)cpuStr= "剪刀";
else if(CPU = = 1)cpuStr = " stone ";
Else cpuStr = " cloth
if(input . equals(" F ")| | input . equals(" F ")){
PE = 0;
System.out.println("你给的是剪刀");
System.out.println("我出"+cpuStr);
检查(cpu,PE);
} else if(input . equals(" S ")| | input . equals(" S "){
PE = 1;
System.out.println("你出的是石头");
System.out.println("我出"+cpuStr);
检查(cpu,PE);
} else if(input . equals(" C ")| | input . equals(" C ")){
PE = 2;
System.out.println("你给的是布");
System.out.println("我出"+cpuStr);
检查(cpu,PE);
} else if(input . equals(" E ")| | input . equals(" E "){
System.out.println("结束游戏。。");
System.out.println("结果统计:");
system . out . println(" win:"+win+" bureau ");
System.out.println("负数:"+fail+" bureau ");
system . out . println(" Ping:"+pi+" Bureau ");
system . exit(0);
}
}
}
}