Untitled
unknown
plain_text
a year ago
1.2 kB
7
Indexable
import random def print_board(board): for row in board: print(" ".join(row)) def check_tile(board, x, y): if board[x][y] == "M": return False else: board[x][y] = "X" return True def main(): mine_x = random.randint(0, 2) mine_y = random.randint(0, 2) lives = 3 board = [[" " for _ in range(3)] for _ in range(3)] while lives > 0: print_board(board) x = int(input("Enter the x coordinate (0-2): ")) y = int(input("Enter the y coordinate (0-2): ")) if x < 0 or x > 2 or y < 0 or y > 2: print("Invalid coordinates. Try again.") continue if check_tile(board, x, y): if (x, y) == (mine_x, mine_y): print_board(board) print("You hit a mine! Game over.") break else: print_board(board) print("You hit a mine! You lose a life.") lives -= 1 if lives == 0: print("Game over. You lost all your lives.") else: print("Congratulations! You found the mine and survived!") if __name__ == "__main__": main()
Editor is loading...
Leave a Comment