diff --git a/Battleship b/Battleship index d1a9702..2dd3af5 100644 --- a/Battleship +++ b/Battleship @@ -30,22 +30,29 @@ ship_col = random_col(board) # Allow player to guess where it is # raw_input asks user for input and returns it as a string > for integers, wrap with int() to convert string - -guess_row = int(raw_input("Guess Row: ")) -guess_col = int(raw_input("Guess Col: ")) +# Added a for loop +for turn in range(4): + print "Turn", turn+1 + guess_row = int(raw_input("Guess Row: ")) + guess_col = int(raw_input("Guess Col: ")) # Check if guess_row equals ship_row and guess_col equals ship_col -if guess_row == ship_row and guess_col == ship_col: - print "Congratulations! You sank my battleship!" -else: - if guess_row not in range(5) or guess_col not in range(5): - print "Oops, that's not even in the ocean." + if guess_row == ship_row and guess_col == ship_col: + print "Congratulations! You sank my battleship!" + # Add break to end program after correct guess + break + else: + if guess_row not in range(5) or guess_col not in range(5): + print "Oops, that's not even in the ocean." - elif guess_row == guess_row and guess_col == guess_col: - print "You guessed that one already." - else: - # Set list element at guess_row, guess_col to "X" - print "You missed my battleship!" - board[int(guess_row)][int(guess_col)] = "X" + elif board[guess_row][guess_col] == "X": + print( "You guessed that one already." ) + else: + print "You missed my battleship!" + board[int(guess_row)][int(guess_col)] = "X" + # See the X on the board - print_board(board) + # Check if number of guesses exceeded and print Game Over + if (turn == 3): + print "Game Over" + print_board(board)