10/25/2023 0 Comments Simple minesweeper python![]() If not isinstance(self.has_mine(), bool): If not isinstance(self.location, tuple) or len(self.location) != 2: '''Return True if the square is legal, False otherwise.''' # The player can only mark invisible squares, with unreserved marks If not self.is_visible() and sign not in Square.signs: X, y = self.location, self.location # square's coordinates '''Return the number of mines near the square.''' '''Return True if the square has a mine, False otherwise.''' '''Return True if the square is visible, False otherwise.''' # method returns so there's no any error.Įlse: # If the square has no any mine, but there are mines near it. # If there's no square with these coordinates, this If not (near_x = x and near_y = y): # not the same square ![]() # the squares near them (recursively), until we reach squares # Expose all of the squares near the current square, and all of Self.sign = ' ' # The sign that means that the square is clean, Self.sign = '*' # The sign that means that the square has a mineĮlif self.num() = 0: # There are no mines near the square ![]() '''Make the square visible to the player (when he exposes it, for Self.sign = '.' # sign - how is the square represented to the user. # player mark the square with '.', he cancels the previous sign)ĭef _init_(self, mine, location, grid): # (signs of visible squares - it doesn't contain '.' because when the # reserved signs - the player can't mark a square with those signs Grid - the gird that has the square in it Location - a tuple that represents the (x, y) of the square in the grid. Mine - if the square has a mine, it's True. I'm new to Python (and generally to programming), and I have recently written this Minesweeper game: import random ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |