Advertisement
StateX

BattleShip.py

Feb 27th, 2014
400
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. from random import randint
  2.  
  3. board = []
  4. #Cambio O por ~ por que se parece mucho mas al aguna del mar xD.
  5. for x in range(5):
  6. board.append(["~"] * 5)
  7.  
  8. def print_board(board):
  9. for row in board:
  10. print " ".join(row)
  11. print """
  12. __________ __ __ .__ _________.__ .__
  13. \______ \_____ _/ |__/ |_| | ____ / _____/| |__ |__|_____
  14. | | _/\__ |\ __\ __\ | _/ __ \ \_____ \ | | \| \____ \
  15. | | \ / __ \| | | | | |_\ ___/ / \| Y \ | |_> >
  16. |______ /(____ /__| |__| |____/\___ >_______ /|___| /__| __/
  17. \/ \/ \/ \/ \/ |__|
  18. """
  19. print """
  20. ,--. ,--. ,--. ,--. ,--.
  21. \ `.' / / \ / \ / |
  22. \ / | () | | () | `| |
  23. \ / \ /.--.\ /.--.| |
  24. `-' `--' '--' `--' '--'`--'
  25. """
  26. print "Let's play Battleship!"
  27.  
  28. print_board(board)
  29.  
  30. def random_row(board):
  31. return randint(0, len(board) - 1)
  32.  
  33. def random_col(board):
  34. return randint(0, len(board[0]) - 1)
  35.  
  36. ship_row = random_row(board)
  37. ship_col = random_col(board)
  38.  
  39. #elimino print ship_row y print ship_col
  40. #para que no se vea por la pantalla y hacer el juego mas entretenido.
  41.  
  42. for turn in range(5):
  43. guess_row = int(raw_input("Guess Row:"))
  44. guess_col = int(raw_input("Guess Col:"))
  45.  
  46.  
  47. if guess_row == ship_row and guess_col == ship_col:
  48. print "Congratulations! You sunk my battleship!"
  49. break
  50. else:
  51. if (guess_row < 0 or guess_row > 4) or (guess_col < 0 or guess_col > 4):
  52. print "Oops, that's not even in the ocean."
  53. elif(board[guess_row][guess_col] == "X"):
  54. print "You guessed that one already."
  55. else:
  56. print "You missed my battleship!"
  57. board[guess_row][guess_col] = "X"
  58. # Un turno mas
  59. print turn + 1
  60. print_board(board)
  61. if turn > range(4):
  62. print "Game Over"
  63. raw_input("Press [enter] to close.... Loser")
  64. break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement