19. Extra Credit


#1


Hi everybody,
I finished the Battleship exercise and I'm very proud of myself. There are beautiful ideas in the exercise Extra credit so I want to apply at least one of them. I want to have two ships in the ocean, I know it's not that hard but I don't know how to prevent the two ships to have the same position, when I assign the value to ( shipB_row) how to exclude the value of (shipA_row), the same for column.
Thank you in advance


shipA_row = random_row(board)
shipA_col = random_col(board)
shipB_row = random_row(board)
shipB_col = random_row(board)


#2

I thought it would be nice for the player to have to guess where the battleship was hiding so I removed these two lines (not formatted here, but it is in TextWrangler and it worked through the command line):

print ship_row
print ship_col

and I added a few lines to the final else:

else:
print "You missed my battleship!"
board[guess_row][guess_col] = "X"
if turn == 3:
print "Game Over"
print "My ship was at B!"
print "Your guesses were at X!"
board[ship_row][ship_col] = "B"
print_board(board)


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.