Пример #1
0
Grille lirefichier (char *fichier) //Les bords doivent être contenus dans le fichier de la grille
{
	char line[100];
	
	int i, j;
	Grille g1;
	
	FILE *fd;
	fd = fopen(fichier, "r");
	
	if (fd == NULL)
	{
		perror("Erreur lors de la lecture du fichier");
		exit (1);
	}	
		fscanf(fd, "%d %d %d", &g1.n, &g1.m, &g1.effect);
		g1 = creerGrille(g1);
	
		while (!feof(fd))
		{
			for (i = 0; i < g1.n; i++)
			{
				for (j = 0; j < g1.m; j++)
				{
					fscanf(fd, "%d", &g1.g[i][j]);
				}
			}
		}

	fclose (fd);
	
	return g1;
}
Пример #2
0
TPartie* initialiser(Tparam *param){

    int i = 0, j = 0;
    int nombreBateaux = 0;
    int casesOccupeBateaux = 0;

    TPartie *partie = malloc (sizeof(TPartie));

    //On initialise le score
    partie->scorePlayer = 0;

    //=========== Initialisation / Allocation ===================

    partie->joueur = creerJoueur();
    partie->machine = creerJoueur();

    partie->grille = creerGrille(KHAUTGRILLE,KLARGGRILLE);
    partie->grilleMachine = creerGrille(KHAUTGRILLE, KLARGGRILLE);

    partie->parametres = param;

    partie->pileCoups = creerPile();

    partie->scorePlayer = 0;

    //On compte le nombre de bateaux à allouer
    nombreBateaux = getNbBat(param);

    //On alloue
    partie->joueur->mesBateaux = malloc( sizeof(TBateau*) * nombreBateaux );
    partie->machine->mesBateaux = malloc( sizeof(TBateau*) * nombreBateaux );

    //=========== Préparation ===================================

    //Préparation des bateaux

    //Création des structures et ajout des id (commencent à 0)
    for(i = 0 ; i < nombreBateaux ; i++){
        partie->joueur->mesBateaux[i] = creerBateau();
        partie->machine->mesBateaux[i] = creerBateau();

        partie->joueur->mesBateaux[i]->idBateau = i;
        partie->machine->mesBateaux[i]->idBateau = i + nombreBateaux;

        partie->joueur->mesBateaux[i]->estPlace = 0;
        partie->machine->mesBateaux[i]->estPlace = 0;
    }

    //Calcul du nombre de cases occupé par les bateaux
    //pour calculer le score
    for(i = 0 ; i < K_NBTYPEBATEAUX ; i++){
        for(j = 0 ; j < partie->parametres->nombreInstanceBateaux[j] ; j++){
            casesOccupeBateaux += i;
        }
    }

    partie->scorePlayer = KLARGGRILLE * KHAUTGRILLE + casesOccupeBateaux;

    return partie;

}