import java.util.Scanner;
public class MyGame {
public static void main(String[] args) {
String username = "匿名用户";
Scanner scanner = new Scanner(System.in);
System.out.println("************************");
System.out.println(" 游戏: 算24");
System.out.println(" 版本:v1.0");
System.out.println("************************");
scanner.nextLine();
System.out.println("请输入玩家的用户名:");
username = scanner.nextLine().trim();
if (username.isEmpty()) {
username = "匿名用户";
}
while (true) {
for (int i = 0; i < 4; i++) {
int num = (int) (Math.random() * 13 + 1);
switch (num) {
case 11:
System.out.print("J" + "\t");
break;
case 12:
System.out.print("Q" + "\t");
break;
case 13:
System.out.print("K" + "\t");
break;
default:
System.out.print(num + "\t");
}
}
System.out.println();
System.out.println("请输入通过加减乘除计算24的方法:");
String computer_line = scanner.nextLine();
// 判断输入算式的合法性,这里仅作简单示例,实际应用中需要更复杂的判断逻辑
if (!computer_line.matches("[0-9+\\-*/\\s]+")) {
System.out.println("输入的算式不合法,请重新输入。");
continue;
}
System.out.println("你的算式:" + computer_line);
System.out.println("请按回车键确认或输入'n'退出游戏。");
String ch = scanner.nextLine().toLowerCase();
if (ch.equals("n")) {
break;
}
}
scanner.close();
}
}
用java实现拍24小游戏
最新推荐文章于 2024-11-11 21:19:25 发布