java----猜拳(10局分胜负)

package learning;
import java.util.*;
public class Guess{
public static void main(String [] args){
int j=0;
while(j<4){
int count1=0;
int count2=0;
int count3=0;
for(int i=1;i<11;i++){
System.out.println("-------猜拳游戏-------");
System.out.println("第"+i+"局");
System.out.println("请出拳:(1.剪刀 2.石头 3.布)");
Scanner in = new Scanner(System.in);
int person = in.nextInt();
int computer = (int)(Math.random()*3+1);
String marks = "拳头";
String marks2 = "拳头";
switch(person){
case 1:
marks = "剪刀";
break;
case 2:
marks = "石头";
break;
case 3:
marks = "布";
break;
}
switch(computer){
case 1:
marks2 = "剪刀";
break;
case 2:
marks2 = "石头";
break;
case 3:
marks2 = "布";
break;
}
if (person==computer){
System.out.println("平局,"+"你出的是"+marks+",电脑出的是"+marks2);
count1 =count1+1;
}
else if (person==1&&computer==2||person==2&&computer==3||person==3&&computer==1){
System.out.println("你输了,"+"你出的是"+marks+",电脑出的是"+marks2);
count2 =count2+1;
}
else {
System.out.println("你赢了,"+"你出的是"+marks+",电脑出的是"+marks2);
count3 =count3+1;
}
System.out.println("你赢了"+count3+"局,"+"你输了"+count2+"局,"+"平局"+count1+"局");
}
if(count3>count2){
System.out.println("恭喜你,你赢了!");
break;
}
if(count3<count2){
System.out.println("很遗憾,你输了!");
break;
}
if(count3==count2){
System.out.println("棋逢对手,平局!再来一次吧!");
j++;
continue;
}
}
}
}

posted @ 2018-05-28 12:31  业余py  阅读(200)  评论(0编辑  收藏  举报