public void run() {
// TODO Auto-generated method stub
boolean flag = true;
do {
System.out.println("=======猜拳规则:=======\n1、石头\t2、剪刀\t3、布\n4、结束猜拳游戏");
System.out.println("猜拳开始\n请您出拳:");
Scanner sc = new Scanner(System.in);
Random rand = new Random();
int uPrint,cPrint;
String u = null;
//我出拳
uPrint = sc.nextInt();
switch (uPrint) {
case 1:
u = "石头";
break;
case 2:
u = "剪刀";
break;
case 3:
u = "布";
break;
case 4:
flag = false;
break;
default:
u = "选择错误!视为您不出!为输!";
break;
}
System.out.println(new GameWoldThread().getName()+"出:"+u);
//电脑出拳
cPrint = rand.nextInt(3)+1;
switch (cPrint) {
case 1:
u = "石头";
break;
case 2:
u = "剪刀";
break;
case 3:
u = "布";
break;
}
System.out.println("电脑出:"+u);
if(uPrint == cPrint){
System.out.println("您们平局!");
}else if((uPrint==1&&cPrint==2)||(uPrint==2&&cPrint==3)||(uPrint==3&&cPrint==1)){
System.out.println(new GameWoldThread().getName()+"您赢了");
}else {
System.out.println("您输了");
}
}while(flag);
new GameWoldThread().isSleep(500);
}
}