代码未精简,只做了简单验证,如有错误,还请指正。
欢迎XXX进入猜拳游戏
1.石头 2.剪刀 3.布 0.退出
请输入数字:
/* 此时等待用户输入数字,每个数字代表不同的效果,整个程序只有当用户输入0时才可以退出 否则不允许停止程 序,当用户输入> 1-3之间某个数字的时候,需要和电脑系统AI进行猜拳对比,并对用户输出反馈效果 查看如果做 1~3之间数据获取操作*/
欢迎XXX进入猜拳游戏
1.石头 2.剪刀 3.布 0.退出
请输入数字:
1
如果赢了 提示 恭喜你赢了
如果输了 提示 你输了
如果平局 提示 平局再来
//输入提示语句之后 需要再次显示 以下界面
欢迎XXX进入猜拳游戏
1.石头 2.剪刀 3.布 0.退出
请输入数字:
/*
当用户输入0是,猜拳游戏结束,输出以下界面,需要打印谁玩的,玩了多少局,赢了多少场,胜率是多少
*/
排行榜
****************************************************************** 姓名 总局数 赢场 胜率
XXX 0 0 xx%
import java.util.Scanner;
public class TwentySix {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
boolean choice1 = true;
int playtimes = 0;
int winNumber = 0;
int rival = 0;
do {
System.out.println("************************************************************");
System.out.println("欢迎ThreeGoldXD进入猜拳游戏");
System.out.println("1.石头 2.剪刀 3.布 0.退出");
System.out.println("************************************************************");
System.out.println("请输入数字:");
int choice = input.nextInt();
if (choice == 0) {
choice1 = false;
double winRate = (double) ((double) winNumber / (double) playtimes);
double winRate1 = (double) Math.round(winRate * 100) / 100; //保留两位小数
System.out.println(" 排行榜 ");
System.out.println("******************************************************************");
System.out.println("姓名" + "\t\t" + "总局数" + "\t" + "胜场" + "\t" + "胜率");
System.out.println("ThreeGoldXD" + "\t " + playtimes + "\t\t " + winNumber + "\t\t" + (int) (winRate1 * 100) + "%");
} else if (choice == 1 || choice == 2 || choice == 3) {
playtimes++;
rival = (int) (Math.random() * 3 + 1);
System.out.println("-------------------");
if (choice == 1) System.out.print("|您:✊ VS");
else if (choice == 2) System.out.print("|您:✌ VS");
else if (choice == 3) System.out.print("|您:🖐 VS");
if (rival == 1) System.out.println(" 电脑:✊|");
else if (rival == 2) System.out.println(" 电脑:✌|");
else if (rival == 3) System.out.println(" 电脑:🖐|");
if (choice == rival) System.out.println("-----平局再来------");
else {
choice++;
if (choice > 3) choice = 1;
if (choice == rival) {
System.out.println("----恭喜您赢了-----");
winNumber++;
} else System.out.println("------您输了-------");
}
} else System.out.println("输入错误,请重新输入");
System.out.println();
System.out.println();
} while (choice1);
}
}