Creating a grid layout for battleship game and able to mark the spot that is missed or hit.

Say, I have to create a layout in "grids" like:

A B C D E
1
2
3
4
5

How am i able to achieve this.

And next how is it possible to do something like marking a missed spot.. or hit spot..

pls advise..
In shell programming, we're able to use a "translate" function to convert: "1234567" into "<whitspace>ABCDEF"

From:
1 2 3 4 5 6 7
1
2
3
4
5
6
7

To:
A B C D E F
1
2
3
4
5
6
7

So how is this possible in c++ to create?
Last edited on
@Tampopo

This is how I did my game of 'Qui Vive'.

1
2
3
4
5
6
cout << " "; // Move over a space before printing the 'A'
	for( char a='A';a<'H';a++)
		cout  << a << " ";
	cout << endl;  // New line before the start of the vertical numbers
	for ( int i = 1; i < 8;i++)
		cout << i << endl;
Thanks whitenite1
@Tampopo
And next how is it possible to do something like marking a missed spot.. or hit spot..


I would set up an array, like this, if the board is 10x10.
1
2
3
4
5
6
7
8
9
int ships[10][10] = {{0},{0},{0},{0},{0},{0},{0},{0},{0},{0}};
ships[2][3]=1;  // 1 for aircraft carriers
ships[2][4]=1;
ships[2][5]=1;
ships[2][6]=1;
ships[6][2]=2; // 2 for battleship
ships[7][2]=2;
ships[8][2]=2;
etc..

Then check the users input for row/column. If something is there, show a hit. You really shouldn't say what the type is, otherwise they know how many spaces it takes.. Tell them what was sunk, only after the last hit on that ship.

int shots[10][10] = {{0},{0},{0},{0},{0},{0},{0},{0},{0},{0}}; Check the location in this array for their shot. Place a 1 at the location of their shot if it is a 0, otherwise tell them they already there. Either let them shoot again, or penalize them a shot, and then shoot again.
I Hope this was useful ...
Last edited on
Thanks! I've saved these notes into my template for reference. I'm currently doing the identifying of ship type..
Will u be able to help me out on this?

I've posted on this link:

http://www.cplusplus.com/forum/beginner/55530/
@Tampopo

I'd be happy to, as long as this isn't a class project, or a school assignment. You can PM me and I'll do what I can. Thanks for asking.
Last edited on
I've sent u an email whitenite1.. cheers
Topic archived. No new replies allowed.