package game;
import jdk.internal.instrumentation.Logger;
import java.util.Random;
import java.util.Scanner;
public class CaiQuran{
public CaiQuran()
{
}
public static void main(String[] args) {
int a = 0;//平局次数
int b = 0;//玩家输次数
int c = 0;//玩家赢次数
System.out.println("游戏开始");
System.out.println("剪刀 石头 布");
Scanner sc =new Scanner(System.in);
for(int i = 1; i <= 5; ++i) {
System.out.println("第" + i + "局");
String enter = sc.next();
int randomNumber = (new Random()).nextInt(3) + 1;
if (enter.equals("剪刀")) {
if (randomNumber == 1) {
System.out.println("本局电脑出的是剪刀");
System.out.println("平局");
++a;
} else if (randomNumber == 2) {
System.out.println("本局电脑出的是石头");
System.out.println("你输了");
++b;
} else if (randomNumber == 3) {
System.out.println("本局电脑出的是布");
System.out.println("你赢了");
++c;
}
} else if (enter.equals("石头")) {
if (randomNumber == 1) {
System.out.println("本局电脑出的是剪刀");
System.out.println("你赢了");
++c;
} else if (randomNumber == 2) {
System.out.println("本局电脑出的是石头");
System.out.println("平局 ");
++a;
} else if (randomNumber == 3) {
System.out.println("本局电脑出的是布");
System.out.println("你输了");
++b;}
} else if (enter.equals("布")) {
if (randomNumber == 1) {
System.out.println("本局电脑出的是剪刀");
System.out.println("你输了");
++b;
} else if (randomNumber == 2) {
System.out.println("本局电脑出的是石头");
System.out.println("平局 ");
++a;
} else if (randomNumber == 3) {
System.out.println("本局电脑出的是布");
System.out.println("你赢了");
++c;}
}
}
System.out.println("电脑赢了" + b + "局");
System.out.println("你总共赢了" + c+ "局," + "平了" + a + "局");
if (b == c) {
System.out.println("结果为平局");
} else if (c > b) {
System.out.println(" 结果你赢了!");
} else System.out.println("结果你输了!");
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)