iffinalandmaster[x][y][0]==1:# If it's not revealed, it is a mine and this is the game-over screen
master[x][y][4]["text"]="*"
else:
ifmaster[x][y][3]==0:# If it's not revealed and it's not marked
master[x][y][4]["text"]="#"
else:# If it's not revealed and is marked
ifmaster[x][y][0]==1ornotfinal:# If it's not revealed and is marked and was actually a mine, OR if it's not revealed and is marked and this is not the game-over screen
master[x][y][4]["text"]="*"
else:# If it's not revealed and is marked but was marked incorrectly
master[x][y][4]["text"]="X"
else:# If it is revealed
ifmaster[x][y][0]==1:
master[x][y][4]["text"]="+"
else:
ifmaster[x][y][1]==0:
master[x][y][4]["text"]=""
else:
master[x][y][4]["text"]=str(master[x][y][1])# If it's revealed, and isn't a mine, print the number
#print(row)
ifnotfinal:
CheckIfGameOver()
defreveal(x,y,manual=False):
# Get master from the global scope
globalmaster
ifmaster[x][y][3]==1:# If it's marked, never reveal it.
ifmanual:
tkinter.messagebox.showinfo("Nope","You cannot reveal a marked square. Unmark it first")
returnTrue
ifmaster[x][y][2]==1andnotmanual:# If this is already revealed, exit, otherwise the recursion will be infinite, and that's bad
returnTrue
master[x][y][2]=1# Reveal it
ifmaster[x][y][0]==1:# If it's a mine
tkinter.messagebox.showinfo("Game over","Game over! Better luck next time")
tkinter.messagebox.showinfo("Error","Too many mines for "+str(MaxX*MaxY)+" spaces!")
continue
break
except:
tkinter.messagebox.showinfo("Error","Input parse failed. That's probably not a number!")
MaxXEntry.destroy()
MaxXLabel.destroy()
MaxXFrame.destroy()
MaxYEntry.destroy()
MaxYLabel.destroy()
MaxYFrame.destroy()
NumMinesEntry.destroy()
NumMinesLabel.destroy()
NumMinesFrame.destroy()
SubmitButton.destroy()
# Initialize timer
TimerStart=time.time()
# Initialize variables
master=[]
forxinrange(0,MaxX):
master.append([])
#frames.append(Tkinter.Frame(window))
foryinrange(0,MaxY):
master[x].append([])
master[x][y]=[0,0,0,0,tkinter.Button(window,command=lambdax=x,y=y:reveal(x,y,True))]# See line 2. That x=x,y=y is important, without it each button would think it's position was MaxX-1,MaxY-1
ifmaster[x][y][0]==1or(abs(StartingX-x)<=1orabs(StartingY-y)<=1):# Do not place a mine on a square where there is already a mine, on the starting position, or within the 8 squares surrounding the starting position