扫雷java

发布于 2024-12-07 05:20:17 字数 172 浏览 0 评论 0原文

我正在用 Java 开发一个扫雷程序。我将炸弹分布在整个场地,并且我的动作侦听器响应单击,鼠标侦听器响应右键单击。我还让每个被单击的方块检查与其相邻的炸弹数量,并将数字打印在方块上,就像在游戏中一样。

我唯一不明白的部分是,当单击一个方块(无论是数字还是空白方块)时,扫雷如何打开字段。请帮助我理解这是如何工作的。

I am working on a minesweeper program in Java. I have my bombs distributed throughout the field, and I have my actionlisteners responding to clicks and mouselistener, responding to right clicks. I also have each square that is clicked check to see how many bombs are adjacent to it and print the number on the square just like in the game.

The only part I don't understand is how minesweeper opens up field when clicking a square whether it be a number or a blank square. Please help me understand how this works.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

反目相谮 2024-12-14 05:20:17

我唯一不明白的部分是扫雷如何在单击一个方块(无论是数字还是空白方块)时打开字段。

如果任何邻近的方块有地雷,它会显示一个数字及其周围的地雷数量。

如果周围没有地雷,它就是空白的(即:如果必须的话,它会显示数字 0)。当它为空时,它还会递归地打开其所有邻居(例如:打开所有邻居及其邻居(如果它们也为空),依此类推)。

如果这是一个地雷,你当然会输掉。一个例子:(

X 2 . .
X 2 . .
2 2 1 .
1 X 1 .

X表示一个地雷)。

如果您打开任何标记为 .(空白)的方块,则会自动展开所有这些方块以及它们旁边的数字:(

- 2 . .
- 2 . .
- - 1 .
- - 1 .

- 表示隐藏的方块)。

The only part I don't understand is how minesweeper opens up field when clicking a square whether it be a number or a blank square.

If any of its neighboring squares has a mine, it will show a number with the number of mines around it.

It's blank if there are no mines around it (ie: it would show the number 0 if it had to). When it's blank it also recursively opens all its neighbors (eg: opens all neighbors and their neighbors if they are blank too, and so forth).

And if it's a mine you lose of course. An example:

X 2 . .
X 2 . .
2 2 1 .
1 X 1 .

(let X denote a mine).

If you open any of the squares with marked as . (blank), automatically expand all of them and the numbers next to them:

- 2 . .
- 2 . .
- - 1 .
- - 1 .

(let - denote a hidden square).

夜夜流光相皎洁 2024-12-14 05:20:17

如果是炸弹,你就输了。

如果它是一个数字,那么它只会显示该数字。

如果它是一个空方格,也就是说,一个没有相邻炸弹的方格,那么它就是一个空白方格,并且在被揭示后,游戏会显示与其接触的所有其他空白方格(此过程一直持续到所有相邻方格为止)新创建的空字段是那些本身与至少一个炸弹相邻的字段(也就是说,有一个数字))

If it's a bomb, you lose.

If it's a number then it just reveals that number.

If it's a null square, that is to say, one with no adjacent bombs, then it is a blank square and upon being revealed the game reveals all other squares in contact with it that are blank ( this process continues until all squares which are adjacent to the newly created null field are ones which are them selves adjacent to at least one bomb ( that is to say, have a number ))

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文