赋值出现了问题,运行出现了错误
//人机对战,石头剪刀布
/*规则:
1.一共对弈5局,5局3胜,打印赢家,玩家还是人机
2.可以选择任意1名人机进行对弈,比如:曹操,刘备,孙权
3.用面向对象的思想来写
=================================================
输入
石头
剪刀
布
机器
输入
石头
剪刀
布
你再判断
谁赢
1 = 石头
2 = 剪刀
3 = 布
现象
玩家赢
平局
机器赢
记录
各自
得分
选择一名机器人
输入代号
1.曹操,2.刘备,3.孙权
1.玩家赢
2.曹操赢
*/
package games;
import java.util.Scanner;
public class stjdb {
private String name;
public static void main(String[] args) {
// TODO Auto-generated method stub
int t=1;
int human;
String name = null;
int computer=1;
int d=0;
int e=0;
int f=0;
int x=1;
try (Scanner rc = new Scanner(System.in)) {
//选择任意1名人机进行对弈,比如:曹操,刘备,孙权
System.out.println(" a= 曹操, b= 刘备, c= 孙权");
System.out.print("请你选择:");
stjdb a=new stjdb();
stjdb b=new stjdb();
stjdb c=new stjdb();
a.name="曹操";
b.name="刘备";
c.name="孙权";
computer= rc.nextInt();
while (x<=5){
System.out.println("------------第"+ t++ +"回合------------");
System.out.println(" 1=石头, 2=剪刀, 3=布, 其他数字=退出游戏...");
System.out.print("请你出拳:");
human = rc.nextInt();
if(human>3||human<1) break;
computer = (int) (Math.random() * (3-1)+1);
System.out.println(name+"的出拳是:"+computer);
if(computer==human){
System.out.println("-->平局");
d++;}
else if(human==1&&computer==2||human==2&&computer==3||human==3&&computer==1) {
System.out.println("-->你赢了");
e++;}
else{
System.out.println("-->你输了");
f++;}
}
}
System.out.println("你的战绩是 输:"+ d+",赢:"+ e+",平:"+f+",游戏结束~");
}
}
运行如下: