Chapter 2. Going further
Writing Real Code
Let’s build a Battleship game
It’s you against the browser: the browser hides ships and your job is to seek them out and destroy them. Of course, unlike the real Battleship game, in this one you don’t place any ships of your own. Instead, your job is to sink the computer’s ships in the fewest number of guesses.
Goal: Sink the browser’s ships in the fewest number of guesses. You’re given a rating, based on how well you perform.
Setup: When the game program is launched, the computer places ships on a virtual grid. When that’s done, the game asks for your first guess.
How you play: The browser will prompt you to enter a guess and you’ll type in a grid location. In response to your guess, you’ll ...