Salut à tous !

Je viens à vous car j'ai un gros problème avec mon code. En effet, je dois réaliser, dans le cadre d'un projet, une SDL pour le jeu du Memory. Néanmoins, je n'arrive pas à retourner deux cartes différentes. En effet, lorsque je clique sur "entrée" la première carte se dévoile mais à chaque nouveau clic celle-ci se déplace à l'endroit du clic.

Voici mon code, pour vous donner une idée :
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
program Memory2SDL;
 
uses sdl, sdl_image, sysutils;
 
type TGrille = array[1..9, 1..11] of Char;
 
{---------------------------------------------------------------------}
 
function NewWindow(x, y : Integer ; Caption : PChar) : PSDL_Surface;
 
var Window : PSDL_Surface;
 
begin
    SDL_Init(SDL_INIT_VIDEO);
    Window := SDL_SetVideoMode(x, y, 32, SDL_DOUBLEBUF);
    SDL_WM_SetCaption(Caption, Nil);
    Exit(Window);
end;
 
 
{---------------------------------------------------------------------}
 
 
procedure LoadImage(var TImage : Array of PSDL_Surface);
begin
    TImage[1] := IMG_Load('Fond.png');
    TImage[2] := IMG_Load('Carte.png');
    TImage[3] := IMG_Load('Curseur.png');
    TImage[4] := IMG_Load('Carte2.png');
 
end;
 
 
{---------------------------------------------------------------------}
 
 
procedure LoadGrille(FGrille : String ; var AGrille : TGrille);
var LevelGrille : Text;
    Buffer : String;
    x, y : Integer;
    Iterator : Char;
 
begin
    y := 1;
    Assign(LevelGrille, FGrille);
    Reset(LevelGrille);
    while not Eof(LevelGrille) do
    begin
        Readln(LevelGrille, Buffer);
        x := 1;
        for Iterator in Buffer do
        begin
            AGrille[y][x] := Iterator;
            x := x + 1;
        end;
        y := y + 1;
    end;
    Close(LevelGrille);
end;
 
 
{---------------------------------------------------------------------}
 
 
procedure DrawScene(AWindow : PSDL_Surface ; var TImage : Array of PSDL_Surface ;
    var AGrille : TGrille);
 
var x, y : Integer;
    Position : TSDL_Rect;
 
begin
    for y := 1 to 9 do
    begin
        for x := 1 to 11 do
        begin
            Position.x := (x - 1) * 80;
            Position.y := (y - 1) * 80;
            if String(AGrille[y][x]) = 'f' then
                SDL_BlitSurface(TImage[1], nil, AWindow, @Position);
            if String(AGrille[y][x]) = 'c' then
                SDL_BlitSurface(TImage[2] , nil, AWindow, @Position);
        end;
    end;
end;
 
 
{---------------------------------------------------------------------}
 
 
procedure DrawCursor(AWindow : PSDL_Surface;  x, y : Integer ; ACursor : PSDL_Surface);
 
var Position : TSDL_Rect;
 
begin
    Position.x := (x) * 80;
    Position.y := (y) * 80;
    SDL_BlitSurface(ACursor, nil, AWindow, @Position);
end;
 
 
{---------------------------------------------------------------------}
 
 
procedure DrawCarte1(AWindow : PSDL_Surface;  x, y : Integer ; ACarte : PSDL_Surface);
 
var Position : TSDL_Rect;
 
begin
    Position.x := x * 80;
    Position.y := y * 80;
    SDL_BlitSurface(ACarte, nil, AWindow, @Position);
end;
 
 
{---------------------------------------------------------------------}
 
 
function CValide(AGrille : TGrille; x, y : Integer) : Boolean;
 
begin
    if (x = -1) or (x = 11) or (y = -1) or (y = 9) then 
		Exit(False)
	else	
        Exit(True);    
end;
 
 
{---------------------------------------------------------------------}
 
 
 
procedure PBoucle(AWindow : PSDL_Surface ; var TImage : Array of PSDL_Surface ;
    var AGrille : TGrille);
 
var Event : TSDL_Event;
    Fin : Boolean;
    C_x, S_x : Integer;
    C_y, S_y : Integer;
    Cursor : PSDL_Surface;
 
begin
    Fin := False;
    C_x := 1;
    C_y := 1;
    Cursor := TImage[3];
    while not Fin do
    begin
        while SDL_PollEvent(@Event) <> 0 do
        begin
            if Event.Type_ = SDL_QUITEV then
                Fin := True;
            if Event.Type_ = SDL_KEYDOWN then
            begin
                case Event.key.keysym.sym of 
 
		SDLK_DOWN :	begin
						if CValide(AGrille, C_x, C_y + 2) then
						begin
							C_y += 2;
						end;
					end;
 
		SDLK_UP : begin
						if CVAlide(AGrille, C_x, C_y - 2) then
						begin
							C_y -= 2;
						end;
					end;
 
		SDLK_LEFT : begin
						if CValide(AGrille, C_x - 2, C_y)=True then
						begin
							C_x -= 2;
						end;
					end;
 
		SDLK_RIGHT : begin
						if CValide(AGrille, C_x + 2, C_y) then
						begin
							C_x += 2;
						end;
					end;
 
		SDLK_RETURN : begin
						S_x:=C_x;
						S_y:=C_y;
					end;
            end;
        end;
        DrawScene(AWindow, TImage, AGrille);
        DrawCursor(AWindow, C_x, C_y, Cursor); 
        DrawCarte1(Awindow, S_x, S_y, TImage[4]);
 
        SDL_Flip(AWindow);
        SDL_Delay(30);
    end;
end;
end;
 
{---------------------------------------------------------------------}
 
 
procedure FreeImages(var Image : Array of PSDL_Surface);
 
var i : Integer;
 
begin
    for i := 1 to 4 do
    begin
        Dispose(Image[i]);
    end;
end;
 
 
{---------------------------------------------------------------------}
 
 
var Grille : TGrille;
    Image : Array [1..5] of PSDL_Surface;
    Window : PSDL_Surface;
 
begin
    LoadGrille('level2.grille', Grille);
    LoadImage(Image);
    Window := NewWindow(880, 700, 'Memory - Niveau : Intermédiaire');
    PBoucle(Window, Image, Grille);
    FreeImages(Image);
    SDL_Quit;
end.
Merci d'avance