Bonjour, je doit faire en devoir un jeu d'echec, et je m'emelle avec les headers... J'ai une erreur de definition multiple des variables ^^'
Je code avec SDL, si pouviez m'aider ça serait cool
Voici mon code :
main :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156 #include <SDL/SDL.h> #include <SDL/SDL_image.h> #include <SDL/SDL_ttf.h> #include "constantes.h" #include <string> #include "fonctions.h" #include "global.h" int main( int argc, char* args[] ) { int positiontx = 260; int positionty = 805-80; int positionBlancx = 300; int positionBlancy = 140; int positionVertx = 380; int positionVerty = 140; //Make sure the program waits for a quit bool quit = false; //Initialize if( init() == false ) { return 1; } //Load the files if( load_files() == false ) { return 1; } //Apply the surface to the screen apply_surface( 0, 0, imageDeFond, screen ); char lettre[2]="A"; for(char k='A'; k<'I'; k++) { lettre[0]=k; texte = TTF_RenderText_Blended(police,lettre,textColor); apply_surface( positiontx, positionty, texte, screen); positionty-=80; } positiontx = 260+640+60; positionty = 805-80; char lettre2[2]="A"; for(char k='A'; k<'I'; k++) { lettre2[0]=k; texte = TTF_RenderText_Blended(police,lettre2,textColor); apply_surface( positiontx, positionty, texte, screen); positionty-=80; } positiontx = 330; positionty = 100; char chiffre[2]="1"; for(char k='1'; k<'9'; k++) { chiffre[0]=k; texte = TTF_RenderText_Blended(police,chiffre,textColor); apply_surface( positiontx, positionty, texte, screen); positiontx+=80; } positiontx = 330; positionty = 790; char chiffre2[2]="1"; for(char k='1'; k<'9'; k++) { chiffre2[0]=k; texte = TTF_RenderText_Blended(police,chiffre2,textColor); apply_surface( positiontx, positionty, texte, screen); positiontx+=80; } //If there was an error in rendering the text if( texte == NULL ) { return 1; } do { do { apply_surface( positionBlancx, positionBlancy, blanc, screen ); positionBlancx = positionBlancx+160; apply_surface( positionVertx, positionVerty, vert, screen ); positionVertx = positionVertx+160; }while(positionBlancx < 890 && positionVertx < 975); positionBlancx = 300; positionBlancy = positionBlancy+160; positionVertx = 380; positionVerty = positionVerty+160; }while (positionBlancy < 640+140 && positionVerty < 640+140); positionBlancx = 380; positionBlancy = 80+140; positionVertx = 300; positionVerty = 80+140; do { do { apply_surface( positionBlancx, positionBlancy, blanc, screen ); positionBlancx = positionBlancx+160; apply_surface( positionVertx, positionVerty, vert, screen ); positionVertx = positionVertx+160; }while(positionBlancx < 975 && positionVertx < 890); positionVertx = 300; positionVerty = positionVerty+160; positionBlancx = 380; positionBlancy = positionBlancy+160; }while (positionBlancy < 640+140 && positionVerty < 640+140); //Update the screen if( SDL_Flip( screen ) == -1 ) { return 1; } //While the user hasn't quit //Tant que l'utilisateur n'a pas quitter while( quit == false ) { //tant qu'il y a un evenement dans le handler while( SDL_PollEvent( &event ) ) { //Si l'utilisateur ferme la fenetre avec le X if( event.type == SDL_QUIT ) { //On quitte le programme quit = true; } } } clean_up(); return 0; }
fonction.cpp :
.h :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145 #include "SDL/SDL.h" #include "SDL/SDL_image.h" #include <string> #include "constantes.h" #include "fonctions.h" #include "global.h" SDL_Surface *load_image( std::string filename ) { //The image that's loaded SDL_Surface* loadedImage = NULL; //The optimized image that will be used SDL_Surface* optimizedImage = NULL; //Load the image loadedImage = IMG_Load( filename.c_str() ); //If the image loaded if( loadedImage != NULL ) { //Create an optimized image optimizedImage = SDL_DisplayFormat( loadedImage ); //Free the old image SDL_FreeSurface( loadedImage ); if( optimizedImage != NULL ) { //Map the color key Uint32 colorkey = SDL_MapRGB( optimizedImage->format, 0, 0xFF, 0xFF ); //Set all pixels of color R 0, G 0xFF, B 0xFF to be transparent SDL_SetColorKey( optimizedImage, SDL_SRCCOLORKEY, colorkey ); } } //Return the optimized image return optimizedImage; } void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination ) { SDL_Rect offset; offset.x = x; offset.y = y; //on blit la surface SDL_BlitSurface( source, NULL, destination, &offset ); } bool init() { //Initialize all SDL subsystems if( SDL_Init( SDL_INIT_EVERYTHING ) == -1 ) { return false; } //Set up the screen screen = SDL_SetVideoMode(1280, 960, 32, SDL_HWSURFACE | SDL_DOUBLEBUF); //If there was an error in setting up the screen if( screen == NULL ) { return false; } //Initialize SDL_ttf if( TTF_Init() == -1 ) { return false; } //Set the window caption SDL_WM_SetCaption( "Event test", NULL ); //If everything initialized fine return true; } bool load_files() { //Load the image imageDeFond = load_image( "images/pierre.jpg" ); vert = load_image("images/vert.jpg"); blanc = load_image("images/blanc.jpg"); pieceFouNoir = load_image("images/pieceFouNoir.bmp"); pieceFouBlanc = load_image("images/pieceFouBlanc.bmp"); pieceDameNoir = load_image("images/pieceDameNoir.bmp"); pieceDameBlanc = load_image("images/pieceDameBlanc.bmp"); pieceCavalierNoir = load_image("images/pieceCavalierNoir.bmp"); pieceCavalierBlanc = load_image("images/pieceCavalierBlanc.bmp"); pieceRoiNoir = load_image("images/pieceRoiNoir.bmp"); pieceRoiBlanc = load_image("images/pieceRoiBlanc.bmp"); pieceTourNoir = load_image("images/pieceTourNoir.bmp"); pieceTourBlanc = load_image("images/pieceTourBlanc.bmp"); piecePionNoir = load_image("images/piecePionNoir.bmp"); piecePionBlanc = load_image("images/piecePionBlanc.bmp"); police = TTF_OpenFont("calibri.ttf", 35); //If there was an error in loading the image if( imageDeFond == NULL ) { return false; } //If there was an error in loading the font if( police == NULL ) { return false; } //If everything loaded fine return true; } void clean_up() { //Free the image SDL_FreeSurface(pieceFouNoir); SDL_FreeSurface(pieceFouBlanc); SDL_FreeSurface(pieceDameNoir); SDL_FreeSurface(pieceDameBlanc); SDL_FreeSurface(pieceCavalierNoir); SDL_FreeSurface(pieceCavalierBlanc); SDL_FreeSurface(pieceRoiNoir); SDL_FreeSurface(pieceRoiBlanc); SDL_FreeSurface(pieceTourNoir); SDL_FreeSurface(pieceTourBlanc); SDL_FreeSurface(piecePionNoir); SDL_FreeSurface(piecePionBlanc); SDL_FreeSurface(imageDeFond); SDL_FreeSurface(vert); SDL_FreeSurface(blanc); //Quit SDL SDL_Quit(); }
et les variable globales (je sais c'est pas bien ) :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 #ifndef FoNCTIONS_H #define FoNCTIONS_H //The headers #include "SDL/SDL.h" #include "SDL/SDL_image.h" #include <string> //File Loader SDL_Surface *load_image( std::string filename ); //Surface blitter void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination ); //Initialization bool init(); //File loading bool load_files(); //Clean up void clean_up(); #endif
.cpp
.h
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 //The headers #include "SDL/SDL.h" #include "global.h" //The surfaces SDL_Surface *imageDeFond = NULL; SDL_Surface *vert = NULL; SDL_Surface *blanc; SDL_Surface *texte = NULL; SDL_Surface *screen = NULL; SDL_Surface *piecePionBlanc = NULL; SDL_Surface *piecePionNoir = NULL; SDL_Surface *pieceRoiNoir = NULL; SDL_Surface *pieceRoiBlanc = NULL; SDL_Surface *pieceTourBlanc = NULL; SDL_Surface *pieceTourNoir = NULL; SDL_Surface *pieceFouBlanc = NULL; SDL_Surface *pieceFouNoir = NULL; SDL_Surface *pieceCavalierNoir = NULL; SDL_Surface *pieceCavalierBlanc = NULL; SDL_Surface *pieceDameNoir = NULL;, SDL_Surface *pieceDameBlanc = NULL; //The event structure SDL_Event event;
J'ai aussi un .h constantes mais il n'y a que la definition d'une structure que je ne n'utilise pas encore !
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39 #ifndef GLOBAL_H #define GLOBAL_H #include "SDL/SDL.h" #include "SDL/SDL_ttf.h" //extern struct Forme quadri[16][12]; //Echiquier extern SDL_Surface *imageDeFond = NULL; extern SDL_Surface *vert = NULL; extern SDL_Surface *blanc; extern SDL_Surface *texte = NULL; extern SDL_Surface *screen = NULL; //Pieces extern SDL_Surface *piecePionBlanc = NULL; extern SDL_Surface *piecePionNoir = NULL; extern SDL_Surface *pieceRoiNoir = NULL; extern SDL_Surface *pieceRoiBlanc = NULL; extern SDL_Surface *pieceTourBlanc = NULL; extern SDL_Surface *pieceTourNoir = NULL; extern SDL_Surface *pieceFouNoir = NULL; extern SDL_Surface *pieceFouBlanc = NULL; extern SDL_Surface *pieceCavalierNoir = NULL; extern SDL_Surface *pieceCavalierBlanc = NULL; extern SDL_Surface *pieceDameNoir = NULL; extern SDL_Surface *pieceDameBlanc = NULL; //Texte extern TTF_Font *police = NULL; extern SDL_Color textColor = { 0, 0, 0 }; //La structure d'evenement extern SDL_Event event; #endif // GLOBAL_H
Merci de votre aide !
Partager