Write a Minesweeper in Java - Algorithm Reflections

xiaoxiao2021-03-06  49

?? Author: Aaron2004

??? March is a pretty classic game. He offers a very friendly interface.

??? Let's talk about my mine profile. First we randomly put it on the mine area, which can be implemented with the Random class. When you are clicked with a mart, you will show a number indicating that there are several thunders around it. How is this implementation? Can we see the entire mine area as a two-dimensional array a [? I] [j], such as the mine area:

?????????????? 11? 12? 13? 14? 15? 16? 17? 18 ?????????????? 21? 22? 23? 24? 25 ? 26? 27? 28 ?????????????? 31? 32? 33? 34? 35? 36? 37? 38 ????????????? 41? 42? ​​43? 44? 48 ??????????????? 51? 52? 53? 54? 55? 56? 57? 58 ???? we can find A [I] [j] There is a relationship around:

?????????? a [i- 1] [j - 1] ????????? a [? i - 1] [j] ????????? ?? a [i - 1] [j 1]

A [????????????? a [i] [j - 1] ??????????????? [? i] [j] ???? ????????????????? a [i] [j 1] a [????????????? a [? i 1] [J - 1] ?????????? a [? I 1] [j]? ???????????? a [i 1] [J 1]

???????????

As, you can start detection from the upper left corner of A [i] [j]. Of course, if you exceed the boundary, you should use the constraints to judge!

????????????

The minesweeping process will automatically launch a mine-free zone that has no thunder. If A [3] [4] surrounding mine is 1, A [2] [3] has been marked as mine, then A [2] [4], A [2] [5], A [3] [3 ], A [3] [5], A [4] [3], A [4] [4], A [4] [5] will be deployed, and the non-determinable mine areas will be spread. This is also the key to implementation. We can set an element of the array as a class object, and the class sets such an event: When the departure, check whether the mine around the surrounding mine is equal, if equal, if it is equal, unfolding Lei area indicated. In this way, the new mine area is triggered and triggered, so that it is recursive, it has always spread to the non-expandable mine zone. I believe that after learning the above two points, write the mine-like class (if there is a label, whether to expand the mark, the surrounding mine, etc. Simple one thing.

?

转载请注明原文地址:https://www.9cbs.com/read-117702.html

New Post(0)