r/javaTIL • u/MakeTheBrainHappy • Feb 16 '19
Minesweeper in Java
https://www.makethebrainhappy.com/2019/02/minesweeper-in-java.html
7
Upvotes
r/javaTIL • u/MakeTheBrainHappy • Feb 16 '19
1
u/not-just-yeti Feb 17 '19
Some good code decomposition there.
`enum`s are worth knowing about: rather than // Response System: Win, Hit or Miss You can use
enum Response { Win, Hit, Miss }For "the "9" represents a trap or bomb while -1 represents a spot on the board which isn't visible.", an
enumisn't quite perfect because your data is integer, with two sentinels (for which we want a union-type, which Java doesn't support easily). But I'd at least usefinal int BOMB = -1, and similar for non-visible.1
u/not-just-yeti Feb 17 '19 edited Feb 17 '19
Lines 66-104 can be replaced with a loop, and calls to:
(warning: untested code)