Two Player C++ BattleShip game

Im coding a battleship game in C++ and Im confused where on where to start. I typed up a pseudocode for the game. Where is the best place to start? Should I change the pseudocode? Thank you!!
Here is the pseudocode I have at the moment:
1. Initialize variables
2. Code battleship board:(Const int BOARD_WIDTH, Const int BOARD_HEIGHT, Const int SHIP_TYPES)
3. Draw board
4. Players#1 place ships down on the board
5. Flag for player#2 to do the same
6. Loop for start of the game
7. Player inputs an attack on the board
8. Check if the attack inputted is a hit
9. Remove ships
10. Redraw game board
11. Check to see if game is over, if a player won (If a player won, and the game is over, end the program)
12. Flag for next player's turn
13.Loop until a player wins


For every instruction you have numbered there, ask yourself "is this enough information to write corresponding code with"? If a step sounds too vague, perhaps had sub-steps beneath it to flesh it out a bit more.

You say you want to "initialize variables" for step #1. Okay... what variables? What are you initializing? Define your data, and be precise about it. For example, your data might be a 10x10 grid of characters, each cell representing a place where the player could place a potential target. You also need to keep track of the positions of each enemy ship. And you'd need one of these for each player.
Last edited on
How will you represent the board itself? Nail that down. Note that there are are two boards: one for each player, and the opponent has an incomplete view of the board. How will you represent the boards? What about the incomplete views?

This gets a general point about pseudo-code: you have to create pseudocode for the data too. In fact, I usually find it most productive to work out the data first.

Next, copy your pseudocode into your .cpp file and convert each line to a comment. Maybe think about what pieces should be functions. Two obvious ones are "draw board" and "is the game over."

It's always good to write a little code, test it, and then move on to more code. So I'd write code for the first 3 parts and test them. Think about it this way: if you can't display the board correctly, you'll never find bugs in other parts of the code.

Once you can populate and display the board, you can work on the game logic itself.

A question: is this for two players, or 1 player vs. the computer?
Topic archived. No new replies allowed.