![how to make a minesweeper game in python without pygame how to make a minesweeper game in python without pygame](https://www.pygame.org/thumb/a59faa23dd1e22444d3173cc671fc07e.png)
- #How to make a minesweeper game in python without pygame how to#
- #How to make a minesweeper game in python without pygame code#
Letters for columns and numbers for rows (or the opposite)
#How to make a minesweeper game in python without pygame how to#
Have you got any answers to my questions, or any general tips on how to improve the performance or readability?įrom a user interface point of view, it would be good to have : Finally, I wasn't sure whether to use a list comprehension or a normal loop in the final elif of Board.show().
#How to make a minesweeper game in python without pygame code#
Was this the right decision? I also think the for a in b: for c in a: which are repeated throughout the code could be cleaned up. When I implemented this, however, it looked quite messy, so I chose readability over performance.
![how to make a minesweeper game in python without pygame how to make a minesweeper game in python without pygame](https://media.springernature.com/lw785/springer-static/image/chp%3A10.1007%2F978-1-4842-1790-0_17/MediaObjects/978-1-4842-1790-0_17_Figa_HTML.jpg)
I am currently aware that when counting remaining_mines, the property function runs each time, whereas it would have been more efficient only adding and subtracting from the mine count when a mine or flag is placed. Print("Well done! You solved the board!") (row_id, col_id, is_flag) = get_move(board) While board.is_playing and not board.is_solved: If len(move_input) = 3 and move_input != "f": Int(move_input) not in range(len(board))): Int(move_input) not in range(len(board)) or If move_input = "H" or (len(move_input) not in (2, 3) or Return (int(move), int(move), True if move = "f" else False) Enter your move (for help enter \"H\"): ") Move = input("Enter your move (for help enter \"H\"): ") "would place a flag on the 6th column, 4th row). "remove a flag, add \"f\" after the row (for example, 64f " INSTRUCTIONS = ("First, enter the column, followed by the row. If not(cell.is_visible or cell.is_flagged):īoard = Board(tuple()Īvailable_pos = list(range((size-1) * (size-1))) Return 0 <= row_id < len(self) and 0 <= col_id < remaining_mines(self): Neighbours.append((row_id + surr_row, col_id + surr_col))
![how to make a minesweeper game in python without pygame how to make a minesweeper game in python without pygame](https://www.pygame.org/thumb/3c7b82afee3ed1f10b7466527cec2468.jpg)
If (self.is_in_range(surr_row, surr_col) andĭef get_neighbours(self, row_id, col_id): Print("Cannot add flag, cell already visible.")ĭef count_surrounding(self, row_id, col_id):įor (surr_row, surr_col) in self.get_neighbours(row_id, col_id): [self.show(surr_row, surr_col) for (surr_row, surr_col) in "".join())īoard_string += str(unt_surrounding(row_id,īoard_string += "\n " + "".join()Įlif unt_surrounding(row_id, col_id) = 0: I have recently written this Minesweeper game in Python: import randomĭef _init_(self, is_mine, is_visible=False, is_flagged=False):īoard_string = ("Mines: " + str(self.remaining_mines) + "\n " +