MCPcopy Index your code
hub / github.com/ndleah/python-mini-project / play

Function play

Minesweeper_game/minesweeper.py:112–135  ·  view source on GitHub ↗
(dim_size=10, num_bombs=10)

Source from the content-addressed store, hash-verified

110
111
112def play(dim_size=10, num_bombs=10):
113
114 board = Board(dim_size, num_bombs)
115
116 safe = True
117
118 while len(board.dug) < board.dim_size ** 2 - num_bombs:
119 print(board)
120
121 user_input = re.split(',(\\s)*', input("Where would you like to dig? Input as row,col: ")) # '0, 3'
122 row, col = int(user_input[0]), int(user_input[-1])
123 if row < 0 or row >= board.dim_size or col < 0 or col >= dim_size:
124 print("Invalid location. Try again.")
125 continue
126
127 safe = board.dig(row, col)
128 if not safe:
129 break
130 if safe:
131 print("CONGRATULATIONS!!!! YOU ARE VICTORIOUS!")
132 else:
133 print("GAME OVER!!! BETTER LUCK NEXT TIME :(")
134 board.dug = [(r,c) for r in range(board.dim_size) for c in range(board.dim_size)]
135 print(board)
136
137if __name__ == '__main__':
138 play()

Callers 1

minesweeper.pyFile · 0.70

Calls 3

digMethod · 0.95
splitMethod · 0.80
BoardClass · 0.70

Tested by

no test coverage detected