day03_小游戏剪刀石头布
作者:互联网
关于剪刀石头布小游戏的demo,闲得无聊,,,
package day03;
import java.util.Random;
import java.util.Scanner;
public class CaiQuanGame {
public static void main(String[] args) {
//机器:0拳头 1布 2剪刀
Scanner input = new Scanner(System.in);
Random input2 = new Random();
String juding="是";
int count =0;
int count1=0;
int sum=0;
System.out.println("三局两胜猜拳现在开始!");
while(!juding.equals("否")&&count!=2){
int jiqi = input2.nextInt(3);
System.out.println("请输入你的出拳方式:");
String ren = input.next();
if((ren.equals("拳头")&&jiqi==2)||(ren.equals("布")&&jiqi==0)||(ren.equals("剪刀")&&jiqi==1)){
count++;
System.out.println("大佬牛批!");
}else if((ren.equals("拳头")&&jiqi==0)||(ren.equals("布")&&jiqi==1)||(ren.equals("剪刀")&&jiqi==2)){
System.out.println("平局");
}else{
count1++;
System.out.println("你这个菜鸡,连机器都打不过");
}
sum++;
if(sum==3){
break;
}
System.out.println("请问还要继续嘛?");
juding = input.next();
}
System.out.println();
System.out.println("三局两胜的结果:");
if(count==2){
System.out.print("恭喜大佬赢了!");
}else if(count1==2){
System.out.print("机器大获全胜!");
}
else{
System.out.print("你和机器平局");
}
}
}
标签:day03,System,equals,小游戏,ren,&&,println,剪刀,out 来源: https://blog.csdn.net/xiaoyoupei/article/details/110200322