From 719830785af78c3f032bfabacf98c0595c6394ff Mon Sep 17 00:00:00 2001 From: laker109 Date: Tue, 9 Sep 2025 11:50:05 -0300 Subject: [PATCH 1/2] Add my project: simple Python game --- Minesweeper/minesweeper.py | 63 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 Minesweeper/minesweeper.py diff --git a/Minesweeper/minesweeper.py b/Minesweeper/minesweeper.py new file mode 100644 index 00000000..7b0179f9 --- /dev/null +++ b/Minesweeper/minesweeper.py @@ -0,0 +1,63 @@ +import random + +# Basic settings +rows = 5 +cols = 5 +mines = 3 + +# Create hidden board +board = [[" " for _ in range(cols)] for _ in range(rows)] +visible = [["?" for _ in range(cols)] for _ in range(rows)] + +# Place mines +placed_mines = 0 +while placed_mines < mines: + r = random.randint(0, rows - 1) + c = random.randint(0, cols - 1) + if board[r][c] != "X": + board[r][c] = "X" + placed_mines += 1 + +# Count mines around a cell +def count_mines(r, c): + count = 0 + for i in range(r - 1, r + 2): + for j in range(c - 1, c + 2): + if 0 <= i < rows and 0 <= j < cols: + if board[i][j] == "X": + count += 1 + return count + +# Fill board with numbers +for r in range(rows): + for c in range(cols): + if board[r][c] != "X": + board[r][c] = str(count_mines(r, c)) + +# Show the visible board +def show(): + for row in visible: + print(" ".join(row)) + print() + +# Game loop +safe_cells = rows * cols - mines +while True: + show() + r = int(input("Row (0-4): ")) + c = int(input("Col (0-4): ")) + + if board[r][c] == "X": + print("💥 You hit a mine. Game Over!") + break + else: + visible[r][c] = board[r][c] + safe_cells -= 1 + if safe_cells == 0: + print("🏆 You won! No safe cells left.") + break + +# Reveal the real board at the end +print("\nReal board:") +for row in board: + print(" ".join(row)) From 27348750b1cd850189601f5a1c59be6bbe880616 Mon Sep 17 00:00:00 2001 From: laker109 Date: Tue, 9 Sep 2025 11:54:37 -0300 Subject: [PATCH 2/2] Add Minesweeper game in Python --- Minesweeper/Readme.md | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 Minesweeper/Readme.md diff --git a/Minesweeper/Readme.md b/Minesweeper/Readme.md new file mode 100644 index 00000000..2af49813 --- /dev/null +++ b/Minesweeper/Readme.md @@ -0,0 +1,10 @@ +## minesweeper + +A pretty Basic Minesweeper game written in Python for console. + +This is a basic console version of Minesweeper in Python. +Features: +- 5x5 board with 3 random mines +- Player selects row/col +- Win if all safe cells are revealed +- Lose if a mine is hit \ No newline at end of file