diff --git a/.github/workflows/ci_cd.yml b/.github/workflows/ci_cd.yml index 12da9f0..973a93c 100644 --- a/.github/workflows/ci_cd.yml +++ b/.github/workflows/ci_cd.yml @@ -42,7 +42,7 @@ jobs: pip install pylint - name: Analysing the code with pylint run: | - pylint $(git ls-files '*.py') + pylint --max-attributes=8 $(git ls-files '*.py') doc-build: runs-on: ubuntu-latest diff --git a/src/demineur.py b/src/demineur.py index 0043d3d..0442482 100644 --- a/src/demineur.py +++ b/src/demineur.py @@ -2,6 +2,7 @@ import random import json import os +import time from statistiques import Statistiques class Demineur: @@ -34,6 +35,7 @@ def __init__(self, fichier_sauvegarde='demineur.json', difficulte='moyen'): self.marques = set() self.__placer_mines() self.__calculer_indices() + self.mouvements = 0 def __placer_mines(self): mines_placees = 0 @@ -69,6 +71,8 @@ def decouvrir_cases(self, x, y): if self.grille_visible[y][x] != '■': return self.grille_visible[y][x] = self.grille[y][x] + self.mouvements += 1 + if self.grille[y][x] == '0': self.decouvrir_cases(x - 1, y) self.decouvrir_cases(x + 1, y) @@ -81,6 +85,22 @@ def afficher_grille(self): 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) + + if self.statistiques.timer_start: + temps_ecoule = int(time.time() - self.statistiques.timer_start) + else: + temps_ecoule = 0 + + hours, remainder = divmod(temps_ecoule, 3600) + minutes, seconds = divmod(remainder, 60) + + print( + f"\nMines restantes: {mines_restantes} | " + f"Mouvements: {self.mouvements} | " + f"Temps: {hours:02}:{minutes:02}:{seconds:02}" +) + def charger_jeu(self): """ Load the game state from a JSON file.