- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在创建一个 Java 的 Java 实现来娱乐,并且当您单击其中的一个池时,我尝试填充全零。 (玩扫雷看看我在说什么)
这是我的递归调用:
private void revealZeros(int x, int y) {
if (board[y][x].revealed)
return;
board[y][x].revealed = true;
if (y > 0) {
if (x > 0)
if (!board[y - 1][x - 1].revealed && board[y - 1][x - 1].b == 0)
revealZeros(y - 1, x - 1);
if (x < 15) {
if (!board[y - 1][x + 1].revealed && board[y - 1][x + 1].b == 0)
revealZeros(y - 1, x + 1);
}
if (!board[y - 1][x].revealed && board[y - 1][x].b == 0)
revealZeros(y - 1, x);
}
if (x > 0)
if (!board[y][x - 1].revealed && board[y][x - 1].b == 0)
revealZeros(y, x - 1);
if (x < 15)
if (!board[y][x + 1].revealed && board[y][x + 1].b == 0)
revealZeros(y, x + 1);
if (y < 15) {
if (x > 0)
if (!board[y + 1][x - 1].revealed && board[y + 1][x - 1].b == 0)
revealZeros(y + 1, x - 1);
if (x < 15)
if (!board[y + 1][x + 1].revealed && board[y + 1][x + 1].b == 0)
revealZeros(y + 1, x + 1);
if (!board[y + 1][x].revealed && board[y + 1][x].b == 0)
revealZeros(y + 1, x);
}
}
通话无法正常进行。它揭示了除 0 以外的 block ,并且不揭示所有 0 block 。
Space.b = 周围的炸弹数量
Space.revealed = 空间是否显露?
最佳答案
哇!!我能够想到一个解决方案。很简单。这是我的最终代码:
private void revealZeros(int x, int y) {
if (x < 0 || x > 15 || y < 0 || y > 15) return; // check for bounds
if ( board[y][x].b == 0 && !board[y][x].revealed) {
board[y][x].revealed = true;
revealZeros( x+1, y );
revealZeros( x-1, y );
revealZeros( x, y-1 );
revealZeros( x, y+1 );
} else {
return;
}
}
关于java - 递归扫雷 "0-fill",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19106911/
1)扫雷 简介 扫雷 是一种经典的单人电脑游戏,最初由微软公司在 1990 年代开发并内置在 Windows 操作系统中。游戏的目标是在一个由方块组成的网格上揭开所有非地雷的方块,而不触发地雷。每个
我正在制作 MineSweeper 的 Angular 版本,但我遇到了事件问题。我的意思是,我有这样的字段组件: import {Component, Input, OnInit} from '@a
我正在尝试制作一个简单的扫雷器,在 n*n 板上埋下 n*n/3 个地雷。地雷用*标记,空格用0标记。(它还不能作为游戏运行:我正在尝试制作扫雷的“答卷”)请注意,我还没有使用过任何有目的的方法。 我
我必须制作一个扫雷 GUI,但我不知道如何使每个按钮都有自己的 mouseAdapter。当我单击某个按钮时,它会更改屏幕上的每个按钮,而不仅仅是我单击的按钮。我可以提供一些关于如何执行此操作的指示吗
我想制作一款扫雷游戏。首先,这适用于按钮。我想我将研究二维数组,并且会有类似 boolean 数组来显示炸弹在哪里,例如,如果 booleanArray[0][4] 为 true,则有炸弹。 现在,我
我遇到了这个奇怪的问题,但我似乎无法弄清楚。我有一个按钮,上面写着“新游戏”。在我玩一次游戏后,然后按“新游戏”返回到 initGame() ,我遇到一个问题,因为我无法右键单击前一个游戏的地雷单元格
我现在面临一个问题,我认为我的 main 正在一遍又一遍地执行一个方法,而不是一次。如果我根据一个例子来解释一下就更好了。我已经能够编写扫雷游戏了。但我把这一切都写在一个 MAIN 类中。这次我尝试再
几个月来我一直在尝试创建自己的扫雷游戏(为了好玩)。唯一让我真正困惑的是如何使用递归函数(flood-fill)来填充游戏中的空白区域。 洪水填充仅部分起作用。它不会从任何单击的节点延伸到右侧或底部节
我正在尝试在 C++11 中使用 Qt 编写扫雷程序。 如果我按下一个带有 0 个炸弹的按钮,我想检查这个按钮周围的按钮以及它们是否也有 0 个炸弹。如果他们有 0 颗炸弹,我想检查按钮。 (图:红色
我想做的是能够“转动”每个相邻的 0,就像普通的扫雷游戏一样。 #include #include #include #include #include int buscamina(); u
有没有办法让某些事件 Action 特定于鼠标左键和右键单击? 我正在创建一个扫雷器图形用户界面,所以当左键单击一个方 block 时,它会被发现,而当它被右键单击时,它会被标记。 我不确定如何从语法
我正在尝试制作一个控制台版本的扫雷。 尽管我目前很努力,但我无法弄清楚扫雷的“洪水填充”部分,如果所选方格的周围邻居不包含炸弹,我们现在必须检查这些相邻方格以找到相邻方格炸弹。 下面的代码适用于所选方
我是论坛新手,因此如果这不符合该网站的标准,我想表示歉意,但是我对 2D 阵列扫雷程序有疑问。 我试图在棋盘上随机放置地雷,棋盘是通过数组构建的。不幸的是,地雷被随机放置在对角线上,而不是整个棋盘上。
我是 Java 编程新手,想寻求您的帮助。我正在尝试使用 Java 开发一个简单的扫雷游戏。但是,我不断收到错误“线程“main”java.lang.ArrayIndexOutOfBoundsExce
我在这段代码上工作了几个小时,终于接近完成了。一旦我弄清楚如何添加通过右键单击标记地雷的功能,我将添加一个地雷计数器和一个计时器。我了解到 JButton 无法识别右键单击,因此我必须使用 Mouse
for (var i = 0; i < 10; i++) { bommen[i] = [ Math.floor(Math.random() * 10), Math.floor(
我正在完成大学的一项作业,我们获得了扫雷游戏的源代码,并且我们有一定的实现要求。其中之一是,所有游戏都是在用户登录后从磁盘读取的,用户可以随时保存游戏进度。我一直在阅读序列化来保存/加载游戏进度,但我
我正在尝试用 Java 制作类似扫雷的游戏,并且我已经完成了其中的大部分工作。我需要帮助的是 FloodFill - http://en.wikipedia.org/wiki/Flood_fill .
我正在尝试为我正在制作的扫雷游戏制作一个函数。该函数的目的是根据给定的 x 和 y(它所在的位置)显示一个元素。这可能不是实现它的最优雅的方法,但我正在为每个标题为 newField 的图 block
这款游戏是扫雷。我试图实现的人工智能将采用已经在计算机上运行的扫雷游戏实例(本例为 Windows 7),获取窗口的矩形尺寸,计算窗口的位置,将其推送到前台在屏幕上,单击左上角的方 block ,然后
我是一名优秀的程序员,十分优秀!