Guest User

Untitled

a guest
May 24th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. from random import randint
  2. #imports a random integer
  3.  
  4. board = []
  5. #makes the grid an array
  6.  
  7. for x in range(5):
  8. board.append(["O"] * 5)
  9. #Creates the 5x5 grid as the board.
  10.  
  11. def print_board(board):
  12. for row in board:
  13. print(" ").join(row)
  14. #Creates gaps between each space in the grid.
  15.  
  16. print("Let's play Mine-sweeper!")
  17. print_board(board)
  18. #Welcomes the player and displays the board.
  19.  
  20. def random_row(board):
  21. return randint(0, len(board) + 1)
  22. def random_col(board):
  23. return randint(0, len(board[0]) + 1)
  24. #Can't remember :(
  25.  
  26. mine_row = random_row(board)
  27. mine_col = random_col(board)
  28. #Randomly generates a mine somewhere in the grid.
  29.  
  30. while mine_row and mine_col != True:
  31. global guess_row
  32. global guess_col
  33. guess_row = int(raw_input("Guess Row:"))
  34. guess_col = int(raw_input("Guess Col:"))
  35. if guess_row == mine_row and guess_col == mine_col:
  36. mine_row = True
  37. mine_col = True
  38. #Keeps the player guessing if they haven't landed on the mine.
  39.  
  40. if mine_row and mine_col == True:
  41. quit("X( You hit the mine!")
  42. if (guess_row < 0 or guess_row > 4) or (guess_col < 0 or guess_col > 4):
  43. quit("That's an invalid guess.")
  44. elif(board[guess_row][guess_col] == "X"):
  45. print(":/ You guessed that one already.")
  46. else:
  47. print(":) Safe guess.")
  48. board[guess_row][guess_col] = "X"
  49. for turn in range(1):
  50. print_board(board)
  51. else:
  52. guess_row = int(raw_input("Guess Row:"))
  53. guess_col = int(raw_input("Guess Col:"))
  54. #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