扫雷java
我正在用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果任何邻近的方块有地雷,它会显示一个数字及其周围的地雷数量。
如果周围没有地雷,它就是空白的(即:如果必须的话,它会显示数字 0)。当它为空时,它还会递归地打开其所有邻居(例如:打开所有邻居及其邻居(如果它们也为空),依此类推)。
如果这是一个地雷,你当然会输掉。一个例子:(
让
X
表示一个地雷)。如果您打开任何标记为
.
(空白)的方块,则会自动展开所有这些方块以及它们旁边的数字:(让
-
表示隐藏的方块)。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:
(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:(let
-
denote a hidden square).如果是炸弹,你就输了。
如果它是一个数字,那么它只会显示该数字。
如果它是一个空方格,也就是说,一个没有相邻炸弹的方格,那么它就是一个空白方格,并且在被揭示后,游戏会显示与其接触的所有其他空白方格(此过程一直持续到所有相邻方格为止)新创建的空字段是那些本身与至少一个炸弹相邻的字段(也就是说,有一个数字))
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 ))