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;
}
}
| |