Advertisement
pacho_the_python

Mines

May 25th, 2022
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.57 KB | None | 0 0
  1. import random
  2.  
  3.  
  4. class Mine:
  5.     def __init__(self, difficulty):
  6.         self.difficulty = difficulty
  7.         self.n = 0
  8.         self.counter = 0
  9.         self.board = []
  10.         self.serious_dict = {
  11.             "Easy": [10, 5],
  12.             "Normal": [20, 10],
  13.             "Hard": [30, 15]
  14.         }
  15.  
  16.     def are_you_serious(self):
  17.         if self.difficulty == "Easy":
  18.             self.n = self.serious_dict["Easy"][0]
  19.             self.counter = self.serious_dict["Easy"][1]
  20.         elif self.difficulty == "Normal":
  21.             self.n = self.serious_dict["Normal"][0]
  22.             self.counter = self.serious_dict["Normal"][1]
  23.         elif self.difficulty == "Hard":
  24.             self.n = self.serious_dict["Hard"][0]
  25.             self.counter = self.serious_dict["Hard"][1]
  26.  
  27.     def game_matrix(self):
  28.         symbols = ["-", "*"]
  29.         for i in range(self.n):
  30.             result = random.choices(symbols, weights=[50, 25], k=self.n)
  31.             self.board.append(result)
  32.         for j in self.board:
  33.             print(f"{' '.join(j)}")
  34.  
  35.     def player_move(self):
  36.         while True:
  37.             if self.counter == 0:
  38.                 print("You passed the mine field!")
  39.                 print("You win. GG!")
  40.                 break
  41.  
  42.             print(f"Enter the first number between 0 to {self.n - 1} including: ", end="")
  43.             coordinate_x = int(input())
  44.             while True:
  45.                 if 0 <= coordinate_x <= (self.n - 1):
  46.                     break
  47.                 else:
  48.                     print("Wrong input!")
  49.                     print(f"Enter enter the first number between 0 to {self.n - 1} including: ", end="")
  50.                     coordinate_x = int(input())
  51.  
  52.             print(f"Enter the second number between 0 to {self.n - 1} including: ", end="")
  53.             coordinate_y = int(input())
  54.             while True:
  55.                 if 0 <= coordinate_y <= (self.n - 1):
  56.                     break
  57.                 else:
  58.                     print("Wrong input!")
  59.                     print(f"Enter the second number between 0 to {self.n - 1} including: ", end="")
  60.                     coordinate_y = int(input())
  61.  
  62.             move = self.board[coordinate_x][coordinate_y]
  63.  
  64.             if move == "-":
  65.                 self.counter -= 1
  66.                 print("You survive!")
  67.             elif move == "*":
  68.                 print("You hug a mine.")
  69.                 print("Game Over!")
  70.                 break
  71.  
  72.  
  73. obj = Mine(difficulty=input("Choose between Easy, Normal or Hard: "))
  74. obj.are_you_serious()
  75. obj.game_matrix()
  76. obj.player_move()
  77.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement