Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # If you want to play this abomination... https://repl.it/@Null_Cat/Bad-Minesweeper
- # Part of the Minesweeper Project [https://pastebin.com/Yftb7QWL]
- import random
- import os
- import traceback
- import placeBoardNumbers as pn
- import datetime
- def clear():
- # definitely not stolen from stack overflow
- os.system('cls' if os.name=='nt' else 'clear')
- def insertDifficulty():
- inputDifficulty = input("Select a Difficulty\nEasy, Intermediate, Advanced, Expert, Marathon, Custom, or Daily?\n> ")
- return inputDifficulty
- inputMines = None
- inputSeed = ""
- while inputMines == None:
- inputDifficulty = insertDifficulty().lower()
- if inputDifficulty == "easy":
- inputWidth = 8
- inputHeight = 8
- inputMines = 10
- elif inputDifficulty == "intermediate":
- inputWidth = 16
- inputHeight = 16
- inputMines = 40
- elif inputDifficulty == "advanced":
- inputWidth = 16
- inputHeight = 32
- inputMines = 99
- elif inputDifficulty == "expert":
- inputWidth = 24
- inputHeight = 32
- inputMines = 249
- elif inputDifficulty == "marathon":
- inputWidth = 32
- inputHeight = 32
- inputMines = 165
- elif inputDifficulty == "marathon+":
- 9 inputWidth = 50
- inputHeight = 50
- inputMines = 512
- elif inputDifficulty == "daily":
- inputWidth = 16
- inputHeight = 16
- inputMines = 40
- inputSeed = str(datetime.datetime.today().year) + str(datetime.datetime.today().month) + str(datetime.datetime.today().day)
- elif inputDifficulty == "custom":
- inputWidth, inputHeight, inputMines = "","",""
- clear()
- while inputWidth == "":
- inputWidth = input("Insert Width\n>")
- try:
- inputWidth = int(inputWidth)
- clear()
- if inputWidth <= 0:
- print("Please insert a valid POSITIVE number.\n")
- inputWidth = ""
- except:
- clear()
- print("Please insert a valid number.\n")
- inputWidth = ""
- while inputHeight == "":
- inputHeight = input("Insert Height\n>")
- try:
- inputHeight = int(inputHeight)
- clear()
- if inputHeight <= 0:
- print("Please insert a valid POSITIVE number.\n")
- inputHeight = ""
- except:
- clear()
- print("Please insert a valid number.\n")
- inputHeight = ""
- while inputMines == "":
- inputMines = input("Insert Mine Count\n>")
- try:
- inputMines = int(inputMines)
- clear()
- if inputMines > inputWidth * inputHeight:
- inputMines = ""
- print("What did Minesweeper do to you for you to put more mines than spaces on the board, huh?\n")
- elif inputMines <= 0:
- print("Please insert a valid POSITIVE number.\n")
- inputMines = ""
- except:
- inputMines = ""
- clear()
- print("Please insert a valid number.\n")
- else:
- clear()
- print("Please Insert A Valid Difficulty\n")
- clear()
- if inputSeed == "":
- inputSeed = input("Insert seed (insert nothing to make it random)\n> ")
- if inputSeed == "":
- inputSeed = random.randint(-4000000000, 4000000000)
- clear()
- inputMode = ""
- while inputMode == "":
- inputMode = input("Insert Mode. Insert nothing for Normal.\nNormal (That's it)\n>").lower()
- if inputMode == "":
- inputMode = "normal"
- clear()
- print('\n')
- # "omg wat r yuo doin puttin object in teh arrey?!?!?//11"
- class Board:
- 'Creates the Board'
- def __init__(self, size, contents, seed):
- self.Size = size
- self.Contents = contents
- self.Seed = seed
- def addRow(self, rowToAdd):
- self.Contents.append(rowToAdd)
- class Space:
- 'Creates an Empty Space'
- def __init__(self, position=[0,0], minesAround=0, uncovered = False, flagged=False):
- self.Pos = position
- self.MinesAround = minesAround
- self.Uncovered = uncovered
- self.Flagged = flagged
- def __del__(self):
- self = 0
- class Mine:
- 'Creates A Mine'
- def __init__(self, position=[0,0], uncovered = False, flagged=False):
- self.Pos = position
- self.Uncovered = uncovered
- self.Flagged = flagged
- # isinstance(someMine, Mine) -- is the variable/object "someMine" part of the "Mine" class?
- def createBoard(width, height, mineCount, seed, type="Normal"):
- 'Creates a Board. The Numbers around mines will change with the type.'
- newSeed = seed
- random.seed(newSeed)
- newBoard = Board([width, height, mineCount], [], newSeed)
- #Generates the board while placing mines in the process.
- for i in range(height):
- newRow = []
- for j in range(width):
- if random.randint(1, 10) == 1 and mineCount != 0:
- newRow.append(Mine([j,i]))
- mineCount -= 1
- else:
- newRow.append(Space([j,i], 0))
- newBoard.addRow(newRow)
- #Checking if there are not enough mines and placing more.
- while (mineCount != 0):
- for i in range(height):
- for j in range(width):
- if random.randint(1,16) == 1 and mineCount != 0 and isinstance(newBoard.Contents[i][j], Mine) == False:
- del newBoard.Contents[i][j]
- newBoard.Contents[i].insert(j, Mine([j,i]))
- mineCount -= 1
- # Adding the numbers around the mines.
- pn.placeNumbersNormal(newBoard, Mine, Space)
- return newBoard
- try:
- theBoard = createBoard(inputWidth,inputHeight,inputMines, inputSeed)
- except Exception as e:
- print("The board failed to create due to",e)
- print("Seed:",inputSeed)
- print("Difficulty:",inputDifficulty.upper())
- if inputDifficulty == "custom":
- print("Size:",inputWidth,"by",inputHeight,"with",inputMines,"mines.")
- print("Please report this!")
- print("\n\nFull Error:\n")
- print(traceback.format_exc())
- exit()
- exploded = False
- while not exploded:
- print("Seed:",theBoard.Seed)
- print("Board Size:",theBoard.Size[0],"by",theBoard.Size[1],"with",theBoard.Size[2],"mines.")
- xPosGuide = " "
- for i in range(theBoard.Size[1]):
- xPosGuide += str(i)+" "
- print(xPosGuide+"\n")
- try:
- for i in range(theBoard.Size[0]):
- newLinePrint = ""+str(i)+" "
- for j in range(theBoard.Size[1]):
- if isinstance(theBoard.Contents[j][i], Space) and theBoard.Contents[j][i].Uncovered == True:
- newLinePrint += str(theBoard.Contents[j][i].MinesAround)+" "
- elif isinstance(theBoard.Contents[j][i], Mine) and theBoard.Contents[j][i].Uncovered == True:
- newLinePrint += "X "
- elif theBoard.Contents[j][i].Flagged == True:
- newLinePrint += "◼ "
- else:
- newLinePrint += "☐ "
- print(newLinePrint)
- spaceToUncover = input("Uncover or Flag?\nSyntax: <U(ncover):F(lag)> <x> <y>\n>")
- if spaceToUncover[0].lower() == "f":
- print("Flag")
- spaceToUncover = [int(s) for s in spaceToUncover.split() if s.isdigit()]
- try:
- if theBoard.Contents[spaceToUncover[0]][spaceToUncover[1]].Flagged == False:
- theBoard.Contents[spaceToUncover[0]][spaceToUncover[1]].Flagged = True
- else:
- theBoard.Contents[spaceToUncover[0]][spaceToUncover[1]].Flagged = False
- except IndexError:
- pass
- elif spaceToUncover[0].lower() == "u":
- print("Uncover")
- try:
- spaceToUncover = [int(s) for s in spaceToUncover.split() if s.isdigit()]
- if theBoard.Contents[spaceToUncover[0]][spaceToUncover[1]].Flagged == False:
- theBoard.Contents[spaceToUncover[0]][spaceToUncover[1]].Uncovered = True
- if isinstance(theBoard.Contents[spaceToUncover[0]][spaceToUncover[1]], Mine):
- exploded = True
- except IndexError:
- pass
- except IndexError:
- pass
- clear()
- print("""
- _____________
- | |
- | ________|
- | |_____
- | |
- | _____|
- | |
- | |
- |____|
- """)
Advertisement
Add Comment
Please, Sign In to add comment