run time error

Hi, I am learning c + + and I am developing a small game in console mode called battala naval. the problem is that when I finish putting the boats in their pociciones I get an error at runtime is as follows: Run-Time Check Failure # 2 - Stack around the variable 'game' was corrupted. The program consists of two arrchivos, one for classes called "BT.h" and one for the application called "main.cpp". In summary "BT.h" there are two classes one for the map (board) and one for boats. The class boat simply stored in variables x and y positions in addition also holds another char variable to see if the Varco is positioned vertically or horizontally. The class map is mainly among other things two matrices, one for the board of player 1 "mapaj1" and another the same for the other player. both with length [9] [9]. and error for me is in the method cargar_barcos which is in charge of pocicionar boats on the map the player one or two. Below I summarize the code to see if I can help:
main.cpp(here is the function that collects the positions of 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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
void juego_vs_maquina()
{

	//CADA BARCO GUARDA SU POCICION EN UNA MATRIZ COMO SI ESTUVIECE SOLO EN ELLA
	//LUEGO HACER QUE CARGE LOS BARCOS DE J1 EN UN MAPA GENERICO Y LOS BARCOS DE J2 EN OTRO MAPA
	using namespace BT;
	using std::cout;
	using std::endl;
	using std::cin;
	int op=1;// Variable used to manipulate the loop
	int r=0; //variable used to obtain the return value 

	
	//Declaracion de objetos barco
	barcos j1barco2(2);"barco" in Spanish means boat
	barcos j1barco3(3);
	barcos j1barco5(5);


	//declaracion de objetos de mapa
	mapa juego;
	juego.cargar_mapa(); //function that loads the value '0 'in all positions of the matrix
	
	// COLLECTION OF DATA PLACEMENT OF VESSELS PLAYER 1
	while(op!=0)
	{
	system("cls");
	cout << endl << "COLOQUE SUS BARCOS: ";
	cout << endl << "COLOCACION BARCO DE 2 VIDAS: ";
	cout << endl << "COORD. X (HORIZONTAL): ";
	cin >> j1barco2.posx;
	cout << endl << "COORD. Y (VERTICAL):  ";
	cin >> j1barco2.posy;
	cout << endl << "POCICION DEL VARCO, \n(1)VERTICAL\n(2)HORIZONTAL\n(3)CANCELAR Y VOLVER A COLOCAR\n ELIJA OPCION: ";
	cin >> op;
	
	if(op==1)
	{
		//i put the boat
		r=juego.colocar_barcos(2,'v',j1barco2.posx,j1barco2.posy,1);
		
		
				
	}
	else if(op==2)
	{
		r=juego.colocar_barcos(2,'h',j1barco2.posx,j1barco2.posy,1);
		
	}

	cout << endl;
	for(int i=0;i<=9;i++)
	{
		for(int j = 0; j<=9;j++)
		{ 
		std::cout << juego.mapaj1[i][j];
		}
		std::cout << std::endl;
	}
	getch();

	//ERRORS

	if(r==0)
	{
		cout << endl <<"ERROR GENERICO POR FAVOR VUELVA A COLOCAR EL BARCO";
		op=1;
		getch();
	}

	if(r==1)
	{
		cout << endl <<"ERROR, LAS COORDENADAS QUE ESPECIFICO ESTAN FUERA DE RANGO\n POR FAVOR INGRESE COORDENADAS VALIDAS DE 0 A 9";
		op=1;
		getch();
	}

	if(r==2)
	{
		
		cout << endl <<"ERROR " << r << ", EN LAS COORDENADAS QUE ESPESIFICA YA HAY OTRO BARCO COLOCADO\n POR FAVOR COLOQUE EL BARCO EN OTRA POCICION";
		op=1;
		getch();
	}
	if(r==3)
	{	cout << endl <<"Ok. barco colocado"; //SHORT THE LOOP IF EVERYTHING WENT WELL
		getch();
		op=0;
	}
	}//fin while 

BT.h (ONLY PLACE THAT IS PART OF THE CODE IS WHERE THE ERROR)
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
	class mapa
	{
	public:
		mapa();
		~mapa();
		
		char mapaj1[maxl][maxl];
		char mapaj2[maxl][maxl];

		char tiros[9][9]; //tabla resumen de tiros deben ser publicas
		char tirosj2[9][9];

		int colocar_barcos(int barco, char vhpos,int posx, int posy,int jugador);
		int disparar(int posx, int posy,int jugador);

		void cargar_mapa();//LLENA CON 0 (48 ASCII) LA MATRIZ
	};

	class barcos
	{
	public:
		barcos();
		barcos(int vida);
		~barcos();
		int posx;
		int posy;

		void configurarvida(unsigned short int vida);
		int mostrarvida() const;
		void confvhpos(char pos);
		char BT::barcos::obtenervhpos() const;
	private:
		int vida;
		char vhpos;
	};
int BT::mapa::colocar_barcos(int barco, char vhpos,int posx, int posy,int jugador) //BOAT, VHPOS,POSX,POSY,GAMER
{
	/*
	RETURN VALUES
	0 - GENERIC ERROR
	1-  OUT OF RANG
	2-  ALLREDY EXIST A BOAT IN THIS POSITION
	3-  OK
	*/

	if((posx<0 || posy<0) || (posx>9 || posy>9))
	{
		return 1;
	}
	
	if(jugador==1)
	{
	for(int x=0;x<=9;x++)
	{
		for(int y=0;y<=9;y++)
		{
			if((mapaj1[x][y] == 49) && (mapaj1[x][y] == mapaj1[posx][posy]))
			{
				return 2;
			}
		}
	}
	}

	

	
	//----------------------------------------LOAD BOAT GAMER 1-------------------------------
	if(jugador==1)
	{
	switch(barco)
	{
	case 2:
		if(vhpos=='v' || vhpos=='V') //verical trabaja con eje y solo sumo al ¡Y!
		{
			//YO NEXT
			if((posx>=0 && posx<8)&&(posy>=0 && posy<8)) //para que no se pase de rango
			{

				for(int i =0;i<2;i++)
				{
				mapa::mapaj1[posx+i][posy] = COLOCADO; //COLOCADO = '1'
				
			   	}
			}
			else
			{
			//TO BACK
			for(int i = 0;i<2;i++)
			{
				mapaj1[posx-i][posy] = COLOCADO; 
			}
			
			}
			
		}
		else if (vhpos=='h' || vhpos=='H') //horizontal
		{
			//hacia adelante
			if((posx>=0 && posx<8)&&(posy>=0 && posy<8)) //para que no se pase de rango
			{
			for(int i = 0;i<2;i++)
			{
				mapa::mapaj1[posx][posy+i] = COLOCADO; 
			}//fin for i
			}
			else
			{
			//hacia atras
			for(int i = 0;i<1;i++)
			{
				mapaj1[posx][posy-i] = COLOCADO; 
			}//fin for i
			}
		}
		break;
default:
		return 0;
		break;
	}//Fin switch
	return 3;
	}
}


from already thank you very much, I hope my English is good enough to be understood greetings to all colleagues.
This for(int i=0;i<=9;i++) goes likely out of bounds. if you have an array with 9 elements you can access the element from 0 to 8 only: for(int i=0;i<9;i++)
hi thanks for your help, but then if I change the value of the index of the array to 10, because I keep jumping the same error? is assumed that if the index is 10 matrix of 0 to 9 ... any suggestions?
Topic archived. No new replies allowed.