Skip to content

Commit

Permalink
FEAT: Ajouter des niveaux de difficulté au jeu (#36)
Browse files Browse the repository at this point in the history
* CHORE: Update authors

* feat: Add level difficulty

---------

Co-authored-by: SMoraisDev <[email protected]>
  • Loading branch information
alexandreantunesmnds and SMoraisDev authored Oct 9, 2024
1 parent 9f2e857 commit 33a37c3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
1 change: 1 addition & 0 deletions AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@
- Samy FERGUI, [email protected]
- Marwane, RACHAD, [email protected]
- Mathis, Beauville, [email protected]
- Alexandre ANTUNES MENDES, [email protected]
31 changes: 26 additions & 5 deletions src/demineur.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,26 @@
class Demineur:
"""Class representing a Deminer game"""

def __init__(self, nombre_mines=10):
self.taille = 10
self.nombre_mines = nombre_mines
def __init__(self, difficulte='moyen'):
"""
Initialize the game with a grid and place mines based on difficulty level.
:param difficulte: Difficulty level of the game ('facile', 'moyen', 'difficile').
:raises ValueError: If the difficulty level is not one of 'facile', 'moyen', or 'difficile'.
"""
if difficulte not in ['facile', 'moyen', 'difficile']:
raise ValueError("Le niveau de difficulté doit être 'facile', 'moyen' ou 'difficile'.")

if difficulte == 'facile':
self.taille = 8
self.nombre_mines = 10
elif difficulte == 'difficile':
self.taille = 16
self.nombre_mines = 40
else: # moyen
self.taille = 10
self.nombre_mines = 20

self.grille = [['.' for _ in range(self.taille)] for _ in range(self.taille)]
self.grille_visible = [['.' for _ in range(self.taille)] for _ in range(self.taille)]
self.__placer_mines()
Expand Down Expand Up @@ -78,5 +95,9 @@ def jouer(self):


if __name__ == "__main__":
jeu = Demineur()
jeu.jouer()
niveau_difficulte = input("Choisissez un niveau de difficulte (facile, moyen, difficile): ")
try:
jeu = Demineur(niveau_difficulte)
jeu.jouer()
except ValueError as e:
print(e)

0 comments on commit 33a37c3

Please sign in to comment.