package com.wind;import java.util.Random;
import java.util.Scanner;public class ResultLei {static Random random = new Random();public static void main(String[] args) {boolean end = true;while (end) {System.out.println("请输入你选择的难度对应的数字:" + '\n' + "简单:1" + '\n' + "中等:2" + '\n' + "困难:3" + '\n' + "退出:4");Scanner sc = new Scanner(System.in);int t = sc.nextInt();switch (t) {case 1:result(9, 9, 10);break;case 2:result(16, 16, 40);break;case 3:result(16, 30, 100);break;case 4:end = false;break;default:break;}}}public static void result(int q, int w, int e) {// 定义一个二维数组用来存储地雷的数据int[][] arr = new int[e][e];// 定义一个变量存储随机出来的数据比较唯一性int x, y;// 随机出雷的数据并保证唯一性for (int i = 0; i < e; i++) {boolean one = true;x = random.nextInt(q) + 1;y = random.nextInt(w) + 1;for (int j = 0; j <= i; j++) {if (x == arr[1][j] && y == arr[2][j]) {one = false;i--;break;}}if (one) {arr[1][i] = x;arr[2][i] = y;}}// 计算非雷格的数字,并将数据输出for (int i = 1; i <= q; i++) {for (int j = 1; j <= w; j++) {boolean lei = true;for (int t = 0; t < e; t++) {if (i == arr[1][t] && j == arr[2][t]) {System.out.print("* ");lei = false;}}if (lei) {int count = 0;for (int t = 0; t < e; t++) {if (i - 1 == arr[1][t] && j - 1 == arr[2][t]) {count++;}if (i - 1 == arr[1][t] && j == arr[2][t]) {count++;}if (i - 1 == arr[1][t] && j + 1 == arr[2][t]) {count++;}if (i == arr[1][t] && j - 1 == arr[2][t]) {count++;}if (i == arr[1][t] && j + 1 == arr[2][t]) {count++;}if (i + 1 == arr[1][t] && j - 1 == arr[2][t]) {count++;}if (i + 1 == arr[1][t] && j == arr[2][t]) {count++;}if (i + 1 == arr[1][t] && j + 1 == arr[2][t]) {count++;}}System.out.print(count + " ");}}System.out.println();}}
}
扫雷小游戏纯后端版
2025/7/15 4:04:32
来源:https://blog.csdn.net/qq_49173880/article/details/140724711
浏览:
次
关键词:扫雷小游戏纯后端版
版权声明:
本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。
我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com
热文排行
- 电力物联网的电力监控系统
- `git restore` 和 `git checkout` 用于丢弃工作区的改动, `git switch` 和 `git checkout` 用来切换分支
- 《警世贤文》摘抄:处人篇、受恩篇、宽人篇、听劝篇、劝善篇(多读书、多看报、少吃零食多睡觉)
- Android显示系统(08)- OpenGL ES - 图片拉伸
- Vmess协议是什么意思? VLESS与VMess有什么区别?
- 三元组抽取在实际应用中如何处理语义模糊性?
- WPS将文字文档朗读
- 使用 Docker 在 Alpine Linux 下部署 Caddy 服务器
- Rust Web框架怎么选?
- Vue.js 项目部署全解析:从开发到上线的关键旅程题