Page principale | Liste des fichiers | Portée globale

test.c

Aller à la documentation de ce fichier.
00001 /*******************************************************************************\
00002  *                      SeaBattle - D.Bernaudeau, J. Vehent - 2006             *
00003  *                                                                             *
00004  *      fonction test: contrôles d'intégrités de placement et de jeu, tests    *
00005  *                      d'états "bateau coulé" et "fin de partie"              *
00006  *                                                                             *
00007 \*******************************************************************************/ 
00008 
00018 
00019 
00027 int set_collision(int matrice[10][10], int taille, int x,int y, int orientation){
00028 
00029         int i,j;
00030 
00032 
00033         if(orientation==0){
00034                 //Bateau horizontal
00035                 j=y;
00036                 for(i=x;i<=taille+x;i++){
00037                         if(matrice[j][i]!=0) return -1;
00038                 }
00039         }else{
00040                 //Bateau vertical
00041                 i=x;
00042                 for(j=y;j<=taille+x;j++){
00043                         if(matrice[j][i]!=0) return -1;
00044                 }
00045         }
00046 
00047         return 0;
00048 }
00049 
00050 
00052 
00059 int sortie_matrice(int taille, int x,int y, int orientation){
00060 
00062         if(orientation==0){
00063                 //Bateau horizontal
00064                 if( (taille+x)>10 ) return -1;
00065         }else{
00066                 //Bateau vertical
00067                 if( (taille+y)>10 ) return -1;
00068         }
00069 
00070         return 0;
00071 }
00072 
00074 
00080 int couler(int matrice[10][10], int ligne, int colonne){
00081 
00082                 //id_bateau est forcément une valeur négative
00083         int i, id_bateau = matrice[ligne][colonne];
00084 
00086         for(i=0;i<10;i++){
00087                 if(matrice[ligne][i] == (id_bateau*(-1)) )
00089                         return 0;
00090         }
00091 
00093         for(i=0;i<10;i++){
00094                 if(matrice[i][colonne]== (id_bateau*(-1)) )
00096                         return 0;
00097         }
00098         
00099         //le bateau est coulé, on renvoie 1
00100         return 1;
00101 }
00102 
00104 
00108 int perdu(int matrice[10][10]){
00109 
00110         int i,j,cpt=0;
00111 
00113         for(i=0;i<10;i++){
00114                 for(j=0;j<10;j++){
00115                         if(matrice[i][j] < -13)
00117                                 cpt++;
00118                 }
00119         }
00120 
00123         if (cpt == 18) return 1;
00124 
00126         else return 0;
00127 }

Généré le Sun Apr 30 17:46:01 2006 pour SeaBattle par  doxygen 1.4.4