falorealtime.blogg.se

Python simple function that creats minesweeper
Python simple function that creats minesweeper












python simple function that creats minesweeper

# Reveal all positions around this, if they are not mines either. X, y = random.randint(0, self.b_size - 1), random.randint(0, self.b_size - 1) Python def _reset_add_starting_marker(self): Try and solve this yourself by postponing the calculation!

python simple function that creats minesweeper

But it means we can't allow the user to choose their initial move - we can explain this away as the "initial exploration around the rocket" and make it sound completely sensible.

python simple function that creats minesweeper

Pre-calculating the adjacent counts here helps simplify the reveal logic later. We count the number of these that is a mine is_mine = True and store. The custom function get_surrounding simply returns those positions around a given x and y location. With mines in position, we can now calculate the 'adjacency' numberįor each position - simply the number of mines in the immediate vicinity, using a 3x3 grid around the given point. Self.end_game_n = (self.b_size * self.b_size) - (self.n_mines + 1) X, y = random.randint(0, self.b_size-1), random.randint(0, self.b_size-1)

  • Add a starting marker (the rocket) and trigger initial exploration.
  • Calculate the number of mines adjacent to each position.
  • Remove all mines (and reset data) from the field.
  • The main function reset_map calls these functions We name them _reset (the leading underscore is a convention to indicate a private function, not intended for external use). Now we have our grid of positional tile objects in place, we canīegin creating the initial conditions of the playing board.
  • The singleShot timer is required to ensure the resize runs after we've returned to the event loop and Qt is aware of the new contents.
  • QTimer.singleShot(0, lambda: self.resize(1,1)) # # Place resize on the event queue, giving control back to Qt before.














    Python simple function that creats minesweeper