Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI : Amélioration de l'affichage de la grille #67

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@
- Théo, POSENEL, [email protected]
- Mourad, LARBI MESSAOUDI, [email protected]
- Minh Quang, CAO, [email protected]
- Ilyes, HAMOUDA, [email protected]
44 changes: 37 additions & 7 deletions src/demineur.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,43 @@ def decouvrir_cases(self, x, y):
self.decouvrir_cases(x, y + 1)

def afficher_grille(self):
"""A Function to show the game's board"""
print(" "+ " ".join([str(i) for i in range(self.taille)]))
for idx, ligne in enumerate(self.grille_visible):
print(f"{idx:2}| " + ' '.join(ligne) + " |")

mines_restantes = self.nombre_mines - sum(row.count('M') for row in self.grille_visible)
"""A Function to show the game's board with better visuals"""

def color_number(num):
"""Returns a colored version of the number for visibility."""
color_map = {
'1': '\033[94m1\033[0m', # Blue
'2': '\033[92m2\033[0m', # Green
'3': '\033[93m3\033[0m', # Yellow
'4': '\033[91m4\033[0m', # Red
'5': '\033[95m5\033[0m', # Purple
# Add more colors as needed
}
return color_map.get(num, num) # Default to uncolored if not in map

# Define the symbols for display
display_map = {
'■': '🟦', # Hidden cell
'M': '💣', # Mine
'F': '🚩', # Flag
'0': '⬜' # Empty cell
}

# Display the column headers
print(" " + " ".join([str(i) for i in range(self.taille)]))
for idx, ligne in enumerate(self.grille_visible):
# Transform the grid row for display
displayed_row = []
for cell in ligne:
if cell.isdigit(): # If the cell is a number, color it
displayed_row.append(color_number(cell))
else: # Otherwise, map it to its display symbol
displayed_row.append(display_map.get(cell, cell))
# Print each row with its index
print(f"{idx:2} | " + ' '.join(displayed_row) + " |")

# Display mines remaining, moves, and timer
mines_restantes = self.nombre_mines - sum(row.count('🚩') for row in self.grille_visible)
if self.statistiques.timer_start:
temps_ecoule = int(time.time() - self.statistiques.timer_start)
else:
Expand All @@ -99,7 +129,7 @@ def afficher_grille(self):
f"\nMines restantes: {mines_restantes} | "
f"Mouvements: {self.mouvements} | "
f"Temps: {hours:02}:{minutes:02}:{seconds:02}"
)
)

def charger_jeu(self):
"""
Expand Down
Loading