Ajout de la sélection aléatoire des images
This commit is contained in:
parent
95016b63a1
commit
30d3f4c360
39
src/game.c
39
src/game.c
@ -1,6 +1,7 @@
|
|||||||
#include<stdio.h>
|
#include<stdio.h>
|
||||||
#include<stdlib.h>
|
#include<stdlib.h>
|
||||||
#include<graph.h>
|
#include<graph.h>
|
||||||
|
#include<time.h>
|
||||||
#include"../include/main.h"
|
#include"../include/main.h"
|
||||||
#include"../include/timer.h"
|
#include"../include/timer.h"
|
||||||
#include"../include/fin.h"
|
#include"../include/fin.h"
|
||||||
@ -22,9 +23,47 @@ 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 used, r;
|
||||||
|
int* tab = malloc(sizeof(int) * (colonnes * lignes));
|
||||||
|
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;) {
|
||||||
|
r = rand() % 60 + 1;
|
||||||
|
used=0;
|
||||||
|
|
||||||
|
for(j=0; j < i; j++) {
|
||||||
|
if(tab[j] == r) {
|
||||||
|
used = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!used) {
|
||||||
|
tab[i] = r;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i=0; i<(colonnes*lignes)/2; i+=1) {
|
||||||
|
tab[i+((colonnes*lignes)/2)] = tab[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((colonnes * lignes) > 1)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
for (i = 0; i < (colonnes * lignes) - 1; i++)
|
||||||
|
{
|
||||||
|
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;
|
unsigned int 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;
|
unsigned int case_max_height = (WINDOW_HEIGHT - (GAME_MARGIN_TOP + GAME_MARGIN_BOTTOM)) / lignes;
|
||||||
unsigned int case_max_dimensions;
|
unsigned int case_max_dimensions;
|
||||||
|
Loading…
Reference in New Issue
Block a user