-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexecutive.py
59 lines (47 loc) · 1.69 KB
/
executive.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
"""@package docstring
Executive - will run the minesweeper game
"""
import pygame
from sweeper_UI import *
class executive:
def run(self):
"""
@pre none
@post runs a game
"""
print("WELCOME TO MINESWEEPER!")
while True:
self.get_input()
start_game(self.rows, self.cols, self.mines)
def get_input(self):
"""
@pre none
@post sets rows, columns and mines equal to a valid user input (2 <= rows <= 30, 2 <= cols <= 40, 1 <= mines <= rows*cols -1)
"""
while True:
try:
self.rows = int(input("Number of rows: "))
while self.rows < 2 or self.rows > 30:
self.rows = int(input("Please enter a number between 2 and 30: "))
break
except ValueError:
print("Please enter a number!")
while True:
try:
self.cols = int(input("Number of columns: "))
while self.cols < 2 or self.cols > 30:
self.cols = int(input("Please enter a number between 2 and 30: "))
break
except ValueError:
print("Please enter a number!")
while True:
try:
self.mines = int(input("Number of mines: "))
while self.mines < 1 or (self.mines >= self.rows * self.cols):
tile_count = self.rows * self.cols
self.mines = int(input("Please enter a number between 1 and " + str(tile_count - 1) + ": "))
break
except ValueError:
print("Please enter a number!")
exec = executive()
exec.run()