C/Visual C - CODIGO FUENTE DE BATALLA NAVAL

 
Vista:

CODIGO FUENTE DE BATALLA NAVAL

Publicado por Gabriel (1 intervención) el 14/12/2004 18:08:37
HOLA A TODOS LOS DEL FORO, ME GUSTARIA SABER SI ALGUNO PUEDE FACILITARME O DECIRME DONDE PUEDO ENCONTRAR EL CODIGO FUENTE EN C O C++ DEL JUEGO DE BATALLA NAVAL, LO QUE PASA ES QUE LO ESTOY DESARROLLANDO COMO PARTE DE UN PROYECTO DE UNA MATERIA DE MI CARRERA, Y NECESITO SABER SI VOY EN LA DIRECCION CORRECTA, ESPERO RESPONDAN PRONTO, YA QUE LA FECHA DE ENTREGA ES EL SABADO
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

CODIGO FUENTE DE BATALLA NAVAL

Publicado por Orlando (2 intervenciones) el 03/08/2011 18:51:07
//BATALLA NAVAL,,, HECHO POR ORLANDITO PEREZ,,,
#include <iostream>
using namespace std;

void mat_en_cero(int mat[][10]);
void mat_en_x(int mat[][10]);
void parte1(int mat[][10]);
void parte2(int mat[][10]);
void parte3(int mat[][10]);
void parte4(int mat[][10]);
void batalla(int tir,int &j,int h[],int a[]);

int main(int argc, char *argv[]) {
int cant;
char jug[10][10];
cout<<"Ingrese cantidad de jugadores: ";
cin>>cant;
for(int i=0;i<cant;i++){
cout<<"Ingrese nombre jugador "<<i+1<<" : ";
cin>>jug[i];
cout<<endl;
}
int tir;

cout<<endl<<"A cuantos tiros juegan?"<<endl;
cin>>tir;
int h[4],a[4];
int i=1,gan=0,seg=0;
for(int f=0;f<cant;f++){
batalla(tir,i,h,a);
i++;
cout<<endl<<endl<<"Turno seguiente jugador"<<endl;}
for(int j=0;j<cant;j++){
if(h[j+1]>seg){
if(seg>gan){
seg=gan;gan=h[j+1];}
else
seg=h[j+1];
}

}
cout<<"Ganador: "<<jug[gan]<<". Barcos Hundidos: "<<h[gan]<<endl;
















return 0;
}




void mat_en_x(int fal [][10]){
for(int i=0;i<10;i++)
for(int j=0;j<10;j++)
fal[i][j]=0;

}
void mat_en_cero(int mat [][10]){
for(int i=0;i<10;i++)
for(int j=0;j<10;j++)
mat[i][j]=0;

}
void parte1(int mat[][10]){
int fil,col;
cout<<"Barco de 1 parte"<<endl<<"Ingrese fila"<<endl;
cin>>fil;
cout<<"Ingrese columna"<<endl;
cin>>col;
mat[fil-1][col-1]=1;
}
void parte2(int mat[][10]){
int fil,col;
cout<<"Barco de 2 partes"<<endl;
for(int i=0;i<2;i++){
cout<<"Ingrese fila"<<endl;
cin>>fil;
cout<<"Ingrese columna"<<endl;
cin>>col;
mat[fil-1][col-1]=2;
}
//como hago para mostar msj en caso de que este mal ingresado?

}
void parte3(int mat[][10]){
int fil,col;
cout<<"Barco de 3 partes"<<endl;
for(int i=0;i<3;i++){
cout<<"Ingrese fila"<<endl;
cin>>fil;
cout<<"Ingrese columna"<<endl;
cin>>col;
mat[fil-1][col-1]=3;
}
}
void parte4(int mat[][10]){
int fil,col;
cout<<"Barco de 4 partes"<<endl;
for(int i=0;i<4;i++){
cout<<"Ingrese fila"<<endl;
cin>>fil;
cout<<"Ingrese columna"<<endl;
cin>>col;
mat[fil-1][col-1]=4;
}
}
void batalla(int tir,int &j,int h[],int a[]){
h[j]=0;
a[j]=0;

int mat[10][10];
mat_en_cero(mat);

parte1(mat);
parte2(mat);
parte3(mat);
parte4(mat);

for(int i=0;i<10;i++){
for(int j=0;j<10;j++){
cout<<mat[i][j];}
cout<<endl;
}

int k=5;
int fal[10][10],col,c1=0,fil;
mat_en_x(fal);
while(c1<tir){
cout<<"Ingrese tiro!"<<endl<<endl;
cout<<"Columna: "<<endl;
cin>>col;
cout<<"Ingrese fila: "<<endl;
cin>>fil;
if(mat[fil-1][col-1]==0){
cout<<endl<<"oleeeeeeee jajajaj agua bobo"<<endl<<endl;
}else{
if(mat[fil-1][col-1]==1){
cout<<"HUNDISTE EL BARCO DE 1 PARTE!!"<<endl;fal[fil-1][col-1]=1;h[j]++;}
if(mat[fil-1][col-1]==2){
cout<<"Averiaste barco de 2 partes"<<endl;fal[fil-1][col-1]=2;
mat[fil-1][col-1]=0;
for(int i=0;i<10;i++)
for(int j=0;j<10;j++)
if(mat[i][j]==2){
cout<<"te falta una/s parte/s"<<endl;
a[j]++;k=0;}

if(k==5){cout<<"BARCO HUNDIDO!!!"<<endl;h[j]++;}

}
if(mat[fil-1][col-1]==3){
cout<<"Averiaste barco de 3 partes"<<endl;fal[fil-1][col-1]=3;
mat[fil-1][col-1]=0;
for(int i=0;i<10;i++)
for(int j=0;j<10;j++)
if(mat[i][j]==3){
cout<<"te falta una/s parte/s"<<endl;a[j]++;k=0;}
if(k==5){cout<<"BARCO HUNDIDO!!!"<<endl;h[j]++;}



}
if(mat[fil-1][col-1]==4){
cout<<"Averiaste barco de 4 partes"<<endl;fal[fil-1][col-1]=4;
mat[fil-1][col-1]=0;
for(int i=0;i<10;i++)
for(int j=0;j<10;j++)
if(mat[i][j]==4){
cout<<"te falta una/s parte/s"<<endl;a[j]++;k=0;}
if(k==5){cout<<"BARCO HUNDIDO!!!"<<endl;h[j]++;}
}

}
for(int i=0;i<10;i++){
for(int j=0;j<10;j++){
cout<<fal[i][j];}
cout<<endl;
}
cout<<endl<<endl<<endl<<endl;
c1++;
k=5;
}



}
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

CODIGO FUENTE DE BATALLA NAVAL

Publicado por Orlando (2 intervenciones) el 03/08/2011 18:51:54
DE ALGO DE VA A SERVIR
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar