Bonjour, j'essaye de réaliser un sudoku pour un projet informatique à rendre pour dans 1 semaine mais le problème est que lorsque je veux afficher les numéros dans la grille (qui s'affiche normalement lorsque je ne rajoute pas les numéros) ma grille s'affiche mal et des numéros se superposent. Et il y a aussi le curseur que n'arrive pas à afficher.
Merci d'avance.
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
program Essai1SDL;
 
uses sdl, sdl_image, sysutils, crt, DOS;
 
type TGrille = array[1..9, 1..9] of Char;
	 GrilleSudoku = array [1..9] of array [1..9] of integer;  
     RegionInitial = array [1..9] of integer;  
	 GsdkM = array [1..9, 1..9] of boolean;
 
{---------------------------------------------------------------------}
 
procedure Creat ( var Gsdk : GrilleSudoku );  
       var Ireg : RegionInitial;  
           i, j, k, l : integer;  
          pre : boolean;  
       begin  
           for i := 1 to 9 do   
           begin  
               Ireg [i] := 0;  
           end;  
           j := 1;  
           while ( j < 10 ) do   
           begin  
               k := random (9) + 1;  
               pre := true;  
               while ( pre ) do  
               begin  
                   pre := false;  
                     for i := 1 to 9 do   
                      begin  
                           if (Ireg [i] = k) then pre := true;  
                    end;  
                    if ( pre ) then  
                    begin    
                         k := k + 1;  
                       if (k = 10) then k := 1;  
                    end;  
                end;  
                Ireg [j] := k;  
                j := j + 1;  
            end;  
 
            j := 1;  
            l := 1;  
            while ( j <> 0 ) do  
            begin  
                 k := j;  
                  for i := 1 to 9 do  
                 begin  
                      Gsdk [i, l] := Ireg [k];  
                    k := k + 1;  
                     if ( k > 9 ) then k := k - 9;  
                end;  
                l := l + 1;  
                case ( j ) of  
                1 : j := 4;  
                4 : j := 7;  
                7 : j := 8;  
                8 : j := 2;  
                2 : j := 5;  
                5 : j := 6;  
                6 : j := 9;  
                9 : j := 3;  
                3 : j := 0;  
                end;  
            end;  
        end;  
 
	procedure remix ( var Gsdk : GrilleSudoku );  
        var i, j, k : integer;  
           GsdkTemp : GrilleSudoku;  
           Hreg : RegionInitial;  
        begin  
 
            i := 1;  
            j := random (2) + 2;  
            for k := 1 to 9 do   
            begin  
                 if ((k = 4) or (k = 7)) then j := random (3) + 1;  
                 case k of  
                1..3 : Hreg [i] := j;  
                4..6 : Hreg [i] := j + 3;  
                7..9 : Hreg [i] := j + 6;  
                end;  
               j := j + 1;  
                i := i + 1;  
                if ( j = 4 ) then j := 1;  
            end;  
 
            for i := 1 to 9 do  
              for j := 1 to 9 do  
              begin  
                   k := Hreg [i];  
                   GsdkTemp [i, j] := Gsdk [k, j];   
              end;   
 
            k := 7;  
            i := 1;  
            while ( k <> 0 ) do  
            begin  
                 for j := 1 to 9 do  
                 begin  
                     Gsdk [i, j] := GsdkTemp [k, j];  
                    Gsdk [i+1, j] := GsdkTemp [k+1, j];  
                    Gsdk [i+2, j] := GsdkTemp [k+2, j];  
                end;  
                case (k) of  
                7 : begin k := 1; i := 4; end;  
                1 : begin k := 4; i := 7; end;  
                4 : begin k := 0; end;  
                end;  
            end;  
        end;  
 
procedure generateur ( var Gsdk : GrilleSudoku );
    begin  
        Creat ( Gsdk );  
        remix ( Gsdk );
    end;
 
    procedure masque (var Gsdk : GrilleSudoku; var GsdkJ : GrilleSudoku; var mask : GsdkM );  
    var i, j, ix, jx : integer; 
		Nbre_cases_masquees : Integer; 
    begin 
    Nbre_cases_masquees:=2;
         for i := 1 to 9 do  
           for j := 1 to 9 do  
             mask [i, j] := false; 
        for i := 1 to Nbre_cases_masquees do   
        begin  
             repeat  
                ix := random (9) + 1;  
                jx := random (9) + 1;  
            until not mask [ix, jx];  
            mask [ix, jx] := true;  
        end;  
        for j := 1 to 9 do  
          for i := 1 to 9 do  
          begin     
               if ( not mask [i, j] ) then  
               GsdkJ [i, j] := Gsdk [i, j]  
              else GsdkJ [i, j] := 0;  
          end;  
	end; 
 
 
Procedure RemplirGrille(GsdkJ : GrilleSudoku; var FichierGsdk : Text);
var i,j : Integer;
	GsdkL : array [1..9,1..9] of char;
begin
assign(FichierGsdk, 'FichierGsdk.txt');
Rewrite(FichierGsdk);
for i:=1 to 9 do
	begin
	for j:=1 to 9 do
		begin
			case GsdkJ[i, j] of
			0 : begin
					GsdkL[i, j] := 'm';
				end;
 
			1 : begin
					GsdkL[i, j] := 'a';
				end;
 
			2 : begin
					GsdkL[i, j] := 'b';
				end;
 
			3 : begin
					GsdkL[i, j] := 'c';
				end;
 
			4 : begin
					GsdkL[i, j] := 'd';
				end;
 
			5 : begin
					GsdkL[i, j] := 'e';
				end;
 
			6 : begin
					GsdkL[i, j] := 'f';
				end;
 
			7 : begin
					GsdkL[i, j] := 'g';
				end;
 
			8 : begin
					GsdkL[i, j] := 'h';
				end;
 
			9 : begin
					GsdkL[i, j] := 'i';
				end;
			end;
		write(FichierGsdk, GsdkL[i, j]);
		end;
	writeln(FichierGsdk);
	end;
close(FichierGsdk);
end;		 
 
{-----------------SDL début-------------------------------------------}  
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('caseA.png');
    TImage[2] := IMG_Load('caseB.png');
    TImage[3] := IMG_Load('caseC.png');
    TImage[4] := IMG_Load('caseD.png');
 
    TImage[5] := IMG_Load('curseur.png');		
 
	TImage[6] := IMG_Load('chiffre1.png');
	TImage[7] := IMG_Load('chiffre2.png');
	TImage[8] := IMG_Load('chiffre3.png');
	TImage[9] := IMG_Load('chiffre4.png');
	TImage[10] := IMG_Load('chiffre5.png');
	TImage[11] := IMG_Load('chiffre6.png');
	TImage[12] := IMG_Load('chiffre7.png');
	TImage[13] := IMG_Load('chiffre8.png');
	TImage[14] := IMG_Load('chiffre9.png');
 
end;
 
 
{lit le fichier et met les valeurs lues dans un tableau}
 
procedure LoadGrille(FGrille : String ; var AGrille : TGrille);
var FichierG : Text;
    Buffer : String;
    x, y : Integer;
    Iterator : Char;
 
begin
    y := 1;
    Assign(FichierG, FGrille);
    Reset(FichierG);
    while not Eof(FichierG) do
    begin
        Readln(FichierG, Buffer);
        x := 1;
        for Iterator in Buffer do
        begin
            AGrille[y][x] := Iterator;
            x := x + 1;
        end;
        y := y + 1;
    end;
    Close(FichierG);
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 9 do
        begin
            Position.x := (x - 1) * 61;
            Position.y := (y - 1) * 61;
            if String(AGrille[y][x]) = 'a' then
                SDL_BlitSurface(TImage[1], nil, AWindow, @Position);
			if String(AGrille[y][x]) = 'b' then
                SDL_BlitSurface(TImage[2], nil, AWindow, @Position);
			if String(AGrille[y][x]) = 'c' then
                SDL_BlitSurface(TImage[3], nil, AWindow, @Position);                
            if String(AGrille[y][x]) = 'd' then
                SDL_BlitSurface(TImage[4] , nil, AWindow, @Position);
        end;
    end;
end;
 
procedure DrawCursor(AWindow : PSDL_Surface;  x, y : Integer ; var ACursor : PSDL_Surface);
 
var Position : TSDL_Rect;
 
begin
    Position.x := (x-1) * 61;
    Position.y := (y-1) * 61;
    SDL_BlitSurface(ACursor , nil, AWindow, @Position);
end;
 
procedure DrawChiffre (AWindow : PSDL_Surface; GrilleJ : TGrille; mask : GsdkM; var TImage : array of PSDL_Surface);
var x, y : Integer;
	Position : TSDL_Rect;
 
begin
 
	for y := 1 to 9 do
	begin
		for x := 1 to 9 do
		begin
			Position.x := (x - 1) * 61;
			Position.y := (y - 1) * 61;
				if String(GrilleJ[y][x]) = 'a' then
					if (mask[x, y] = false) then
						SDL_BlitSurface(TImage[6], nil, AWindow, @Position);
				if String(GrilleJ[y][x]) = 'b' then
					if (mask[x, y] = false) then
						SDL_BlitSurface(TImage[7], nil, AWindow, @Position);
				if String(GrilleJ[y][x]) = 'c' then
					if (mask[x, y] = false) then
						SDL_BlitSurface(TImage[8], nil, AWindow, @Position);                
				if String(GrilleJ[y][x]) = 'd' then
					if (mask[x, y] = false) then
						SDL_BlitSurface(TImage[9] , nil, AWindow, @Position);
				if String(GrilleJ[y][x]) = 'e' then
					if (mask[x, y] = false) then
						SDL_BlitSurface(TImage[10] , nil, AWindow, @Position);
				if String(GrilleJ[y][x]) = 'f' then
					if (mask[x, y] = false) then
						SDL_BlitSurface(TImage[11] , nil, AWindow, @Position);
				if String(GrilleJ[y][x]) = 'g' then
					if (mask[x, y] = false) then
						SDL_BlitSurface(TImage[12] , nil, AWindow, @Position);
				if String(GrilleJ[y][x]) = 'h' then
					if (mask[x, y] = false) then
						SDL_BlitSurface(TImage[13] , nil, AWindow, @Position);
				if String(GrilleJ[y][x]) = 'i' then
					if (mask[x, y] = false) then
						SDL_BlitSurface(TImage[14] , nil, AWindow, @Position);
 
		end;
	end;
end;				
 
{---------------------------------------------------------------------}
 
function CValide(AGrille : TGrille; x, y : Integer) : Boolean;
 
begin
    if (x = -1) or (x = 9) or (y = -1) or (y = 9) then 
		Exit(False)
	else	
        Exit(True);    
end;
 
{---------------------------------------------------------------------}
 
procedure FreeImages(var TImage : Array of PSDL_Surface);
 
var i : Integer;
 
begin
    for i := 1 to 15 do
    begin
        Dispose(TImage[i]);
    end;
end;
 
 
{---------------------------------------------------------------------}
var Grille, GrilleJ : TGrille;
    Image : Array [1..14] of PSDL_Surface;
    Window : PSDL_Surface;
    Gsdk,GsdkJ : GrilleSudoku;   
	mask : GsdkM; 
	FichierGsdk : text;
 
begin
	generateur ( Gsdk );  
	masque (Gsdk, GsdkJ, mask );
	RemplirGrille(Gsdk, FichierGsdk);
    LoadGrille('grilleSdk.txt', Grille);
    LoadGrille('FichierGsdk.txt', GrilleJ);
    LoadImage(Image);
    Window := NewWindow(549,700, 'SUDOKU');
    DrawScene(Window, Image, Grille);
	DrawChiffre (Window, GrilleJ, mask, Image);
    SDL_Flip(Window);
    SDL_Delay(300000000);
    FreeImages(Image);
    SDL_Quit;
end.
ImageSDL.zip