BattleShip - Fill Board with Ships

Hello there. I'm making the BattleShip game and I'm having some problems to fill the board with ships.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
 void Board::putShip(const Ship &s){



	int size = s.getSize();
	char ori = s.getOri();
	int line = s.getLin();
	int col = s.getCol();
	char symbol = s.getSymbol();

	for (unsigned int i = 0; i < ships.size(); i++){
		for (int j = 0; j < size; j++){
			if((board[line][col] == -1) && (ori == 'H')){
							board[line][col] = i;
							col++;
						}
			/*else if(board[line][col] >= 0){
			cout << "Ship " << symbol << " in position " << size << " cannot be placed" << endl;
		}*/



		}
	}

}


Basically I fill the board with numbers, each number corresponds to the ships vector index. So, when I read my ships from the txt it stores each line in the vector ships. -1 means water and I fill it with a dot ('.'). You can see it here:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
void Board::display() const{

	//string filename;


	int upC = 65, lowC = 97; //aqui temos o codigo ascii do a, primeira letra do alfabeto, 65 é o seu uppercase e 97 o seu lowercase
	int icc = 0; //int char coluna


	cout << "  ";




	while (icc < numLines){ //o int char coluna vai aumentando consoante as dimensoes do tabuleiro || e.g Se tivermos um tab 10x10
		cout << (char)lowC << " ";       				//teremos um range de 65-75 [a-j] para as colunas e um range 97 -107 [A-J] para as linhas
		icc++;
		lowC++;
	}
	cout << endl;
	icc = 0;

	for (int y = 0; y< numLines; y++)
	{
		cout << (char)upC << " ";
		for (int x = 0; x < numColumns; x++){
			if(board[y][x] == -1)
				cout << '.' << " ";
			else
				cout << ships[board[y][x]].getSymbol() << " ";
		}

		cout << endl;
		upC++;
	}




}


But somehow it isnt storing my ships correctly. For example, to test it I got on my txt something like:

1
2
3
board: 10 x 10 
A - Ea - H - 4 - 10
B - Aa - H - 3 - 10


It should print 4 A's on the line E (line 5) column a(column 1) and 3 B's on the line 1 column 1. But instead of it it's printing something like this:

1
2
3
4
5
6
7
8
9
10
11
 a b c d e f g h i j 
A A A A B B B . . . . 
B . . . . . . . . . . 
C . . . . . . . . . . 
D . . . . . . . . . . 
E A A A A . . . . . . 
F . . . . . . . . . . 
G . . . . . . . . . . 
H . . . . . . . . . . 
I . . . . . . . . . . 
J . . . . . . . . . . 


Any idea in whats wrong? I guess it's something really simple and I'm sorry for the newbie question but I can't really figure it out and it has been 18 hrs with this. I need to cool down :)

Best regards and thank you!
Topic archived. No new replies allowed.