Youโve fired test shots. Youโve taken out a few rogue ships. But now itโs full-scale war โ and the tides have turned. This time, the computer isnโt just hidingโฆ itโs fighting back. In todayโs mission, youโll upgrade your Battleship program from a shooting gallery to a competitive duel. Every turn matters. Every hit counts. And the last fleet standing rules the sea.
๐ Implement a HIT/MISS display bar below the board
๐ Create a turn-based battle system between player and computer
๐ข Randomly place 10 single-tile ships (5 for each side)ย
โ๏ธ After all ships are sunk, declare a winner
๐ฎ What It Might Look Like:
Your players need a clear view of the battle status. It's time to add a HUD (Heads-Up Display) at the bottom of the board showing how many:
Shots have been taken
Hits have landed
Misses have occurred
DISPLAY THIS AT THE BOTTOM OF THE BOARD
Create three variables: hits, misses, and total_turns
After each guess, update one of those values
After printing the board, print a summary line with f-strings or .format()
๐ก Design flair: Use emojis like ๐ฏ for hits and ๐จ for misses to make it fun!
This is the main event. You and the computer will take turns launching attacks until one fleet is completely destroyed.
10 total ships are placed (5 for player, 5 for computer)
Both sides take turns guessing
First to eliminate the other's 5 ships wins the war
1. PLAYER'S TURN
Ask for input (e.g., "Enter location to fire (e.g., A3): ")
Validate and convert the input
Check if it hits a computer ship
โ If hit: Add to player_hits
โ If miss: Add to player_misses
Update the board
Print updated board and HIT/MISS bar
2. COMPUTER'S TURN
Randomly guess a coordinate (generate row and col)
Check if that guess hits a player ship
โ If hit: Add to computer_hits
โ If miss: Add to computer_misses
Tell the player what the computer tried
Update The Board
NOTE: Make sure the computer doesn't guess the same spot twice!ย
Use a list of guesses to check for repeats.
Check after each round:
Has the player hit 5 computer ships? ๐
Has the computer hit 5 player ships? ๐
Once one side reaches 5 hits:
Display a Fun Message:
๐ PLAYER WINS! The ocean belongs to you now.
-- OR --
๐ฅ COMPUTER WINS! Your fleet is sunk. Time to regroup.
Complete the end game condition:
Prompt for New Game or To Quit
Now you need to modify the game so you can save your game state to a .json file, then reload it later to continue right where they left off. Think of it like a save slot in a video game โ perfect for turn-based systems, stat tracking, or testing new features.
Hereโs a meaningful list of data to include...
Remember, when you do this, you'll need to provide the following options:
Save Game
You can offer this in place of someone taking a turn, or via a special Key Sequence
Load Game
This should be offered at the beginning of the game (start menu option)
Create a fully functional Game Menu that lets the player choose what to do before the battle begins.
โ [1] Start New Game
Resets the board and starts fresh
Players place ships, computer randomly places ships
Begins the gameplay loop
โ [2] Load Saved Game
Loads from battleship_save.json
Restores game state (from your JSON task)
โ [3] How to Play
Display a quick message like:
โTake turns entering coordinates like A3 or J10. Try to sink the enemy's ships before they sink yours!"
[4] Quit Game
Ends the program
(Optional: Add dramatic message like โThe sea claims one more coward...โ)
๐ Final Tips for Style Points:
Add a splash screen or ASCII art for Battleship at the top
Use time.sleep() to add small delays for drama
Use .center() and .rjust() to format your menu cleanly