如何检测“胜利”在扫雷游戏中?
I am working on a Minesweeper which I have pretty much complete.
The only thing missing is the detection of winning. What would be the best way to implement this? I know its going to be part of the actionlistener that detects clicks, at some point the last click should detect a winner.
Could anyone give me some ideas thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
则玩家获胜
如果(如果单元格处于初始状态或标记为地雷则未打开),
numUnopenedCells
numBombs
那么玩家必然“打开”了一个炸弹单元并且已经输了。是的,此代码段将直接或间接执行动作监听器。我建议您有一个游戏状态模型,并在
openCell(int x, int y)
方法中检查上述内容,并采取适当的操作。The player has won if
(where a cell is unopened if it is in its initial state, or flagged as a mine).
numUnopenedCells > numBombs
then the player has unopened cells which are not bombs (i.e. some work left to do)numUnopenedCells < numBombs
then the player has necessarily "opened" a bomb cell and already lost.Yes, this snippet would be executed directly or indirectly by the action listener. I'd suggest you have a model of the game state, and in the
openCell(int x, int y)
method you check the above, and take the appropriate action.如果打开的字段为
#(所有字段) - #(炸弹字段)
。If the opened fields are
#(all fields) - #(bomb fields)
.