From 268a7ebf5ef57141103c1f85c78f6819c6413dcc Mon Sep 17 00:00:00 2001 From: UdeeshaRukshan Date: Sun, 22 Oct 2023 15:58:58 +0530 Subject: [PATCH 1/2] Mine Sweeper game using python --- M/Mine_Sweaper_game.py | 44 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 M/Mine_Sweaper_game.py diff --git a/M/Mine_Sweaper_game.py b/M/Mine_Sweaper_game.py new file mode 100644 index 00000000..74881b68 --- /dev/null +++ b/M/Mine_Sweaper_game.py @@ -0,0 +1,44 @@ +import random + +# Define the game board +board_size = 10 +num_mines = 10 +board = [[0 for _ in range(board_size)] for _ in range(board_size)] + +# Place the mines randomly on the board +mines = random.sample(range(board_size * board_size), num_mines) +for mine in mines: + row = mine // board_size + col = mine % board_size + board[row][col] = -1 + +# Calculate the number of adjacent mines for each cell +for row in range(board_size): + for col in range(board_size): + if board[row][col] == -1: + continue + for i in range(max(0, row - 1), min(board_size, row + 2)): + for j in range(max(0, col - 1), min(board_size, col + 2)): + if board[i][j] == -1: + board[row][col] += 1 + +# Define the game loop +while True: + # Display the current board + for row in board: + print(' '.join(str(cell) for cell in row)) + + # Prompt the player for input + row = int(input('Enter row: ')) + col = int(input('Enter column: ')) + + # Check if the player hit a mine + if board[row][col] == -1: + print('Game over!') + break + + # Reveal the cell and check if the player won + board[row][col] = -2 + if all(all(cell in (-1, -2) for cell in row) for row in board): + print('You win!') + break \ No newline at end of file From 8e161d06691d53b337f01dca5253f7401fe609f7 Mon Sep 17 00:00:00 2001 From: UdeeshaRukshan Date: Sun, 22 Oct 2023 16:02:20 +0530 Subject: [PATCH 2/2] Readme file updated --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b6748e5a..1098d7d4 100644 --- a/README.md +++ b/README.md @@ -95,7 +95,7 @@ We appreciate the contributions from the following community members: - [Ezhill Ragesh](https://github.com/ezhillragesh) - [Brunda Bharadwaj](https://github.com/brundabharadwaj/) - [Hemanth Singh](https://github.com/Hemanth11011) - +- [Udeesha Rukshan](https://github.com/UdeeshaRukshan) --- Happy coding! 🚀