Battleship Game

Hi All!

I'm in Programming I and out latest project is to make a one player battleship game out of a 5x5 array with 5 ships. The game will have hits, misses, and check for duplicates. The ships are to be randomized in placement each time. We are supposed to use mostly arrays and functions to build the program. I have no clue how to start, if someone could push me in the right direction of how to get the board array to output and get the game going that would be great. Thank you so much!
how to get the board array to output
How should your program look like, command line, GUI, using a graphic library ?
I suppose firstly you make a console verison. So really you have to make an array for the game field. Do the ships have regular shape?

xxxxx

or
x
x
x
x
x

Not
x
x
xxx

Or
x
.x
..x
...x
....x

I suggest that make a struct or a class for the ships. It can store the size of the ships, positions, damage etc. For example:

1
2
3
4
5
6
7
8
9
10
11
12
class cShip
{
	int x1, y1, x2, y2; // The position of the front and back of the ship
	int size;
	int damage[]; // for storing the damage. 
	//It is more simple if you make an array on the stack: int damage[5] // size is maximum 5
	public:
	cShip(int x1, y1, x2, y2, size); // constructor
	~cShip(); // destructor for destroying the damage array
	bool isDestroyed(); // for polling the destroyed
	bool isHit(int x, y); // for polling the hit		
};


You should make a game class which stores the array game field, both player (I suppose one of them is a computer and it plays with random generated hits.)
The program is supposed to use a 5 x 5 array for the board, while all the ships take up only 1 space. Unfortunately we haven't learned classes yet and cannot use them in this assignment!
It is a little late to start paying attention in class...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
// Use a two-dimensional array for your gameboard.
int gameboard[ 5 ][ 5 ];

// You will need a function to initialize the gameboard.
void initialize_gameboard( int gameboard[ 5 ][ 5 ] );

// You will need a function to display the gameboard.
void display_gameboard( int gameboard[ 5 ][ 5 ] );

// You will need different values in your gameboard
const int empty    = 0;  // contains water
const int occupied = 1;  // contains a ship
const int missed   = 2;  // enemy already tried to bomb this spot (but it only had water)
const int hit      = 3;  // this spot was bombed (and it had a ship) 

Good luck!
Topic archived. No new replies allowed.