Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2014
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. '''
  2. Created on Jul 21, 2014
  3.  
  4. @author: Clover
  5. '''
  6. import random
  7. from random import randint
  8.  
  9. board = []
  10. for i in range(5):
  11. board.append(["O"] * 5)
  12.  
  13. def print_board(b):
  14. for i in b:
  15. print " ".join(i)
  16. def random_row(board):
  17. return randint(0, len(board)- 1)
  18. def random_col(board):
  19. return randint(0, len(board)- 1)
  20. ship_row = random_row(board)
  21. ship_col = random_col(board)
  22. print ship_row
  23. print ship_col
  24. for turn in range(4):
  25. print "Turn", turn + 1
  26. guess_row = int(raw_input("Guess Row: "))
  27. guess_col = int(raw_input("Guess Column: "))
  28. if guess_row == ship_row and guess_col == ship_col:
  29. print "Congratulations! You sank my battleship!"
  30. break
  31. elif board[guess_row][guess_col] == "X":
  32. print "You guessed that one already."
  33. else:
  34. if guess_row not in range(5) or guess_col not in range(5):
  35. print "Oops, that's not even in the ocean."
  36. else:
  37. print "You missed my battleship!"
  38. board[guess_row][guess_col] = "X"
  39. if turn == 3:
  40. print "Game Over."
  41. print_board(board)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement