Skip to content

Commit

Permalink
FEATURE: Add level difficulty
Browse files Browse the repository at this point in the history
  • Loading branch information
SMoraisDev authored and Alexandre Antunes Mendes committed Oct 9, 2024
1 parent 565f716 commit 36d80fc
Showing 1 changed file with 26 additions and 5 deletions.
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 36d80fc

Please sign in to comment.