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 :

Problème comparaison et actualisation - Jeu du Memory


Sujet :

Free Pascal

  1. #1
    Membre à l'essai
    Profil pro
    Inscrit en
    Février 2014
    Messages
    14
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2014
    Messages : 14
    Points : 15
    Points
    15
    Par défaut Problème comparaison et actualisation - Jeu du Memory
    Bonjour,

    Voilà j'ai un gros problème avec mon programme.

    En effet, la comparaison des cartes et l'actualisation de la grille ne fonctionnent pas et je ne vois où se trouve le problème.

    C'est sûrement tout c** mais cela fait des heures que je cherche sans trouver.

    Voici mon code :

    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
    program Memory;
     
    uses
      sdl, sdl_image;
     
    type
      TGrille = array[1..9, 1..13] 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('Image2/Fond.png');
      TImage[2] := IMG_Load('Image2/Carte-2.png');
      TImage[3] := IMG_Load('Image2/Curseur.png');
      TImage[4] := IMG_Load('Image2/Image2-1.png');
      TImage[5] := IMG_Load('Image2/Image2-2.png');
      TImage[6] := IMG_Load('Image2/Image2-3.png');
      TImage[7] := IMG_Load('Image2/Image2-4.png');
      TImage[8] := IMG_Load('Image2/Image2-5.png');
      TImage[9] := IMG_Load('Image2/Image2-6.png');
      TImage[10] := IMG_Load('Image2/Image2-7.png');
      TImage[11] := IMG_Load('Image2/Image2-8.png');
      TImage[12] := IMG_Load('Image2/Image2-9.png');
      TImage[13] := IMG_Load('Image2/Image2-10.png');
      TImage[14] := IMG_Load('Image2/Image2-11.png');
      TImage[15] := IMG_Load('Image2/Image2-12.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 13 do
        begin
          Position.x := (x - 1) * 60;
          Position.y := (y - 1) * 60;
          if string(AGrille[y][x]) = 'Z' then
            SDL_BlitSurface(TImage[1], nil, AWindow, @Position);
          if string(AGrille[y][x]) = 'X' then
            SDL_BlitSurface(TImage[2], nil, AWindow, @Position);
          if string(AGrille[y][x]) = 'A' then
            SDL_BlitSurface(TImage[4], nil, AWindow, @Position);
          if string(AGrille[y][x]) = 'B' then
            SDL_BlitSurface(TImage[5], nil, AWindow, @Position);
          if string(AGrille[y][x]) = 'C' then
            SDL_BlitSurface(TImage[6], nil, AWindow, @Position);
          if string(AGrille[y][x]) = 'D' then
            SDL_BlitSurface(TImage[7], nil, AWindow, @Position);
          if string(AGrille[y][x]) = 'E' then
            SDL_BlitSurface(TImage[8], nil, AWindow, @Position);
          if string(AGrille[y][x]) = 'F' then
            SDL_BlitSurface(TImage[9], nil, AWindow, @Position);
          if string(AGrille[y][x]) = 'G' then
            SDL_BlitSurface(TImage[10], nil, AWindow, @Position);
          if string(AGrille[y][x]) = 'H' then
            SDL_BlitSurface(TImage[11], nil, AWindow, @Position);
          if string(AGrille[y][x]) = 'I' then
            SDL_BlitSurface(TImage[12], nil, AWindow, @Position);
          if string(AGrille[y][x]) = 'J' then
            SDL_BlitSurface(TImage[13], nil, AWindow, @Position);
          if string(AGrille[y][x]) = 'K' then
            SDL_BlitSurface(TImage[14], nil, AWindow, @Position);
          if string(AGrille[y][x]) = 'L' then
            SDL_BlitSurface(TImage[15], nil, AWindow, @Position);        
          end;
      end;
    end;
     
    procedure DrawSurface(AWindow: PSDL_Surface; x, y: Integer; ASurface: PSDL_Surface);
    var
      Position: TSDL_Rect;
    begin
      Position.x := (x - 1) * 60;
      Position.y := (y - 1) * 60;
      SDL_BlitSurface(ASurface, nil, AWindow, @Position);
    end;
     
    function CValide(AGrille: TGrille; x, y: Integer): Boolean;
    begin
      if (x = 0) or (x = 14) or (y = 0) or (y = 10) then
        Exit(False)
      else
        Exit(True);
    end;
     
    function ComparerCartes(RGrille :  TGrille ; C1_x,C1_y,C2_x,C2_y : Integer):Boolean;
    begin
    If RGrille[C1_y][C1_x] <> RGrille[C2_y][C2_x] then
    		Exit(True)
    	else
    		Exit(False);	
    end;
     
    procedure ActualiserGrille(C1_x, C2_x, C1_y, C2_y:Integer; RGrille: TGrille ; var AGRille : TGrille; var i: Integer);
     
    begin
     
    if (ComparerCartes(RGrille, C1_x, C2_x, C1_y, C2_y) = True) then
    		begin
    		i:=0;
    		C1_x:=0;
    		C2_x:=0;
    		C1_y:=0;
    		C2_y:=0;
    		end
    else 
    	begin
    	AGrille[C1_y][C1_x] := 'X';
    	AGrille[C2_y][C2_x] := 'X';
    	i:=0;
    	C1_x:=0;
    	C2_x:=0;
    	C1_y:=0;
    	C2_y:=0;
    	end;
    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, C_y, S_y,i, C1_x, C2_x, C1_y, C2_y: Integer;
      RGrille : TGrille;
    begin
      Fin := False;
      C_x := 2;
      C_y := 2;
      S_x := 0;
      S_y := 0;
      C1_x := 0;
      C1_y := 0;
      C2_x := 0;
      C2_y := 0; 
      i:= 0;
      LoadGrille('Fichier2/FichierGrille2.txt', RGrille);
      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) and (i<>2) then
          begin
            case Event.key.keysym.sym of
              SDLK_DOWN:
                begin
                  if (CValide(AGrille, C_x, C_y + 2) = True) then
                  begin
                    C_y += 2;
                  end;
                end;
              SDLK_UP:
                begin
                  if (CVAlide(AGrille, C_x, C_y - 2) = True) 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) = True) then
                  begin
                    C_x += 2;
                  end;
                end;
              SDLK_RETURN:
                begin
                  S_x := C_x;
                  S_y := C_y;
                  i:=i+1;
                end;
            end; 
             if (C1_x = 0) then
    			begin
    			C1_x:=S_x;
    			C1_y:= S_y;
    			end
    		else 
    			begin
    			C2_x:=S_x;
    			C2_y:= S_y;
    			end;
          end;
          if S_x <> 0 then
          AGrille[S_y, S_x] := RGrille[S_y, S_x]; 
          DrawScene(AWindow, TImage, AGrille);
          DrawSurface(AWindow, C_x, C_y, TImage[3]);
    	  ActualiserGrille(C1_x, C2_x, C1_y, C2_y, RGrille, AGrille,i);
          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 15 do
      begin
        Dispose(Image[i]);
      end;
    end;
     
    var
      Grille: TGrille;
      Image: array[1..16] of PSDL_Surface;
      Window: PSDL_Surface;
     
    begin
      LoadGrille('Fichier2/GrilleLevel2.txt', Grille);
      LoadImage(Image);
      Window := NewWindow(13* 60, 9 * 60, 'Memory - Niveau : Intermédiaire');
      PBoucle(Window, Image, Grille);
      FreeImages(Image);
      SDL_Quit;
    end.
    Voici les images et fichiers du programme:

    Image & Fichier.zip

    Merci d'avance

  2. #2
    Rédacteur/Modérateur

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

    Informations professionnelles :
    Activité : Enseignant

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

    Tu as vraiment de quoi faire quelque chose de bien mais, à mon avis, ton code dans son état actuel est trop compliqué. Pas étonnant que tu ne t'y retrouves pas. Si c'était moi, plutôt que d'essayer de le faire fonctionner tel qu'il est, je le réécrirais entièrement, sur des bases plus simples et plus solides. Ce n'est sans doute pas la réponse que tu attendais, mais je crois sincèrement que c'est le meilleur conseil à te donner.

    Voici donc quelques suggestions. D'abord, ton tableau d'images est mal dimensionné. Il y a quinze images : donc ce devrait être un array[1..15]. Mais attention ! Il faut savoir que lorsque tu passes un tableau en paramètre à une fonction, tu y accèdes toujours (depuis le corps de la fonction) à partir de l'index 0, comme si tu l'avais déclaré array[0..14]. Tu peux t'en rendre compte en ajoutant dans ton programme les lignes suivantes :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    procedure LoadImage(var TImage: array of PSDL_Surface);
    begin
      WriteLn(Low(TImage)); // 0
      WriteLn(High(TImage)); // 14 (15 avec ta déclaration actuelle)
    Le plus simple est peut-être de déclarer directement un array[0..14] : au moins tu n'auras plus à te soucier de ce problème.

    D'autre part, tu devrais revoir ton type TGrille. Ce n'est pas très logique d'inclure dans la grille le fond. Il suffit de le dessiner une fois pour toutes au lancement du programme. Donc tu pourrais déclarer le type ainsi :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    TGrille = array[1..4, 1..6]
    Soit dit en passant, moi j'aurais plutôt fait l'inverse (array[1..6, 1..4]) mais bon ça n'a pas trop d'importance.

    D'autre part, je ne mettrais dans ma grille que les valeurs des cartes et je mettrais dans un autre tableau l'état des cartes, c'est-à-dire si elles sont à l'envers ou à l'endroit. Quelque chose comme ça :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    var
      visible: array[1..4, 1..6] of boolean;
    Voilà. A mon avis, le meilleur moyen pour toi de faire un beau programme, c'est de reprendre tranquillement les choses depuis le début, sans être trop pressé de finir. Tu pourrais aussi inclure dans ton programme des fonctions de débogage, qui enverraient vers la console ou vers un fichier les valeurs successives de ta grille : de cette façon tu trouverais plus facilement les erreurs.

    P.-S. Une autre possibilité serait la suivante :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    type
      TCarte = record
        figure: Char;
        visible: Boolean;
      end;
     
      TGrille = array[1..4, 1..6] of TCarte;
    Mon site personnel consacré à MSEide+MSEgui : msegui.net

  3. #3
    Membre à l'essai
    Profil pro
    Inscrit en
    Février 2014
    Messages
    14
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2014
    Messages : 14
    Points : 15
    Points
    15
    Par défaut
    C'est sûr que je m'attendais pas à cette réponse mais je comprends tout à fait tes remarques et je te remercie de les avoir faîtes car c'est la seule façon de progresser.

    Néanmoins pour ma défense c'est le première fois que je réalise une SDL et la documentation sur internet n'est pas facile à trouver surtout en Pascal.

    Mais je vais prendre tes conseils en compte pour améliorer mon programme.

    Merci

  4. #4
    Rédacteur/Modérateur

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

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Décembre 2011
    Messages : 4 072
    Points : 15 462
    Points
    15 462
    Billets dans le blog
    9
    Par défaut
    Citation Envoyé par Taazer Voir le message
    C'est sûr que je m'attendais pas à cette réponse mais je comprends tout à fait tes remarques et je te remercie de les avoir faites car c'est la seule façon de progresser.
    Excellent état d'esprit !

    Citation Envoyé par Taazer Voir le message
    Néanmoins pour ma défense c'est le première fois que je réalise une SDL et la documentation sur internet n'est pas facile à trouver surtout en Pascal.
    Si tu as du temps et que tu as envie de regarder d'autres programmes faits avec Free Pascal et la SDL, en voici deux :



    Citation Envoyé par Taazer Voir le message
    Mais je vais prendre tes conseils en compte pour améliorer mon programme.
    N'hésite pas à faire part de tes questions ou des difficultés que tu rencontres : il y aura toujours quelqu'un pour t'aider, moi ou quelqu'un d'autre.

    Sur ce, bon courage ! Personnellement j'ai hâte de voir la suite.
    Mon site personnel consacré à MSEide+MSEgui : msegui.net

  5. #5
    Membre à l'essai
    Profil pro
    Inscrit en
    Février 2014
    Messages
    14
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2014
    Messages : 14
    Points : 15
    Points
    15
    Par défaut
    J'ai essayé de simplifier mon programme voilà ce que ça donne, dîtes moi ce que vous en pensez

    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
    program MemorySDL;
     
    uses 
    	sdl, sdl_image;
     
    const  
    	NbColonne = 6;		NbLigne = 4;		NbImage = 14;
    	TailleC = 60;		Xmin = 0;			Xmax = 14;			
    	Ymin = 0;			Ymax = 10;			LargeurF = 540;		
    	LongueurF = 780; 
     
     
    Type
    	TGrille = array [1.. NbColonne, 1.. NbLigne] of Char;
    	TImage = array [0..NbImage] of PSDL_Surface;
    	CVisible = array [1..NbColonne, 1..NbLigne] of Boolean;
     
    {----------------------------------------------------------------------}
     
    function CreerFenetre(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 ChargerImage(var Image: TImage);
     
    begin
     
      Image[0] := IMG_Load('Image2/Fond.png');
      Image[1] := IMG_Load('Image2/Carte-2.png');
      Image[2] := IMG_Load('Image2/Curseur.png');
      Image[3] := IMG_Load('Image2/Image2-1.png');
      Image[4] := IMG_Load('Image2/Image2-2.png');
      Image[5] := IMG_Load('Image2/Image2-3.png');
      Image[6] := IMG_Load('Image2/Image2-4.png');
      Image[7] := IMG_Load('Image2/Image2-5.png');
      Image[8] := IMG_Load('Image2/Image2-6.png');
      Image[9] := IMG_Load('Image2/Image2-7.png');
      Image[10] := IMG_Load('Image2/Image2-8.png');
      Image[11] := IMG_Load('Image2/Image2-9.png');
      Image[12] := IMG_Load('Image2/Image2-10.png');
      Image[13] := IMG_Load('Image2/Image2-11.png');
      Image[14] := IMG_Load('Image2/Image2-12.png');
     
    end;
     
    {----------------------------------------------------------------------}
     
    procedure ChargerGrille(FGrille: string; var Grille: 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
          Grille[y][x] := Iterator;
          x := x + 1;
        end;
        y := y + 1;
      end;
      Close(LevelGrille);
     
    end;	
     
    {----------------------------------------------------------------------}
     
    procedure DessinerScene(Window: PSDL_Surface; var Image: TImage ; Grille: TGrille);
     
    var
      x, y: Integer;
      Position: TSDL_Rect;
     
    begin
     
      for y := 1 to Nbligne do
      begin
        for x := 1 to NbColonne do
        begin
          Position.x := (x - 1) * TailleC;
          Position.y := (y - 1) * TailleC;
    	  case string(Grille[y][x]) of  
    	  'X' : SDL_BlitSurface(Image[1], nil, Window, @Position);
    	  'A' : SDL_BlitSurface(Image[3], nil, Window, @Position);
    	  'B' : SDL_BlitSurface(Image[4], nil, Window, @Position);
    	  'C' : SDL_BlitSurface(Image[5], nil, Window, @Position);
    	  'D' : SDL_BlitSurface(Image[6], nil, Window, @Position);
    	  'E' : SDL_BlitSurface(Image[7], nil, Window, @Position);
    	  'F' : SDL_BlitSurface(Image[8], nil, Window, @Position);
    	  'G' : SDL_BlitSurface(Image[9], nil, Window, @Position);
    	  'H' : SDL_BlitSurface(Image[10], nil, Window, @Position);
    	  'I' : SDL_BlitSurface(Image[11], nil, Window, @Position);
    	  'J' : SDL_BlitSurface(Image[12], nil, Window, @Position);
    	  'K' : SDL_BlitSurface(Image[13], nil, Window, @Position);
    	  'L' : SDL_BlitSurface(Image[14], nil, Window, @Position);             
          end;
        end;
      end;
    end;
     
    {----------------------------------------------------------------------}
     
    procedure Visibilite(match : Boolean; x, y: Integer; var Visible: CVisible; Grille: TGrille);
     
    begin
     
    if (match=True) then
    	Visible[y][x]:=True;
    if (match=False) then
    begin
    	Visible[y][x]:=False;
    	Grille[y][x] := 'X';
    end;
     
    end;
     
    {----------------------------------------------------------------------}
     
    procedure DessinerCurseur(Window: PSDL_Surface; x, y: Integer; Curseur: PSDL_Surface);
     
    var
      Position: TSDL_Rect;
     
    begin
     
      Position.x := (x - 1) * TailleC;
      Position.y := (y - 1) * TailleC;
      SDL_BlitSurface(Curseur, nil, Window, @Position);
     
    end;
     
    {----------------------------------------------------------------------}
     
    function CValide(Grille: TGrille; x, y: Integer): Boolean;
     
    begin
     
      if (x = Xmin) or (x = Xmax) or (y = Ymin) or (y = Ymax) then
        Exit(False)
      else
        Exit(True);
     
    end;
     
    {----------------------------------------------------------------------}
     
    procedure SelectionnerCarte(var x, y: Integer);
     
    begin
     
    x:=x;
    y:=y;
     
    end;
     
    {----------------------------------------------------------------------}
     
    procedure ComparerCarte(x1,y1,x2,y2 : Integer; Grille: TGrille ; var match : Boolean);
     
    begin
     
    if (Grille[y1][x1]) = (Grille[y2][x2])  then
    	match:=True 
    else
    	match:=False
     
    end;
     
    {----------------------------------------------------------------------}
     
    procedure ActualiserGrille(var x1,y1,x2,y2 : Integer; match : Boolean; Grille: TGrille; var Visible : CVisible);
     
    begin
     
    if (match=False) then
    	begin
    		Visibilite(match,x1,y1, Visible, Grille);
    		Visibilite(match,x2,y2, Visible, Grille);
    	end;
    if (match=True) then
    	begin
    		Visibilite(match,x1,y1, Visible, Grille);
    		Visibilite(match,x2,y2, Visible, Grille);
    	end;
    end;
     
    {----------------------------------------------------------------------}
     
    procedure Deplacer(Window: PSDL_Surface; var Image: TImage;  Grille: TGrille; S_x, S_y: Integer);
     
    var
      Event: TSDL_Event;
      Fin: Boolean;
      C_x, C_y: Integer;
     
    begin
     
      Fin := False;
      C_x := 2;
      C_y := 2;
      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(Grille, C_x, C_y + 2) = True) then
                    C_y := C_y + 2;
                end;
              SDLK_UP:
                begin
                  if (CVAlide(Grille, C_x, C_y - 2) = True) then
                    C_y := C_y - 2;
                end;
              SDLK_LEFT:
                begin
                  if (CValide(Grille, C_x - 2, C_y) = True) then
                    C_x := C_x - 2;
                end;
              SDLK_RIGHT:
                begin
                  if (CValide(Grille, C_x + 2, C_y) = True) then
                    C_x := C_x + 2;      
                end;
              SDLK_RETURN:
                begin
                  S_x := C_x;
                  S_y := C_y;
                end;
             end; 
          end;
      end;
    end;
    end;
     
    {----------------------------------------------------------------------}
     
    procedure Tour(Window: PSDL_Surface; Image: TImage; x, y, x1, x2, y1, y2: Integer; Grille: TGrille; match: Boolean; Visible: CVisible);
     
    var
    	i:Integer;
     
    begin
     
    match:=True;
    i:=1;
    repeat
    begin
    	Deplacer(Window, Image, Grille, x, y);
    	SelectionnerCarte(x, y);
    	Visibilite(match, x, y, Visible, Grille);
    	i:=i+1;
    end;	
    until i=2;
    ComparerCarte(x1, y1, x2, y2, Grille, match);
    ActualiserGrille(x1, y1, x2, y2, match, Grille, Visible);
    end;
     
    {----------------------------------------------------------------------}
     
    procedure LibererImages(var Image: TImage);
     
    var
      i: Integer;
     
    begin
     
      for i := 0 to (NbImage + 1) do
      begin
        Dispose(Image[i]);
      end;
     
    end;
     
    {----------------------------------------------------------------------}
     
    procedure Jeu(Window: PSDL_Surface; Image: TImage; x, y, x1, x2, y1, y2, C_x, C_y: Integer; Grille: TGrille; match: Boolean; Visible: CVisible);
     
    var
    	boucle: Boolean;
     
    begin
     
    boucle := False;
    repeat
    begin
      ChargerImage(Image);
      Window := CreerFenetre(LongueurF, LargeurF, 'Memory - Niveau : Intermédiaire');
      SDL_BlitSurface(Image[0],nil,Window, nil);
      ChargerGrille('Fichier2/GrilleLevel2.txt', Grille);
      Tour(Window, Image, x, y, x1, y1, x2, y2, Grille, match, Visible);
      DessinerScene(Window, Image, Grille);
      DessinerCurseur(Window, C_x, C_y, Image[2]);
      SDL_Flip(Window);
      SDL_Delay(30);
    end;  
    until boucle=True;
    LibererImages(Image);
    SDL_Quit;
     
    end;
    Merci d'avance

  6. #6
    Rédacteur/Modérateur

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

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Décembre 2011
    Messages : 4 072
    Points : 15 462
    Points
    15 462
    Billets dans le blog
    9
    Par défaut
    Effectivement, on dirait que tu as pas mal travaillé mais le code que tu as posté est incomplet : il manque la fin, la boucle principale !
    Mon site personnel consacré à MSEide+MSEgui : msegui.net

  7. #7
    Membre à l'essai
    Profil pro
    Inscrit en
    Février 2014
    Messages
    14
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2014
    Messages : 14
    Points : 15
    Points
    15
    Par défaut
    Citation Envoyé par Roland Chastain Voir le message
    Effectivement, on dirait que tu as pas mal travaillé mais le code que tu as posté est incomplet : il manque la fin, la boucle principale !
    Au temps pour moi, je me suis trompé de version

    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
     program MemorySDL;
     
    uses 
    	sdl, sdl_image;
     
    const  
    	NbColonne = 6;		NbLigne = 4;		NbImage = 14;
    	TailleC = 60;		Xmin = 0;			Xmax = 14;			
    	Ymin = 0;			Ymax = 10;			LargeurF = 540;		
    	LongueurF = 780; 
     
     
    Type
    	TGrille = array [1.. NbColonne, 1.. NbLigne] of Char;
    	TImage = array [0..NbImage] of PSDL_Surface;
    	CVisible = array [1..NbColonne, 1..NbLigne] of Boolean;
     
    {----------------------------------------------------------------------}
     
    function CreerFenetre(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 ChargerImage(var Image: TImage);
     
    begin
     
      Image[0] := IMG_Load('Image2/Fond.png');
      Image[1] := IMG_Load('Image2/Carte-2.png');
      Image[2] := IMG_Load('Image2/Curseur.png');
      Image[3] := IMG_Load('Image2/Image2-1.png');
      Image[4] := IMG_Load('Image2/Image2-2.png');
      Image[5] := IMG_Load('Image2/Image2-3.png');
      Image[6] := IMG_Load('Image2/Image2-4.png');
      Image[7] := IMG_Load('Image2/Image2-5.png');
      Image[8] := IMG_Load('Image2/Image2-6.png');
      Image[9] := IMG_Load('Image2/Image2-7.png');
      Image[10] := IMG_Load('Image2/Image2-8.png');
      Image[11] := IMG_Load('Image2/Image2-9.png');
      Image[12] := IMG_Load('Image2/Image2-10.png');
      Image[13] := IMG_Load('Image2/Image2-11.png');
      Image[14] := IMG_Load('Image2/Image2-12.png');
     
    end;
     
    {----------------------------------------------------------------------}
     
    procedure ChargerGrille(FGrille: string; var Grille: 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
          Grille[y][x] := Iterator;
          x := x + 1;
        end;
        y := y + 1;
      end;
      Close(LevelGrille);
     
    end;	
     
    {----------------------------------------------------------------------}
     
    procedure DessinerScene(Window: PSDL_Surface; var Image: TImage ; Grille: TGrille);
     
    var
      x, y: Integer;
      Position: TSDL_Rect;
     
    begin
     
      for y := 1 to Nbligne do
      begin
        for x := 1 to NbColonne do
        begin
          Position.x := (x - 1) * TailleC;
          Position.y := (y - 1) * TailleC;
    	  case string(Grille[y][x]) of  
    	  'X' : SDL_BlitSurface(Image[1], nil, Window, @Position);
    	  'A' : SDL_BlitSurface(Image[3], nil, Window, @Position);
    	  'B' : SDL_BlitSurface(Image[4], nil, Window, @Position);
    	  'C' : SDL_BlitSurface(Image[5], nil, Window, @Position);
    	  'D' : SDL_BlitSurface(Image[6], nil, Window, @Position);
    	  'E' : SDL_BlitSurface(Image[7], nil, Window, @Position);
    	  'F' : SDL_BlitSurface(Image[8], nil, Window, @Position);
    	  'G' : SDL_BlitSurface(Image[9], nil, Window, @Position);
    	  'H' : SDL_BlitSurface(Image[10], nil, Window, @Position);
    	  'I' : SDL_BlitSurface(Image[11], nil, Window, @Position);
    	  'J' : SDL_BlitSurface(Image[12], nil, Window, @Position);
    	  'K' : SDL_BlitSurface(Image[13], nil, Window, @Position);
    	  'L' : SDL_BlitSurface(Image[14], nil, Window, @Position);             
          end;
        end;
      end;
    end;
     
    {----------------------------------------------------------------------}
     
    procedure Visibilite(match : Boolean; x, y: Integer; var Visible: CVisible; Grille: TGrille);
     
    begin
     
    if (match=True) then
    	Visible[y][x]:=True;
    if (match=False) then
    begin
    	Visible[y][x]:=False;
    	Grille[y][x] := 'X';
    end;
     
    end;
     
    {----------------------------------------------------------------------}
     
    procedure DessinerCurseur(Window: PSDL_Surface; x, y: Integer; Curseur: PSDL_Surface);
     
    var
      Position: TSDL_Rect;
     
    begin
     
      Position.x := (x - 1) * TailleC;
      Position.y := (y - 1) * TailleC;
      SDL_BlitSurface(Curseur, nil, Window, @Position);
     
    end;
     
    {----------------------------------------------------------------------}
     
    function CValide(Grille: TGrille; x, y: Integer): Boolean;
     
    begin
     
      if (x = Xmin) or (x = Xmax) or (y = Ymin) or (y = Ymax) then
        Exit(False)
      else
        Exit(True);
     
    end;
     
    {----------------------------------------------------------------------}
     
    procedure SelectionnerCarte(var x, y: Integer);
     
    begin
     
    x:=x;
    y:=y;
     
    end;
     
    {----------------------------------------------------------------------}
     
    procedure ComparerCarte(x1,y1,x2,y2 : Integer; Grille: TGrille ; var match : Boolean);
     
    begin
     
    if (Grille[y1][x1]) = (Grille[y2][x2])  then
    	match:=True 
    else
    	match:=False
     
    end;
     
    {----------------------------------------------------------------------}
     
    procedure ActualiserGrille(var x1,y1,x2,y2 : Integer; match : Boolean; Grille: TGrille; var Visible : CVisible);
     
    begin
     
    if (match=False) then
    	begin
    		Visibilite(match,x1,y1, Visible, Grille);
    		Visibilite(match,x2,y2, Visible, Grille);
    	end;
    if (match=True) then
    	begin
    		Visibilite(match,x1,y1, Visible, Grille);
    		Visibilite(match,x2,y2, Visible, Grille);
    	end;
    end;
     
    {----------------------------------------------------------------------}
     
    procedure Deplacer(Window: PSDL_Surface; var Image: TImage;  Grille: TGrille; S_x, S_y: Integer);
     
    var
      Event: TSDL_Event;
      Fin: Boolean;
      C_x, C_y: Integer;
     
    begin
     
      Fin := False;
      C_x := 2;
      C_y := 2;
      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(Grille, C_x, C_y + 2) = True) then
                    C_y := C_y + 2;
                end;
              SDLK_UP:
                begin
                  if (CVAlide(Grille, C_x, C_y - 2) = True) then
                    C_y := C_y - 2;
                end;
              SDLK_LEFT:
                begin
                  if (CValide(Grille, C_x - 2, C_y) = True) then
                    C_x := C_x - 2;
                end;
              SDLK_RIGHT:
                begin
                  if (CValide(Grille, C_x + 2, C_y) = True) then
                    C_x := C_x + 2;      
                end;
              SDLK_RETURN:
                begin
                  S_x := C_x;
                  S_y := C_y;
                end;
             end; 
          end;
      end;
    end;
    end;
     
    {----------------------------------------------------------------------}
     
    procedure Tour(Window: PSDL_Surface; Image: TImage; x, y, x1, x2, y1, y2: Integer; Grille: TGrille; match: Boolean; Visible: CVisible);
     
    var
    	i:Integer;
     
    begin
     
    match:=True;
    i:=1;
    repeat
    begin
    	Deplacer(Window, Image, Grille, x, y);
    	SelectionnerCarte(x, y);
    	Visibilite(match, x, y, Visible, Grille);
    	i:=i+1;
    end;	
    until i=2;
    ComparerCarte(x1, y1, x2, y2, Grille, match);
    ActualiserGrille(x1, y1, x2, y2, match, Grille, Visible);
    end;
     
    {----------------------------------------------------------------------}
     
    procedure LibererImages(var Image: TImage);
     
    var
      i: Integer;
     
    begin
     
      for i := 0 to (NbImage + 1) do
      begin
        Dispose(Image[i]);
      end;
     
    end;
     
    {----------------------------------------------------------------------}
     
    procedure Gagner(Visible: CVisible; var boucle: Boolean);
     
    var
    	i, j: Integer;
     
    begin
     
    for i:=1 to Nbligne do
    	for j:=1 to NbColonne do
    		if (Visible[i][j] = True) then
    			boucle:=True
    		else
    			boucle:=False;
     
    end;
     
     
    {----------------------------------------------------------------------}
     
    var
    	boucle: Boolean;		
    	Window: PSDL_Surface;
    	Image: TImage;
    	x, y, x1, x2, y1, y2, C_x, C_y, i, j: Integer;
    	Grille: TGrille;
    	match: Boolean;
    	Visible: CVisible;
     
    begin
     
    match := True;
    boucle := False;
    x:=0;
    y:=0;
    x1:=0;
    x2:=0;
    y1:=0;
    y2:=0;
    C_x:=0;
    C_y:=0;
    for i:=1 to NbColonne do
    	for j:=1 to NbLigne do
    		Visible[i][j] := False;
    repeat
    begin
      ChargerImage(Image);
      Window := CreerFenetre(LongueurF, LargeurF, 'Memory - Niveau : Intermédiaire');
      SDL_BlitSurface(Image[0],nil,Window, nil);
      ChargerGrille('Fichier2/GrilleLevel2.txt', Grille);
      Tour(Window, Image, x, y, x1, y1, x2, y2, Grille, match, Visible);
      DessinerScene(Window, Image, Grille);
      DessinerCurseur(Window, C_x, C_y, Image[2]);
      Gagner(Visible, boucle);
      SDL_Flip(Window);
      SDL_Delay(30);
    end;  
    until boucle=True;
    LibererImages(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 072
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 50
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Décembre 2011
    Messages : 4 072
    Points : 15 462
    Points
    15 462
    Billets dans le blog
    9
    Par défaut
    As-tu testé le code que tu viens de poster ? Parce que, pour ma part, je n'obtiens qu'un écran noir quand je l'exécute.
    Mon site personnel consacré à MSEide+MSEgui : msegui.net

  9. #9
    Membre à l'essai
    Profil pro
    Inscrit en
    Février 2014
    Messages
    14
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2014
    Messages : 14
    Points : 15
    Points
    15
    Par défaut
    oui ça me faisait le même résultat et je ne sais d'où cela viens

  10. #10
    Membre à l'essai
    Profil pro
    Inscrit en
    Février 2014
    Messages
    14
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2014
    Messages : 14
    Points : 15
    Points
    15
    Par défaut
    J'ai modifié le programme principale et ça m'affiche toutes les cartes retournées par contre le fond et le curseur ne s'affiche pas.
    De plus je ne vois pas comment faire pour afficher les cartes avec un écart entre chacune d'elle.
    Et mon tableau de booléen ne semble pas fonctionner.

    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
    var
    	boucle: Boolean;		
    	Window: PSDL_Surface;
    	Image: TImage;
    	x, y, x1, x2, y1, y2, C_x, C_y, i, j: Integer;
    	Grille: TGrille;
    	match: Boolean;
    	Visible: CVisible;
     
    begin
     
    match := True;
    boucle := False;
    x:=0;
    y:=0;
    x1:=0;
    x2:=0;
    y1:=0;
    y2:=0;
    C_x:=0;
    C_y:=0;
    for i:=1 to NbColonne do
    	for j:=1 to NbLigne do
    		Visible[i][j] := False;
    repeat
    begin
      ChargerImage(Image);
      Window := CreerFenetre(LongueurF, LargeurF, 'Memory - Niveau : Intermédiaire');
      SDL_BlitSurface(Image[0],nil,Window, nil);
      ChargerGrille('Fichier2/FichierGrille2.txt', Grille);
      DessinerScene(Window, Image, Grille);
      DessinerCurseur(Window, C_x, C_y, Image[2]);
      Tour(Window, Image, x, y, x1, y1, x2, y2, Grille, match, Visible);
      DessinerScene(Window, Image, Grille);
      DessinerCurseur(Window, C_x, C_y, Image[2]);
      Gagner(Visible, boucle);
      SDL_Flip(Window);
      SDL_Delay(30);
    end;  
    until boucle=True;
    LibererImages(Image);
    SDL_Quit;
     
    end
    PS : J'ai aussi changer le fichier en enlevant tous les "Z"

  11. #11
    Rédacteur/Modérateur

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

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Décembre 2011
    Messages : 4 072
    Points : 15 462
    Points
    15 462
    Billets dans le blog
    9
    Par défaut
    Tu n'as pas écouté mon conseil, quand je te disais de ne pas te précipiter !

    Ton code est rempli d'erreurs et de choses mal conçues. Dis-moi un peu, par exemple, quel effet tu attends de cette procédure :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    procedure SelectionnerCarte(var x, y: Integer);
    begin
      x := x;
      y := y;
    end;


    J'ai corrigé ce que j'ai pu mais je n'ai pas pu aller au bout parce qu'à un moment donné je ne comprenais plus rien à ton code. Je poste quand même ce que j'ai fait : tu y trouveras la réponse à certaines questions que tu as posées.

    Combien de temps te reste-t-il pour finir ?

    Ne te décourage pas : tu n'es pas si loin de la solution, mais il faut aller lentement et procéder par étapes.
    Fichiers attachés Fichiers attachés
    Mon site personnel consacré à MSEide+MSEgui : msegui.net

  12. #12
    Membre à l'essai
    Profil pro
    Inscrit en
    Février 2014
    Messages
    14
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2014
    Messages : 14
    Points : 15
    Points
    15
    Par défaut
    Citation Envoyé par Roland Chastain Voir le message
    Combien de temps te reste-t-il pour finir ?
    C'est justement ça le problème c'est qu'il me reste que quelques jours.

    J'ai voulu tout séparé dans mon programme c'est à dire les déplacements des sélections, ...
    Puis j'ai regroupé tout ce qui concerne un tour de jeu (comparaison, actualiser, retournement,...) dans une procédure
    Puis je répète cette procédure et les élément de la SDL dans le programme principale tant que le tableau de booléen ne contient pas que des "True"

    Pour en revenir à SelectionnerCarte je voulais juste enregistrer les coordonnées des cartes pour pourvoir les fournir à d'autres procédures et ainsi pouvoir les utiliser.

  13. #13
    Rédacteur/Modérateur

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

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Décembre 2011
    Messages : 4 072
    Points : 15 462
    Points
    15 462
    Billets dans le blog
    9
    Par défaut
    J'ai nettoyé ton code (voir pièce jointe de mon précédent message) pour que nous puissions repartir sur une bonne base. J'ai supprimé beaucoup de choses : donc le programme est incomplet. Mais il fonctionne parfaitement et (je crois) ne contient plus d'erreurs.

    J'ai fait certaines modifications qui n'étaient pas indispensables mais qui permettaient de compacter le code. L'écran de mon ordinateur est petit et je n'aime pas trop fatiguer mon doigt sur la roulette de la souris. A toi de voir si tu veux conserver ces modifications ou pas.

    Sur la bonne façon de libérer les images, voir ce message du prince des programmeurs en Pascal.

    Voilà, il reste à finir le programme pour en faire un jeu. Ne va pas trop vite. Montre-nous au fur et à mesure tes idées.
    Mon site personnel consacré à MSEide+MSEgui : msegui.net

  14. #14
    Membre à l'essai
    Profil pro
    Inscrit en
    Février 2014
    Messages
    14
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2014
    Messages : 14
    Points : 15
    Points
    15
    Par défaut
    Merci pour ton code c'est vrai qu'il est plus clair comme cela par contre j'aimerais sortir les coordonnées de chaque carte sélectionnée dans la boucle repeat afin de pour voir comparer les cartes et je ne vois pas comment faire.

    Enfin le programme ne me les fournis que lorsque que je quitte la sdl

  15. #15
    Rédacteur/Modérateur

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

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Décembre 2011
    Messages : 4 072
    Points : 15 462
    Points
    15 462
    Billets dans le blog
    9
    Par défaut
    A mon avis, il faut utiliser une variable globale contenant les informations dont on a besoin sur la dernière carte découverte (que j'ai appelée dans mes commentaires "carte à marier"). Voici une démonstration vite faite.

    Par contre je m'aperçois d'une chose à laquelle je n'avais pas pensé, c'est qu'avec ma façon d'initialiser la grille, les cartes ne sont pas distribuées comme il faut (par paires). Du coup je comprends pourquoi tu utilisais un fichier.

    Donc ce point sera à corriger.
    Fichiers attachés Fichiers attachés
    Mon site personnel consacré à MSEide+MSEgui : msegui.net

  16. #16
    Rédacteur/Modérateur

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

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Décembre 2011
    Messages : 4 072
    Points : 15 462
    Points
    15 462
    Billets dans le blog
    9
    Par défaut
    Une modification rapide de la procédure ChargerGrille() :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    procedure ChargerGrille(var aGrille: TGrille);
    var
      x, y, i: Integer;
      s: string;
    begin
      s := 'AABBCCDDEEFFGGHHIIJJKKLL';
      for x := 1 to NOMBRE_COLONNES do
        for y := 1 to NOMBRE_LIGNES do
        begin
          i := Random(Length(s)) + 1;
          aGrille[x, y] := s[i];
          Delete(s, i, 1);
        end;
    end;
    Mon site personnel consacré à MSEide+MSEgui : msegui.net

Discussions similaires

  1. [Free Pascal] [SDL] Problème SDL - Jeu du Memory
    Par Taazer dans le forum Free Pascal
    Réponses: 7
    Dernier message: 15/11/2014, 22h01
  2. [Dates] Problème comparaison de dates
    Par Davboc dans le forum Langage
    Réponses: 2
    Dernier message: 23/08/2006, 12h23
  3. Réponses: 21
    Dernier message: 04/05/2006, 11h09
  4. [Dates] problème Comparaison dates
    Par gwen-al dans le forum Langage
    Réponses: 4
    Dernier message: 06/01/2006, 11h24
  5. problème comparaison de date VB
    Par af_airone dans le forum VB 6 et antérieur
    Réponses: 12
    Dernier message: 20/10/2005, 11h18

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