random fill cells with mines and increments nearest mines num in adiacent cells
(self, w, h, minenum)
| 187 | self.set_root_widget(self.main_container) |
| 188 | |
| 189 | def build_mine_matrix(self, w, h, minenum): |
| 190 | """random fill cells with mines and increments nearest mines num in adiacent cells""" |
| 191 | self.minecount = 0 |
| 192 | matrix = [[Cell(30, 30, x, y, self) for x in range(w)] for y in range(h)] |
| 193 | for i in range(0, minenum): |
| 194 | x = random.randint(0, w - 1) |
| 195 | y = random.randint(0, h - 1) |
| 196 | if matrix[y][x].has_mine: |
| 197 | continue |
| 198 | |
| 199 | self.minecount += 1 |
| 200 | matrix[y][x].has_mine = True |
| 201 | for coord in [[-1, -1], [-1, 0], [-1, 1], [0, -1], [0, 1], [1, -1], [1, 0], [1, 1]]: |
| 202 | _x, _y = coord |
| 203 | if not self.coord_in_map(x + _x, y + _y, w, h): |
| 204 | continue |
| 205 | matrix[y + _y][x + _x].add_nearest_mine() |
| 206 | return matrix |
| 207 | |
| 208 | def no_mine(self, cell): |
| 209 | """opens nearest cells that are not near a mine""" |
no test coverage detected