1
0

Modification de diverses déclarations de variables

This commit is contained in:
Lyanis SOUIDI 2022-12-01 20:41:23 +01:00
parent 30d3f4c360
commit 7952d5f395
3 changed files with 31 additions and 35 deletions

View File

@ -23,50 +23,46 @@ card create_card(int x, int y, int L, int H, char *file) {
} }
int game(int colonnes, int lignes) { int game(int colonnes, int lignes) {
int i,j; int i,j, t, used, r;
int used, r; int i, j, l, c, case_max_width, case_max_height, case_max_dimensions, case_margin, boucle;
unsigned long int timer;
size_t k, m;
int* tab = malloc(sizeof(int) * (colonnes * lignes)); int* tab = malloc(sizeof(int) * (colonnes * lignes));
srand(time(NULL)); srand(time(NULL));
EffacerEcran(CouleurParComposante(54, 57, 63)); EffacerEcran(CouleurParComposante(54, 57, 63));
ChoisirCouleurDessin(CouleurParNom("white")); ChoisirCouleurDessin(CouleurParNom("white"));
for(i=0; i < (colonnes * lignes) / 2;) { for(i = 0; i < (colonnes * lignes) / 2;) {
r = rand() % 60 + 1; r = rand() % 60 + 1;
used=0; used = 0;
for(j=0; j < i; j++) { for (j = 0; j < i; j++) {
if(tab[j] == r) { if(tab[j] == r) {
used = 1; used = 1;
break; break;
} }
} }
if(!used) { if (!used) {
tab[i] = r; tab[i] = r;
i++; i++;
} }
} }
for (i=0; i<(colonnes*lignes)/2; i+=1) { for (i = 0; i < (colonnes * lignes) / 2; i++) {
tab[i+((colonnes*lignes)/2)] = tab[i]; tab[i + ((colonnes * lignes) / 2)] = tab[i];
} }
if ((colonnes * lignes) > 1) for (k = 0; k < (colonnes * lignes) - 1; k++) {
{ m = k + rand() / (RAND_MAX / ((colonnes * lignes) - k) + 1);
size_t i; t = tab[m];
for (i = 0; i < (colonnes * lignes) - 1; i++) tab[m] = tab[k];
{ tab[k] = t;
size_t j = i + rand() / (RAND_MAX / ((colonnes * lignes) - i) + 1);
int t = tab[j];
tab[j] = tab[i];
tab[i] = t;
}
} }
unsigned int case_max_width = (WINDOW_WIDTH - (GAME_MARGIN_RIGHT + GAME_MARGIN_LEFT)) / colonnes; case_max_width = (WINDOW_WIDTH - (GAME_MARGIN_RIGHT + GAME_MARGIN_LEFT)) / colonnes;
unsigned int case_max_height = (WINDOW_HEIGHT - (GAME_MARGIN_TOP + GAME_MARGIN_BOTTOM)) / lignes; case_max_height = (WINDOW_HEIGHT - (GAME_MARGIN_TOP + GAME_MARGIN_BOTTOM)) / lignes;
unsigned int case_max_dimensions;
if (case_max_height < case_max_width) { if (case_max_height < case_max_width) {
case_max_dimensions = case_max_height; case_max_dimensions = case_max_height;
@ -74,20 +70,20 @@ int game(int colonnes, int lignes) {
case_max_dimensions = case_max_width; case_max_dimensions = case_max_width;
} }
unsigned int case_margin = case_max_dimensions * 0.05; case_margin = case_max_dimensions * 0.05;
card cards[lignes][colonnes]; card cards[lignes][colonnes];
for (unsigned int l = 0; l < lignes; l += 1) { for (l = 0; l < lignes; l++) {
for (unsigned int c = 0; c < colonnes; c += 1) { for (c = 0; c < colonnes; c++) {
cards[l][c] = create_card(GAME_MARGIN_RIGHT + (c * case_max_dimensions), GAME_MARGIN_TOP + (l * case_max_dimensions), case_max_dimensions - (2 * case_margin), case_max_dimensions - (2 * case_margin)); cards[l][c] = create_card(GAME_MARGIN_RIGHT + (c * case_max_dimensions), GAME_MARGIN_TOP + (l * case_max_dimensions), case_max_dimensions - (2 * case_margin), case_max_dimensions - (2 * case_margin));
} }
} }
unsigned long int timer = start_timer(0); timer = start_timer(0);
int boucle = 1; boucle = 1;
while (boucle) { while (boucle) {
update_timer(timer); update_timer(timer);
} }
return fin(timer); return fin(timer);
} }s

View File

@ -4,8 +4,8 @@
#define DELTA 1000000L #define DELTA 1000000L
void update_timer(unsigned long int start) { void update_timer(unsigned long int start) {
unsigned int secondes = ((Microsecondes() - start) / DELTA); int secondes = ((Microsecondes() - start) / DELTA);
unsigned int minutes = 0; int minutes = 0;
char buf[100]; char buf[100];
while (secondes >= 60) { while (secondes >= 60) {
@ -29,5 +29,5 @@ unsigned long int start_timer(unsigned long int start) {
} }
unsigned long int stop_timer(unsigned long int start) { unsigned long int stop_timer(unsigned long int start) {
return Microsecondes()-start; return Microsecondes() - start;
} }