From ca48be9db501651c7bdeb205c2dc205f96c11d86 Mon Sep 17 00:00:00 2001 From: pyxfrvnbe <2109796886@qq.com> Date: Sat, 13 Apr 2024 18:38:31 +0800 Subject: [PATCH] ADD file via upload --- src/MapTool.java | 52 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/MapTool.java diff --git a/src/MapTool.java b/src/MapTool.java new file mode 100644 index 0000000..4daaab0 --- /dev/null +++ b/src/MapTool.java @@ -0,0 +1,52 @@ +package keshe; +import java.util.Random; + +/** + * 描述: 游戏规则 ,点击选中两个相同的数字即可消除这两个数字,没有过多的复杂判断 + * MapTool.java 类用于生产数字和判断选中的两个数字是否相同 + **/ +public class MapTool { + //创建数字地图1 + public static int[][] createMap1() { + int[][] map = new int[10][10]; + Random rand = new Random(); + for (int i = 0; i < map.length; i++) { + for (int j = 0; j < map[i].length; j++) { + map[i][j] = rand.nextInt(9) + 1; + } + } + return map; + } + //创建数字地图2 + public static int[][] createMap2() { + int[][] map = new int[15][15]; + Random rand = new Random(); + for (int i = 0; i < map.length; i++) { + for (int j = 0; j < map[i].length; j++) { + map[i][j] = rand.nextInt(14) + 1; + } + } + return map; + } + //创建数字地图3 + public static int[][] createMap3() { + int[][] map = new int[20][20]; + Random rand = new Random(); + for (int i = 0; i < map.length; i++) { + for (int j = 0; j < map[i].length; j++) { + map[i][j] = rand.nextInt(19) + 1; + } + } + return map; + } + + //消除相同的方块,打印消除方块的位置 + public static int[][] removed(int[][] map, int pi, int pj, int ci, int cj) { + if (map[pi][pj] == map[ci][cj] && (pj != cj || pi != ci)) { + System.out.println("消除:map[" + ci + "][" + cj + "],map[" + pi + "][" + pj + "]"); + map[pi][pj] = 0; + map[ci][cj] = 0; + } + return map; + } +} \ No newline at end of file