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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import random, time, replit
from termcolor import cprint
print()
cprint('Welcome to MineSweeper v.3.0!', 'red')
cprint('=============================', 'red')
print()
print('Excited to declare version 3.0 of MineSweeper as almost fully functional!')
def reset():
print('''
MAIN MENU
=========
-> For instructions on how to play, type 'I'
-> To play immediately, type 'P'
''')
choice = input('Type here: ').upper()
if choice == 'I':
print(open('instructions.txt', 'r').read())
input('Press [enter] when ready to play. ')
elif choice != 'P':
reset()
b = [[0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0]]
for n in range (0, 10):
placeBomb(b)
for r in range (0, 9):
for c in range (0, 9):
value = l(r, c, b)
if value == '*':
updateValues(r, c, b)
printBoard(b)
def l(r, c, b):
return b[r][c]
def placeBomb(b):
r = random.randint(0, 8)
c = random.randint(0, 8)
currentRow = b[r]
if not currentRow[c] == '*':
currentRow[c] = '*'
else:
placeBomb(b)
def updateValues(rn, c, b):
if 9 > (rn-1) > -1:
r = b[rn-1]
if 9 > (c-1) > -1:
if not r[c-1] == '*':
r[c-1] += 1
if not r[c] == '*':
r[c] += 1
if 9 > (c+1) > -1:
if not r[c+1] == '*':
r[c+1] += 1
r = b[rn]
if 9 > (c-1) > -1:
if not r[c-1] == '*':
r[c-1] += 1
if 9 > (c+1) > -1:
if not r[c+1] == '*':
r[c+1] += 1
if 9 > (rn+1) > -1:
r = b[rn+1]
if 9 > (c-1) > -1:
if not r[c-1] == '*':
r[c-1] += 1
if not r[c] == '*':
r[c] += 1
if 9 > (c+1) > -1:
if not r[c+1] == '*':
r[c+1] += 1
def printBoard(b):
replit.clear()
print(' A B C D E F G H I')
print(' ╔═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╗')
for r in range (0, 9):
print(r,'║',l(r,0,b),'║',l(r,1,b),'║',l(r,2,b),'║',l(r,3,b),'║',l(r,4,b),'║',l(r,5,b),'║',l(r,6,b),'║',l(r,7,b),'║',l(r,8,b),'║')
if not r == 8:
print(' ╠═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╣')
print(' ╚═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╝')
reset()