Sunday, March 9, 2014

Battleship 12/19

from random import randint

board = []

from random import randint

board = []

for x in range(0, 5):
#1
board.append(["O"] * 5)

def print_board(board):
#1
for row in board:
#2
print " ".join(row)

print_board(board)

def random_row(board):
#1
return randint(0, len(board) - 1)

def random_col(board):
#1
return randint(0, len(board[0]) - 1)

ship_row = random_row(board)
ship_col = random_col(board)
guess_row = int(raw_input("Guess Row:"))
guess_col = int(raw_input("Guess Col:"))

print ship_row
print ship_col

# Write your code below!
if guess_col == ship_col and guess_row == ship_row:
#1
print "Congratulations! You sank my battleship!"
else:
#1
if (guess_row<0 or guess_row>4) or (guess_col<0 or guess_col>4):
#2
print "Oops, that's not even in the ocean."
#1
else:
#2 for next 3 lines
print "You missed my battleship!"
board[guess_row][guess_col] = 'X'
print print_board(board)

No comments:

Post a Comment