Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from random import randint
- #imports a random integer
- board = []
- #makes the grid an array
- for x in range(5):
- board.append(["O"] * 5)
- #Creates the 5x5 grid as the board.
- def print_board(board):
- for row in board:
- print(" ").join(row)
- #Creates gaps between each space in the grid.
- print("Let's play Mine-sweeper!")
- print_board(board)
- #Welcomes the player and displays the board.
- def random_row(board):
- return randint(0, len(board) + 1)
- def random_col(board):
- return randint(0, len(board[0]) + 1)
- #Can't remember :(
- mine_row = random_row(board)
- mine_col = random_col(board)
- #Randomly generates a mine somewhere in the grid.
- while mine_row and mine_col != True:
- global guess_row
- global guess_col
- guess_row = int(raw_input("Guess Row:"))
- guess_col = int(raw_input("Guess Col:"))
- if guess_row == mine_row and guess_col == mine_col:
- mine_row = True
- mine_col = True
- #Keeps the player guessing if they haven't landed on the mine.
- if mine_row and mine_col == True:
- quit("X( You hit the mine!")
- if (guess_row < 0 or guess_row > 4) or (guess_col < 0 or guess_col > 4):
- quit("That's an invalid guess.")
- elif(board[guess_row][guess_col] == "X"):
- print(":/ You guessed that one already.")
- else:
- print(":) Safe guess.")
- board[guess_row][guess_col] = "X"
- for turn in range(1):
- print_board(board)
- else:
- guess_row = int(raw_input("Guess Row:"))
- guess_col = int(raw_input("Guess Col:"))
- #Stops players guessing if they hit the mine, too big/small an entry, and if they put the same guess twice. Otherwise it continues.
Add Comment
Please, Sign In to add comment