IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Free Pascal Discussion :

Réalisation d'un jeu de Sudoku avec la SDL [Free Pascal]


Sujet :

Free Pascal

  1. #1
    Nouveau Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Novembre 2014
    Messages
    7
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 28
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Novembre 2014
    Messages : 7
    Points : 1
    Points
    1
    Par défaut Réalisation d'un jeu de Sudoku avec la SDL
    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

  2. #2
    Rédacteur/Modérateur

    Avatar de Roland Chastain
    Homme Profil pro
    Enseignant
    Inscrit en
    Décembre 2011
    Messages
    4 085
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 51
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Décembre 2011
    Messages : 4 085
    Points : 15 507
    Points
    15 507
    Billets dans le blog
    9
    Par défaut
    Bonjour !

    On ne peut pas essayer le programme que tu as posté : il manque le fichier "grilleSdk.txt".

    En attendant de pouvoir t'aider davantage, une petite remarque : les unités Sysutils, Crt et Dos sont déclarées mais pas utilisées.

  3. #3
    Nouveau Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Novembre 2014
    Messages
    7
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 28
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Novembre 2014
    Messages : 7
    Points : 1
    Points
    1
    Par défaut
    Voilà le fichier qu'il manquait, il permet d'afficher la grille dans la sdl en associant chaque lettre à une case.
    Fichiers attachés Fichiers attachés

  4. #4
    Rédacteur/Modérateur

    Avatar de Roland Chastain
    Homme Profil pro
    Enseignant
    Inscrit en
    Décembre 2011
    Messages
    4 085
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 51
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Décembre 2011
    Messages : 4 085
    Points : 15 507
    Points
    15 507
    Billets dans le blog
    9
    Par défaut
    J'ai essayé ton programme. Je n'ai pas de chiffres qui se superposent, ni de problème pour afficher le curseur (si ce n'est que, dans le code que tu as posté, la procédure DrawCursor() n'est pas appelée mais ça j'imagine que tu le sais).

    Au passage, j'ai ajouté un appel à la procédure Randomize au début du programme principal.

    Je regrette, je n'ai rien de mieux à te dire pour le moment.

  5. #5
    Nouveau Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Novembre 2014
    Messages
    7
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 28
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Novembre 2014
    Messages : 7
    Points : 1
    Points
    1
    Par défaut
    Merci, je vais voir je ne comprends pas bien mais s'il y marche sur ton pc y a pas de raison :p

  6. #6
    Nouveau Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Novembre 2014
    Messages
    7
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 28
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Novembre 2014
    Messages : 7
    Points : 1
    Points
    1
    Par défaut Problème avec les coordonnées en sdl
    Bonjour à tous, je fais appelle à ce forum parce que j'ai un petit soucis avec les coordonnées de ma SDL. Je m'explique, j'ai créé une grille de sudoku avec les numéros et le curseur et tout s'affiche bien mais dès que je veux faire bouger le curseur dans la SDL le mouvement est bloqué à certains moments où il ne devrait pas mais à l'inverse il peut sortir de ma fenêtre SDL.. Ensuite je cherche à permettre au joueur de rentrer les chiffres pour compléter les cases mais il arrive qu'il ne s'affiche pas du tout ou pas dans la bonne case ou parfois même pas le bon numéro..

    Merci d'avance pour votre aide

    PS : Dans le zip vous trouverez les photos et les fichier nécessaires à l'exécution et aussi le programme
    Fichiers attachés Fichiers attachés

  7. #7
    Nouveau Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Novembre 2014
    Messages
    7
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 28
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Novembre 2014
    Messages : 7
    Points : 1
    Points
    1
    Par défaut
    J'ai modifié quelques éléments qui me permettent de bien me retrouver avec les coordonnées je pense mais j'ai toujours un problème pour afficher les numéros voulus par le joueur..

    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
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    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;
    	 Photo = array [1..14] of PSDL_Surface;
    Const 	SDL_KEYDOWN    =   2; 
    		SDL_QUITEV     =  12; 
     
    		SDLK_UP        = 273; 
    		SDLK_DOWN      = 274; 
    		SDLK_RIGHT     = 275; 
    		SDLK_LEFT      = 276;
    {---------------------------------------------------------------------}
     
    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:=30;
             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;  
    	for i:=1 to 9 do
        begin
    		for j:=1 to 9 do 
    		write(GsdkJ[i,j]);
    		writeln();
    	end;
    	writeln();
    	for i:=1 to 9 do
        begin
    		for j:=1 to 9 do 
    		write(Gsdk[i,j]);
    		writeln();
        end;
    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 : Photo);
    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 : Photo ; 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 (AGrille[y][x]) = 'a' then
                    SDL_BlitSurface(TImage[1], nil, AWindow, @Position);
    			if (AGrille[y][x]) = 'b' then
                    SDL_BlitSurface(TImage[2], nil, AWindow, @Position);
    			if (AGrille[y][x]) = 'c' then
                    SDL_BlitSurface(TImage[3], nil, AWindow, @Position);                
                if (AGrille[y][x]) = 'd' then
                    SDL_BlitSurface(TImage[4] , nil, AWindow, @Position);
            end;
        end;
    end;
     
    procedure DrawChiffre (AWindow : PSDL_Surface; GsdkJ : GrilleSudoku; var TImage : Photo);
    var x, y : Integer;
    	Position : TSDL_Rect;
     
    begin
    	for x:= 1 to 9 do
    	begin
    		for y := 1 to 9 do
    		begin
    			Position.y := (x - 1) * 61;
    			Position.x := (y - 1) * 61;
     
    				if (GsdkJ[x][y]) = 1 then
    					SDL_BlitSurface(TImage[6], nil, AWindow, @Position);
    				if (GsdkJ[x][y]) = 2 then
    					SDL_BlitSurface(TImage[7], nil, AWindow, @Position);
    				if (GsdkJ[x][y]) = 3 then
    					SDL_BlitSurface(TImage[8], nil, AWindow, @Position);                
    				if (GsdkJ[x][y]) = 4 then
    					SDL_BlitSurface(TImage[9] , nil, AWindow, @Position);
    				if (GsdkJ[x][y]) = 5 then
    					SDL_BlitSurface(TImage[10] , nil, AWindow, @Position);
    				if (GsdkJ[x][y]) = 6 then
    					SDL_BlitSurface(TImage[11] , nil, AWindow, @Position);
    				if (GsdkJ[x][y]) = 7 then
    					SDL_BlitSurface(TImage[12] , nil, AWindow, @Position);
    				if (GsdkJ[x][y]) = 8 then
    					SDL_BlitSurface(TImage[13] , nil, AWindow, @Position);
    				if (GsdkJ[x][y]) = 9 then
    					SDL_BlitSurface(TImage[14] , nil, AWindow, @Position);
     
    		end;
    	end;
    end;
     
    {procedure DrawChiffreE (AWindow : PSDL_Surface; var GsdkJ : GrilleSudoku; var x, y : Integer; var TImage : Photo);
    var	Position : TSDL_Rect;
     
    begin
    Position.y := (x - 1) * 61;
    Position.x := (y - 1) * 61;
     
    	if (GsdkJ[x][y]) = 1 then
    		SDL_BlitSurface(TImage[6], nil, AWindow, @Position);
    	if (GsdkJ[x][y]) = 2 then
    		SDL_BlitSurface(TImage[7], nil, AWindow, @Position);
    	if (GsdkJ[x][y]) = 3 then
    		SDL_BlitSurface(TImage[8], nil, AWindow, @Position);                
    	if (GsdkJ[x][y]) = 4 then
    		SDL_BlitSurface(TImage[9] , nil, AWindow, @Position);
    	if (GsdkJ[x][y]) = 5 then
    		SDL_BlitSurface(TImage[10] , nil, AWindow, @Position);
    	if (GsdkJ[x][y]) = 6 then
    		SDL_BlitSurface(TImage[11] , nil, AWindow, @Position);
    	if (GsdkJ[x][y]) = 7 then
    		SDL_BlitSurface(TImage[12] , nil, AWindow, @Position);
    	if (GsdkJ[x][y]) = 8 then
    		SDL_BlitSurface(TImage[13] , nil, AWindow, @Position);
    	if (GsdkJ[x][y]) = 9 then
    		SDL_BlitSurface(TImage[14] , nil, AWindow, @Position);
    end;}
     
    procedure DrawCursor(AWindow : PSDL_Surface; var x, y : Integer; var TImage : Photo);
     
    var Position : TSDL_Rect;
     
    begin
    	Position.x := (x-1) * 61;
        Position.y := (y-1) * 61;
        SDL_BlitSurface(TImage[5], nil, AWindow, @Position);
    end;
    {---------------------------------------------------------------------}
     
    function CValide(x, y : Integer) : Boolean;
     
    begin
        //if (x > -1) and (x < 10) and (y > -1) and (y < 10) then 
    		Exit(True)
    	//else	
           // Exit(False);    
    end;
     
    procedure BoucleJeu(AWindow : PSDL_Surface; GsdkJ, Gsdk : GrilleSudoku; mask : GsdkM; var TImage : Photo; var AGrille : TGrille); 
    var 
        Event : TSDL_Event; 
        {Variable qui quand est a true, ordonne de quitter} 
        Fin : Boolean; 
    	x, y : Integer;
    	//num : Integer;
    	nbAide : Integer;
     
    begin 
        Fin := False;
    	x := 1; 
        y := 1;
        nbAide := 0;
        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 
     
    				if Event.key.keysym.sym  =  SDLK_DOWN then 
                    begin 
                        if CValide(x, y-1) then 
                        begin 
                            y:=y+1; 
                        end; 
                    end; 
     
    				if Event.key.keysym.sym  =  SDLK_UP then 
                    begin 
                        if CValide(x, y+1) then 
                        begin 
                            y:=y-1; 
                        end; 
                    end;
     
    				if Event.key.keysym.sym  =  SDLK_RIGHT then 
                    begin 
                        if CValide(x+1, y) then 
                        begin 
                            x:=x+1; 
                        end; 
                    end;
     
    				if Event.key.keysym.sym  =  SDLK_LEFT then 
                    begin 
                        if CValide(x+1, y) then 
                        begin 
                            x:=x-1; 
                        end; 
                    end;
     
    				if Event.key.keysym.sym  =  SDLK_RETURN then 
                    begin 
                        Fin:=True;
    				end;
     
    				if Event.key.keysym.sym  =  SDLK_SPACE then 
                    begin 
                        if (nbAide < 3) then
    					begin
    						if mask [y, x] = True then
    						begin
    							GsdkJ[y, x] := Gsdk[y, x];
    							nbAide := nbAide+1;
    						end;
    					end;
    				end;
     
    				if (Event.key.keysym.sym  =  SDLK_KP1) and (mask [y, x] = True) then 
                    begin
    					GsdkJ[y, x]:=1;
    				end;
     
    				if (Event.key.keysym.sym  =  SDLK_KP1) and (mask [y, x] = True) then 
                    begin
    					GsdkJ[y, x]:=2;
    				end;
     
    				if (Event.key.keysym.sym  =  SDLK_KP1) and (mask [y, x] = True) then 
                    begin
    					GsdkJ[y, x]:=3;
    				end;
     
    				if (Event.key.keysym.sym  =  SDLK_KP1) and (mask [y, x] = True) then 
                    begin
    					GsdkJ[y, x]:=4;
    				end;
     
    				if (Event.key.keysym.sym  =  SDLK_KP1) and (mask [y, x] = True) then 
                    begin
    					GsdkJ[y, x]:=5;
    				end;
     
    				if (Event.key.keysym.sym  =  SDLK_KP1) and (mask [y, x] = True) then 
                    begin
    					GsdkJ[y, x]:=6;
    				end;
     
    				if (Event.key.keysym.sym  =  SDLK_KP1) and (mask [y, x] = True) then 
                    begin
    					GsdkJ[y, x]:=7;
    				end;
     
    				if (Event.key.keysym.sym  =  SDLK_KP1) and (mask [y, x] = True) then 
                    begin
    					GsdkJ[y, x]:=8;
    				end;
     
    				if (Event.key.keysym.sym  =  SDLK_KP1) and (mask [y, x] = True) then 
                    begin
    					GsdkJ[y, x]:=9;
    				end;
     
                    end;  
                 end; 
            DrawScene(AWindow, TImage, AGrille);
    		DrawChiffre(AWindow, GsdkJ, TImage);
    		//DrawChiffreE (AWindow, GsdkJ, x, y, TImage);  
            DrawCursor(AWindow, x, y, TImage); 
            {On raffraichit notre ecran} 
            SDL_Flip(AWindow); 
            {On attends 30ms seconde} 
            SDL_Delay(30);
        end; 
    end; 
     
    procedure FreeImages(var TImage : Photo);
     
    var i : Integer;
     
    begin
        for i := 1 to 15 do
        begin
            Dispose(TImage[i]);
        end;
    end;
     
     
    {---------------------------------------------------------------------}
    var Grille : TGrille;
        Image : Photo;
        Window : PSDL_Surface;
        Gsdk,GsdkJ : GrilleSudoku;   
    	mask : GsdkM;
     
    begin
    	randomize;
    	generateur(Gsdk);  
    	masque(Gsdk, GsdkJ, mask);
        LoadGrille('grilleSdk.txt', Grille);
        LoadImage(Image);
        Window := NewWindow(549,671, 'SUDOKU');
        {DrawScene(Window, Image, Grille);
    	DrawChiffre(Window, GsdkJ, Image);
    	DrawCursor(Window, Image); 
        SDL_Flip(Window);
        SDL_Delay(30);}
    	BoucleJeu(Window, GsdkJ, Gsdk, mask, Image, Grille);
        FreeImages(Image);
        SDL_Quit;
     
    end.

  8. #8
    Rédacteur/Modérateur

    Avatar de Roland Chastain
    Homme Profil pro
    Enseignant
    Inscrit en
    Décembre 2011
    Messages
    4 085
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 51
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Décembre 2011
    Messages : 4 085
    Points : 15 507
    Points
    15 507
    Billets dans le blog
    9
    Par défaut
    Bonjour ! Tu n'as pas tenu compte de ce que je t'ai dit précédemment au sujet de la déclaration inutile des unités. Peu importe, mais ce n'est pas très encourageant.

    Au fait, pourquoi redéclarer les constantes de l'unité SDL ?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    Const 	SDL_KEYDOWN    =   2; 
    		SDL_QUITEV     =  12; 
     
    		SDLK_UP        = 273; 
    		SDLK_DOWN      = 274; 
    		SDLK_RIGHT     = 275; 
    		SDLK_LEFT      = 276;
    D'autre part, en voyant le code de ta fonction CValide(), il me semble comprendre pourquoi ton curseur a tendance à sortir du cadre mais je suppose que c'est fait exprès ?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    function CValide(x, y : Integer) : Boolean;
     
    begin
        //if (x > -1) and (x < 10) and (y > -1) and (y < 10) then 
    		Exit(True)
    	//else	
           // Exit(False);    
    end;
    Ici tu t'es trompé, ça saute aux yeux :

    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
    				if Event.key.keysym.sym  =  SDLK_DOWN then 
                    begin 
                        if CValide(x, y-1) then 
                        begin 
                            y:=y+1; 
                        end; 
                    end; 
     
    				if Event.key.keysym.sym  =  SDLK_UP then 
                    begin 
                        if CValide(x, y+1) then 
                        begin 
                            y:=y-1; 
                        end; 
                    end;
    Citation Envoyé par tazbrraaa Voir le message
    J'ai modifié quelques éléments qui me permettent de bien me retrouver avec les coordonnées je pense mais j'ai toujours un problème pour afficher les numéros voulus par le joueur..
    Il ne faut pas trop "penser", c'est dangereux !

    Mais pourrais-tu être plus précis au sujet du "problème" en question ? Je retire ce que j'ai dit : ton précédent message décrivait bien le problème. Je vais voir si j'arrive à expérimenter la chose.

  9. #9
    Nouveau Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Novembre 2014
    Messages
    7
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 28
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Novembre 2014
    Messages : 7
    Points : 1
    Points
    1
    Par défaut
    Effectivement j'ai pas fait attention avec les unités. En fait, j'ai créé une autre version à partir de l'ancienne et j'ai oublié de rectifier ça mais c'est fait maintenant.

    Après le problème c'est que je n'ai jamais eu de cours de SDL du coup j'essaye de comprendre à partir de programmes diverses et j'avais vu un programme où il y avait déclarer les constante correspondant aux touches mais effectivement ça marche très bien sans.

    Par contre même en corrigeant l'erreur avec les y+1 ou y-1 dans l'appelle de la procedure CValide j'ai toujours un problème dans la circulation de mon curseur..

    En tout cas merci de l'aide

    PS: Pour être plus explicite j'ai plusieurs problèmes dont celui de bloquer le curseur mais là le gros problème c'est que je n'arrive pas à afficher les chiffres entrés par l'utilisateur..

  10. #10
    Rédacteur/Modérateur

    Avatar de Roland Chastain
    Homme Profil pro
    Enseignant
    Inscrit en
    Décembre 2011
    Messages
    4 085
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 51
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Décembre 2011
    Messages : 4 085
    Points : 15 507
    Points
    15 507
    Billets dans le blog
    9
    Par défaut
    Pour le curseur, je vais regarder : l'erreur ne devrait pas être bien difficile à trouver.

    Pour les chiffres entrés par l'utilisateur, comment est-il supposé les entrer ? Que signifie la constante SDLK_KP1 ? S'il s'agit du pavé numérique, il me sera difficile de t'aider vu que je n'en ai pas sur mon clavier. Mais je remarque que tu testes 9 fois la même condition. Il y a un problème, non ?

    Si tu as modifié ton code, pourrais-tu poster la dernière version (en éditant ton message), de façon à ce que nous parlions de la même chose ?

  11. #11
    Nouveau Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Novembre 2014
    Messages
    7
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 28
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Novembre 2014
    Messages : 7
    Points : 1
    Points
    1
    Par défaut
    Normalement tout fonctionne j'ai remarqué plusieurs erreurs d'étourderie comme le fait que je tester 9 fois la même condition (j'avais fait un copié collé mais visiblement j'ai oublié de modifier certains éléments ). En tout cas cette version me semble pas mal, toutes les fonctionnalités fonctionnent même CValide. Et l'erreur était en effet assez bête

    Merci de ton aide, je pense là avoir un programme assez réussi même si je suis convaincu qu'il y a plus simple !

    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
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    536
    537
    538
    539
    540
    541
    542
    543
    544
    545
    546
    program Essai1SDL;
     
    uses sdl, sdl_image;
     
    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;
    	 Photo = array [1..23] of PSDL_Surface;
     
    {---------------------------------------------------------------------}
     
    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:=30;
             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;  
    	for i:=1 to 9 do
        begin
    		for j:=1 to 9 do 
    		write(GsdkJ[i,j]);
    		writeln();
    	end;
    	writeln();
    	for i:=1 to 9 do
        begin
    		for j:=1 to 9 do 
    		write(Gsdk[i,j]);
    		writeln();
        end;
    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 : Photo);
    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');
     
    	TImage[15] := IMG_Load('chiffreE1.png');
    	TImage[16] := IMG_Load('chiffreE2.png');
    	TImage[17] := IMG_Load('chiffreE3.png');
    	TImage[18] := IMG_Load('chiffreE4.png');
    	TImage[19] := IMG_Load('chiffreE5.png');
    	TImage[20] := IMG_Load('chiffreE6.png');
    	TImage[21] := IMG_Load('chiffreE7.png');
    	TImage[22] := IMG_Load('chiffreE8.png');
    	TImage[23] := IMG_Load('chiffreE9.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 : Photo ; 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 (AGrille[y][x]) = 'a' then
                    SDL_BlitSurface(TImage[1], nil, AWindow, @Position);
    			if (AGrille[y][x]) = 'b' then
                    SDL_BlitSurface(TImage[2], nil, AWindow, @Position);
    			if (AGrille[y][x]) = 'c' then
                    SDL_BlitSurface(TImage[3], nil, AWindow, @Position);                
                if (AGrille[y][x]) = 'd' then
                    SDL_BlitSurface(TImage[4] , nil, AWindow, @Position);
            end;
        end;
    end;
     
    procedure DrawChiffre (AWindow : PSDL_Surface; GsdkJ : GrilleSudoku; var TImage : Photo);
    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 (GsdkJ[y][x]) = 1 then
    					SDL_BlitSurface(TImage[6], nil, AWindow, @Position);
    				if (GsdkJ[y][x]) = 2 then
    					SDL_BlitSurface(TImage[7], nil, AWindow, @Position);
    				if (GsdkJ[y][x]) = 3 then
    					SDL_BlitSurface(TImage[8], nil, AWindow, @Position);                
    				if (GsdkJ[y][x]) = 4 then
    					SDL_BlitSurface(TImage[9] , nil, AWindow, @Position);
    				if (GsdkJ[y][x]) = 5 then
    					SDL_BlitSurface(TImage[10] , nil, AWindow, @Position);
    				if (GsdkJ[y][x]) = 6 then
    					SDL_BlitSurface(TImage[11] , nil, AWindow, @Position);
    				if (GsdkJ[y][x]) = 7 then
    					SDL_BlitSurface(TImage[12] , nil, AWindow, @Position);
    				if (GsdkJ[y][x]) = 8 then
    					SDL_BlitSurface(TImage[13] , nil, AWindow, @Position);
    				if (GsdkJ[y][x]) = 9 then
    					SDL_BlitSurface(TImage[14] , nil, AWindow, @Position);
     
    		end;
    	end;
    end;
     
    procedure DrawChiffreE (AWindow : PSDL_Surface; var GrilleJ : GrilleSudoku; var TImage : Photo);
    var	Position : TSDL_Rect;
    	x, y : Integer;
     
    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 (GrilleJ[y][x]) = 1 then
    		SDL_BlitSurface(TImage[15], nil, AWindow, @Position);
    	if (GrilleJ[y][x]) = 2 then
    		SDL_BlitSurface(TImage[16], nil, AWindow, @Position);
    	if (GrilleJ[y][x]) = 3 then
    		SDL_BlitSurface(TImage[17], nil, AWindow, @Position);                
    	if (GrilleJ[y][x]) = 4 then
    		SDL_BlitSurface(TImage[18] , nil, AWindow, @Position);
    	if (GrilleJ[y][x]) = 5 then
    		SDL_BlitSurface(TImage[19] , nil, AWindow, @Position);
    	if (GrilleJ[y][x]) = 6 then
    		SDL_BlitSurface(TImage[20] , nil, AWindow, @Position);
    	if (GrilleJ[y][x]) = 7 then
    		SDL_BlitSurface(TImage[21] , nil, AWindow, @Position);
    	if (GrilleJ[y][x]) = 8 then
    		SDL_BlitSurface(TImage[22] , nil, AWindow, @Position);
    	if (GrilleJ[y][x]) = 9 then
    		SDL_BlitSurface(TImage[23] , nil, AWindow, @Position);
    	end;
    end;
    end;
     
    procedure DrawCursor(AWindow : PSDL_Surface; var x, y : Integer; var TImage : Photo);
     
    var Position : TSDL_Rect;
     
    begin
    	Position.x := (x-1) * 61;
        Position.y := (y-1) * 61;
        SDL_BlitSurface(TImage[5], nil, AWindow, @Position);
    end;
    {---------------------------------------------------------------------}
     
    function CValide(x, y : Integer) : Boolean;
     
    begin
        if (x = 0) or (x = 10) or (y = 0) or (y = 10) then 
    		Exit(False)
    	else	
            Exit(True);    
    end;
     
    procedure BoucleJeu(AWindow : PSDL_Surface; mask : GsdkM; Gsdk : GrilleSudoku; var nbAide : Integer; var GsdkJ, GrilleJ : GrilleSudoku; var TImage : Photo; var AGrille : TGrille); 
    var 
        Event : TSDL_Event; 
        {Variable qui quand est a true, ordonne de quitter} 
        Fin : Boolean; 
    	x, y : Integer;
     
    begin 
        Fin := False;
    	x := 1; 
        y := 1;
        nbAide := 0;
        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 
     
    				if Event.key.keysym.sym  =  SDLK_DOWN then 
                    begin 
                        if CValide(x, y+1) then 
                        begin 
                            y:=y+1; 
                        end; 
                    end; 
     
    				if Event.key.keysym.sym  =  SDLK_UP then 
                    begin 
                        if CValide(x, y-1) then 
                        begin 
                            y:=y-1; 
                        end; 
                    end;
     
    				if Event.key.keysym.sym  =  SDLK_RIGHT then 
                    begin 
                        if CValide(x+1, y) then 
                        begin 
                            x:=x+1; 
                        end; 
                    end;
     
    				if Event.key.keysym.sym  =  SDLK_LEFT then 
                    begin 
                        if CValide(x-1, y) then 
                        begin 
                            x:=x-1; 
                        end; 
                    end;
     
    				if Event.key.keysym.sym  =  SDLK_RETURN then 
                    begin 
                        Fin:=True;
    				end;
     
    				if Event.key.keysym.sym  =  SDLK_SPACE then 
                    begin 
                        if (nbAide < 3) then
    					begin
    						if mask [y, x] = True then
    						begin
    							GsdkJ[y, x] := Gsdk[y, x];
    							nbAide := nbAide+1;
    							mask[y, x] := False;
    						end;
    					end;
    				end;
     
    				if (Event.key.keysym.sym  =  SDLK_KP1) and (mask [y, x] = True) then 
                    begin
    					GrilleJ[y, x]:=1;
    				end;
     
    				if (Event.key.keysym.sym  =  SDLK_KP2) and (mask [y, x] = True) then 
                    begin
    					GrilleJ[y, x]:=2;
    				end;
     
    				if (Event.key.keysym.sym  =  SDLK_KP3) and (mask [y, x] = True) then 
                    begin
    					GrilleJ[y, x]:=3;
    				end;
     
    				if (Event.key.keysym.sym  =  SDLK_KP4) and (mask [y, x] = True) then 
                    begin
    					GrilleJ[y, x]:=4;
    				end;
     
    				if (Event.key.keysym.sym  =  SDLK_KP5) and (mask [y, x] = True) then 
                    begin
    					GrilleJ[y, x]:=5;
    				end;
     
    				if (Event.key.keysym.sym  =  SDLK_KP6) and (mask [y, x] = True) then 
                    begin
    					GrilleJ[y, x]:=6;
    				end;
     
    				if (Event.key.keysym.sym  =  SDLK_KP7) and (mask [y, x] = True) then 
                    begin
    					GrilleJ[y, x]:=7;
    				end;
     
    				if (Event.key.keysym.sym  =  SDLK_KP8) and (mask [y, x] = True) then 
                    begin
    					GrilleJ[y, x]:=8;
    				end;
     
    				if (Event.key.keysym.sym  =  SDLK_KP9) and (mask [y, x] = True) then 
                    begin
    					GrilleJ[y, x]:=9;
    				end;
     
                    end;  
                 end; 
            DrawScene(AWindow, TImage, AGrille);
    		DrawChiffreE (AWindow, GrilleJ, TImage);  
    		DrawChiffre(AWindow, GsdkJ, TImage);
            DrawCursor(AWindow, x, y, TImage); 
            {On raffraichit notre ecran} 
            SDL_Flip(AWindow); 
            {On attends 30ms seconde} 
            SDL_Delay(30);
        end;
        end;
     
    procedure GrilleFinale (GrilleJ : GrilleSudoku; var GsdkJ : GrilleSudoku);
    var i, j : Integer;
    begin
    for i:=1 to 9 do
        begin
    		for j:=1 to 9 do 
    		begin
    			if (GrilleJ[i,j]<>0) then
    				GsdkJ[i,j]:=GrilleJ[i,j]
    		end;
    	end;
    end;
     
    procedure Test (Gsdk : GrilleSudoku; var GsdkJ : GrilleSudoku);
    var i, j : Integer;
    	win : boolean;
    begin
    	for i:=1 to 9 do
        begin
    		for j:=1 to 9 do 
    		write(GsdkJ[i,j]);
    		writeln();
     
    			if GsdkJ[i,j]=Gsdk[i,j] then
    				win:=True
    			else
    				win:=False;
    	end;
    	if win=True then
    		write ('gagné')
    	else
    		write ('perdu');
    end;	    
     
    procedure FreeImages(var TImage : Photo);
     
    var i : Integer;
     
    begin
        for i := 1 to 24 do
        begin
            Dispose(TImage[i]);
        end;
    end;
     
     
    {---------------------------------------------------------------------}
    var Grille : TGrille;
        Image : Photo;
        Window : PSDL_Surface;
        Gsdk,GsdkJ,GrilleJ : GrilleSudoku;   
    	mask : GsdkM;
    	nbAide : Integer;
     
    begin
    	randomize;
    	generateur(Gsdk);  
    	masque(Gsdk, GsdkJ, mask);
        LoadGrille('grilleSdk.txt', Grille);
        LoadImage(Image);
        Window := NewWindow(549,549, 'SUDOKU');
    	BoucleJeu(Window, mask, Gsdk, nbAide, GsdkJ, GrilleJ, Image, Grille);
        FreeImages(Image);
        SDL_Quit;
        GrilleFinale (GrilleJ, GsdkJ);
        Test (Gsdk, GsdkJ);
    end.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [Turbo Pascal] Réaliser un jeu de lumière avec un caractère
    Par machmak dans le forum Turbo Pascal
    Réponses: 1
    Dernier message: 18/12/2012, 01h12
  2. réalisation d'un jeu avec vb.net
    Par urculate dans le forum VB.NET
    Réponses: 4
    Dernier message: 24/02/2008, 20h22
  3. Réalisation d'un jeu 3D avec Director
    Par sab_etudianteBTS dans le forum Développement 2D, 3D et Jeux
    Réponses: 4
    Dernier message: 15/02/2008, 09h32
  4. Jeu de mot avec connexion à une bdd a réaliser
    Par Orkyd dans le forum Projets
    Réponses: 3
    Dernier message: 23/12/2006, 18h59
  5. [3D][Jeu]Réalisation d'un jeu avec java3D
    Par Janitrix dans le forum 3D
    Réponses: 2
    Dernier message: 22/04/2006, 23h22

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo