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 :

Création d'un circuit - Utilisation de ReadKey


Sujet :

Free Pascal

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Profil pro
    Inscrit en
    Octobre 2008
    Messages
    30
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Octobre 2008
    Messages : 30
    Par défaut Création d'un circuit - Utilisation de ReadKey
    Bonjour à tous,
    J'apprends le pascal pour le plaisir personnel et je me suis attaqué depuis ce matin au readkey.

    Voici mon code source,
    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
     Program readkeytest;
     Uses crt;
     Var x,y: byte; mv: char;
     Begin
     cursoroff;
     x:=40;
     y:=10;
     While not(keypressed) do
      Begin
       GotoXY (x,y);
       If (mv='q') OR (mv='d') then WriteLn ('--');
       If (mv='z') OR (mv='s') then WriteLn ('|');
       mv:=readkey;
       If (mv='q') AND (x>1) then x:=x-1;
       If (mv='d') AND (x<78) then x:=x+1;
       If (mv='z') AND (y>1) then y:=y-1;
       If (mv='s') AND (y<24) then y:=y+1;
       clrscr;
      End;
    ReadLn
    End.
    Il fonctionne mais étant débutant, pouvez vous me dire s'il est fait de manière optimal?
    Merci à tous de m'aidez au plus vite.

  2. #2
    Responsable Pascal, Lazarus et Assembleur


    Avatar de Alcatîz
    Homme Profil pro
    Ressources humaines
    Inscrit en
    Mars 2003
    Messages
    8 049
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 58
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ressources humaines
    Secteur : Service public

    Informations forums :
    Inscription : Mars 2003
    Messages : 8 049
    Billets dans le blog
    2
    Par défaut
    Bonjour,

    Il y a des améliorations à apporter aux tests.

    Le premier :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     If (mv='q') OR (mv='d') then WriteLn ('--');
     If (mv='z') OR (mv='s') then WriteLn ('|');
    Tel quel, le second if s'exécute toujours, même si le premier est vrai, ce qui est inutile. Pour éviter cela, un if then else s'impose :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    If (mv='q') OR (mv='d') then 
       WriteLn ('--')
    else
       If (mv='z') OR (mv='s') then WriteLn ('|');

    La remarque est identique pour le second :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     If (mv='q') AND (x>1) then x:=x-1;
     If (mv='d') AND (x<78) then x:=x+1;
     If (mv='z') AND (y>1) then y:=y-1;
     If (mv='s') AND (y<24) then y:=y+1;
    Mais, dans ce cas, une structure case of est particulièrement adaptée :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
       case mv of
         'q' : if x > 1 then x := x - 1;
         'd' : if x < 78 then x := x + 1;
         'z' : if y > 1 then y := y - 1;
         's' : if y < 24 then y := y + 1;
       end;
    Il serait bien, également, de prévoir une possibilité de sortie de boucle.
    Règles du forum
    Cours et tutoriels Pascal, Delphi, Lazarus et Assembleur
    Avant de poser une question, consultez les FAQ Pascal, Delphi, Lazarus et Assembleur
    Mes tutoriels et sources Pascal

    Le problème en ce bas monde est que les imbéciles sont sûrs d'eux et fiers comme des coqs de basse cour, alors que les gens intelligents sont emplis de doute. [Bertrand Russell]
    La tolérance atteindra un tel niveau que les personnes intelligentes seront interdites de toute réflexion afin de ne pas offenser les imbéciles. [Fiodor Mikhaïlovitch Dostoïevski]

  3. #3
    Membre averti
    Profil pro
    Inscrit en
    Octobre 2008
    Messages
    30
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Octobre 2008
    Messages : 30
    Par défaut
    merci pour ta réponse.
    Je m'entraine donc à faire des programmes pour évoluer. J'ai décidé de faire un jeux de F1 (un bien grand mot haha). Donc enfaite j'ai déjà tracé le circuit, je sais faire bouger la "voiture" (une simple flèche lol) dans tout les sens. Mais j'aimerais que la voiture doivent faire 5 tours par exemple. Je dois alors mettre un compteur qui retire 1 à la variable "tour" initialisé à 5. Mais je ne sais pas où mettre se compteur. J'aimerais également mettre un chronomètre. J'ai recherché et j'ai trouvé ceci:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
     uses
      SysUtils;
     
    var
      Debut : double;
      Ligne: char;
    BEGIN
      Debut := Now;
      While (Ligne<>#13) do
       Begin
          WriteLn('secondes : ', FormatDateTime('s', Now - debut));
       End;
    END.
    Donc je mets çà dans une fonction. Mais où appeler cette fonction? Car si je la mets dans la boucle, les secondes augmentent uniquement quand j'appuie sur une touche alors qu'elles devraient augmenter toutes les secondes lol. Depuis, ce conteur monte uniquement jusque 60 et reviens ensuite à 0.

    Voici mon code source:

    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
    Program readkeytest1;
    Uses SysUtils, crt;
     
    Var x, y, tour: byte; mv: char;
     
    Procedure Circuit;
     Begin
       tour:=5;
       GotoXY (6,1); WriteLn ('--------------------'); GotoXY (11,5); WriteLn ('----------------'); GotoXY (23,2); WriteLn ('   |');
       GotoXY (5,2); WriteLn ('|   '); GotoXY (23,3); WriteLn ('   |'); GotoXY (5,3); WriteLn ('|    ');
       GotoXY (23,4); WriteLn ('   |'); GotoXY (5,4); WriteLn ('|    '); GotoXY (23,5); WriteLn ('   |'); GotoXY (5,5); WriteLn ('|    ');
       GotoXY (23,6); WriteLn ('|   '); GotoXY (5,6); WriteLn ('|    |'); GotoXY (23,7); WriteLn ('|   '); GotoXY (5,7); WriteLn ('|    |');
       GotoXY (23,8); WriteLn ('|   '); GotoXY (5,8); WriteLn ('|    |'); GotoXY (27,6); WriteLn ('----------------'); GotoXY (5,9); WriteLn ('|    |');
       GotoXY (24,9); WriteLn ('----------------'); GotoXY (5,10); WriteLn ('|    |'); GotoXY (38,7);  WriteLn ('     |'); GotoXY (5,11); WriteLn ('|    |');
       GotoXY (38,8);  WriteLn ('     |'); GotoXY (5,12); WriteLn ('|    |'); GotoXY (38,9);  WriteLn ('     |'); GotoXY (5,13); WriteLn ('|    |');
       GotoXY (38,10); WriteLn ('|    |'); GotoXY (5,14); WriteLn ('|    |'); GotoXY (38,11); WriteLn ('|    |'); GotoXY (5,15); WriteLn ('|    |');
       GotoXY (38,12); WriteLn ('|    |'); GotoXY (5,16); WriteLn ('|    |'); GotoXY (38,13); WriteLn ('|    |'); GotoXY (5,17); WriteLn ('|    |');
       GotoXY (38,14); WriteLn ('|    |'); GotoXY (5,18); WriteLn ('|    |'); GotoXY (38,15); WriteLn ('|    |'); GotoXY (5,19); WriteLn ('|    |');
       GotoXY (38,16); WriteLn ('|    |'); GotoXY (5,20); WriteLn ('|    |'); GotoXY (38,17); WriteLn ('|     '); GotoXY (5,21); WriteLn ('|     ');
       GotoXY (38,18); WriteLn ('|     '); GotoXY (5,22); WriteLn ('|     '); GotoXY (38,19); WriteLn ('|     '); GotoXY (5,23); WriteLn ('|     ');
       GotoXY (11,21); WriteLn ('---------------------------------------------------------------'); GotoXY (6,24); WriteLn ('------------------------------------------------------------------------');
       GotoXY (73,23); WriteLn ('     |'); GotoXY (73,22); WriteLn ('     |'); GotoXY (73,21); WriteLn ('     |'); GotoXY (73,20); WriteLn ('|    |');
       GotoXY (73,19); WriteLn ('|    |'); GotoXY (73,18); WriteLn ('|    |'); GotoXY (73,17); WriteLn ('|    |'); GotoXY (73,16); WriteLn ('|    |');
       GotoXY (73,15); WriteLn ('|    |'); GotoXY (73,14); WriteLn ('|    |'); GotoXY (73,13); WriteLn ('|    |');
       GotoXY (73,12); WriteLn ('|    |'); GotoXY (73,11); WriteLn ('|    |'); GotoXY (73,10); WriteLn ('     |'); GotoXY (73,11); WriteLn ('     |');
       GotoXY (73,12); WriteLn ('     |'); GotoXY (57,12); WriteLn ('----------------'); GotoXY (62,9); WriteLn ('----------------');
       GotoXY (56,9); WriteLn ('|'); GotoXY (56,10); WriteLn ('|'); GotoXY (56,11); WriteLn ('|'); GotoXY (56,8); WriteLn ('|    |');
       GotoXY (56,7); WriteLn ('|    |'); GotoXY (56,6); WriteLn ('|    |'); GotoXY (56,5); WriteLn ('|    |'); GotoXY (56,4); WriteLn ('     |');
       GotoXY (56,3); WriteLn ('     |'); GotoXY (56,2); WriteLn ('     |'); GotoXY (47,1); WriteLn ('--------------'); GotoXY (52,4); WriteLn ('----');
       GotoXY (46,2); WriteLn ('|'); GotoXY (46,3); WriteLn ('|'); GotoXY (46,4); WriteLn ('|'); GotoXY (46,5); WriteLn ('|    |');
       GotoXY (46,6); WriteLn ('|    |'); GotoXY (46,7); WriteLn ('|    |'); GotoXY (46,8); WriteLn ('|    |'); GotoXY (46,9); WriteLn ('|    |');
       GotoXY (46,10); WriteLn ('|    |'); GotoXY (46,11); WriteLn ('|    |'); GotoXY (46,12); WriteLn ('|    |'); GotoXY (46,13); WriteLn ('|    |');
       GotoXY (46,14); WriteLn ('|    |'); GotoXY (46,15); WriteLn ('|    |'); GotoXY (46,16); WriteLn ('|    |'); GotoXY (46,17); WriteLn ('     |');
       GotoXY (46,18); WriteLn ('     |'); GotoXY (46,19); WriteLn ('     |'); GotoXY (44,17); WriteLn ('--'); GotoXY (39,20); WriteLn ('------------');
       GotoXY (41,23); WriteLn ('|'); GotoXY (41,22); WriteLn ('|');
       textcolor (4); GotoXY (31,3); WriteLn ('F1 *******')
       GotoXY (63,3); Write ('Tour(s): '); WriteLn (tour);
       GotoXY (63,5); WriteLn('Temps : ');
     End;
     
    Begin
     mv:='a';
     cursoroff;
     x:=40;
     y:=23;
     GotoXY (x,y); textcolor (4); WriteLn ('>');
     While not(keypressed) AND (mv<>#13) do
        Begin
          textcolor (8);
          Circuit;
          GotoXY (x,y);
          textcolor (4);
          Case mv of
             'q' : If (x>1)  then WriteLn ('<');
             'd' : If (x<78) then WriteLn ('>');
             'z' : If (y>1)  then WriteLn ('^');
             's' : If (y<24) then WriteLn ('V');
            End;
          mv:=readkey;
          Case mv of
             'q' : If (x>1)  then x:=x-1;
             'd' : If (x<78) then x:=x+1;
             'z' : If (y>1)  then y:=y-1;
             's' : If (y<24) then y:=y+1;
            End;
         Clrscr;
       End;
    End.
    J'ai enlevé la fonction étant donné que je ne savais pas où l'appeler.

  4. #4
    Responsable Pascal, Lazarus et Assembleur


    Avatar de Alcatîz
    Homme Profil pro
    Ressources humaines
    Inscrit en
    Mars 2003
    Messages
    8 049
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 58
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ressources humaines
    Secteur : Service public

    Informations forums :
    Inscription : Mars 2003
    Messages : 8 049
    Billets dans le blog
    2
    Par défaut
    Hé mais ce n'est pas mal du tout !

    L'ajout d'une véritable horloge n'est pas chose aisée; pour t'en convaincre, fais une recherche sur le forum avec le mot-clé timer. Pour pouvoir utiliser le résultat de la fonction Now, tu peux le convertir en TSystemTime à l'aide de la procédure DateTimeToSystemTime.

    La structure TSystemTime te permet d'avoir (entre autres) les minutes et les secondes :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
       TSystemTime = record
          Year, Month, Day: word;
          Hour, Minute, Second, MilliSecond: word;
       end;
    Et voici la conversion du résultat de Now :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
     DateTimeToSystemTime(Now,Debut);
    Avant cela, il faudrait pouvoir gérer le parcours lui-même, pour éviter que la voiture quitte le circuit et pour pouvoir détecter qu'elle franchit la ligne de départ, pour pouvoir compter les tours.

    Règles du forum
    Cours et tutoriels Pascal, Delphi, Lazarus et Assembleur
    Avant de poser une question, consultez les FAQ Pascal, Delphi, Lazarus et Assembleur
    Mes tutoriels et sources Pascal

    Le problème en ce bas monde est que les imbéciles sont sûrs d'eux et fiers comme des coqs de basse cour, alors que les gens intelligents sont emplis de doute. [Bertrand Russell]
    La tolérance atteindra un tel niveau que les personnes intelligentes seront interdites de toute réflexion afin de ne pas offenser les imbéciles. [Fiodor Mikhaïlovitch Dostoïevski]

  5. #5
    Membre averti
    Profil pro
    Inscrit en
    Octobre 2008
    Messages
    30
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Octobre 2008
    Messages : 30
    Par défaut
    J'ai limité le circuit, la "voiture" ne sait plus en sortir. Par contre la décrémentais du nombre de tour ne fonctionne pas, sans doute que la condition est mauvaise mais j'ai du mal à voir quoi mettre.

    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
    Program readkeytest1;
    Uses SysUtils, crt;
     
    Var x, y, tour: byte; mv: char;
     
    Procedure Circuit;
     Begin
       tour:=5;
       GotoXY (6,1); WriteLn ('--------------------'); GotoXY (11,5); WriteLn ('----------------'); GotoXY (23,2); WriteLn ('   |');
       GotoXY (5,2); WriteLn ('|   '); GotoXY (23,3); WriteLn ('   |'); GotoXY (5,3); WriteLn ('|    ');
       GotoXY (23,4); WriteLn ('   |'); GotoXY (5,4); WriteLn ('|    '); GotoXY (23,5); WriteLn ('   |'); GotoXY (5,5); WriteLn ('|    ');
       GotoXY (23,6); WriteLn ('|   '); GotoXY (5,6); WriteLn ('|    |'); GotoXY (23,7); WriteLn ('|   '); GotoXY (5,7); WriteLn ('|    |');
       GotoXY (23,8); WriteLn ('|   '); GotoXY (5,8); WriteLn ('|    |'); GotoXY (27,6); WriteLn ('----------------'); GotoXY (5,9); WriteLn ('|    |');
       GotoXY (24,9); WriteLn ('----------------'); GotoXY (5,10); WriteLn ('|    |'); GotoXY (38,7);  WriteLn ('     |'); GotoXY (5,11); WriteLn ('|    |');
       GotoXY (38,8);  WriteLn ('     |'); GotoXY (5,12); WriteLn ('|    |'); GotoXY (38,9);  WriteLn ('     |'); GotoXY (5,13); WriteLn ('|    |');
       GotoXY (38,10); WriteLn ('|    |'); GotoXY (5,14); WriteLn ('|    |'); GotoXY (38,11); WriteLn ('|    |'); GotoXY (5,15); WriteLn ('|    |');
       GotoXY (38,12); WriteLn ('|    |'); GotoXY (5,16); WriteLn ('|    |'); GotoXY (38,13); WriteLn ('|    |'); GotoXY (5,17); WriteLn ('|    |');
       GotoXY (38,14); WriteLn ('|    |'); GotoXY (5,18); WriteLn ('|    |'); GotoXY (38,15); WriteLn ('|    |'); GotoXY (5,19); WriteLn ('|    |');
       GotoXY (38,16); WriteLn ('|    |'); GotoXY (5,20); WriteLn ('|    |'); GotoXY (38,17); WriteLn ('|     '); GotoXY (5,21); WriteLn ('|     ');
       GotoXY (38,18); WriteLn ('|     '); GotoXY (5,22); WriteLn ('|     '); GotoXY (38,19); WriteLn ('|     '); GotoXY (5,23); WriteLn ('|     ');
       GotoXY (11,21); WriteLn ('---------------------------------------------------------------'); GotoXY (6,24); WriteLn ('------------------------------------------------------------------------');
       GotoXY (73,23); WriteLn ('     |'); GotoXY (73,22); WriteLn ('     |'); GotoXY (73,21); WriteLn ('     |'); GotoXY (73,20); WriteLn ('|    |');
       GotoXY (73,19); WriteLn ('|    |'); GotoXY (73,18); WriteLn ('|    |'); GotoXY (73,17); WriteLn ('|    |'); GotoXY (73,16); WriteLn ('|    |');
       GotoXY (73,15); WriteLn ('|    |'); GotoXY (73,14); WriteLn ('|    |'); GotoXY (73,13); WriteLn ('|    |');
       GotoXY (73,12); WriteLn ('|    |'); GotoXY (73,11); WriteLn ('|    |'); GotoXY (73,10); WriteLn ('     |'); GotoXY (73,11); WriteLn ('     |');
       GotoXY (73,12); WriteLn ('     |'); GotoXY (57,12); WriteLn ('----------------'); GotoXY (62,9); WriteLn ('----------------');
       GotoXY (56,9); WriteLn ('|'); GotoXY (56,10); WriteLn ('|'); GotoXY (56,11); WriteLn ('|'); GotoXY (56,8); WriteLn ('|    |');
       GotoXY (56,7); WriteLn ('|    |'); GotoXY (56,6); WriteLn ('|    |'); GotoXY (56,5); WriteLn ('|    |'); GotoXY (56,4); WriteLn ('     |');
       GotoXY (56,3); WriteLn ('     |'); GotoXY (56,2); WriteLn ('     |'); GotoXY (47,1); WriteLn ('--------------'); GotoXY (52,4); WriteLn ('----');
       GotoXY (46,2); WriteLn ('|'); GotoXY (46,3); WriteLn ('|'); GotoXY (46,4); WriteLn ('|'); GotoXY (46,5); WriteLn ('|    |');
       GotoXY (46,6); WriteLn ('|    |'); GotoXY (46,7); WriteLn ('|    |'); GotoXY (46,8); WriteLn ('|    |'); GotoXY (46,9); WriteLn ('|    |');
       GotoXY (46,10); WriteLn ('|    |'); GotoXY (46,11); WriteLn ('|    |'); GotoXY (46,12); WriteLn ('|    |'); GotoXY (46,13); WriteLn ('|    |');
       GotoXY (46,14); WriteLn ('|    |'); GotoXY (46,15); WriteLn ('|    |'); GotoXY (46,16); WriteLn ('|    |'); GotoXY (46,17); WriteLn ('     |');
       GotoXY (46,18); WriteLn ('     |'); GotoXY (46,19); WriteLn ('     |'); GotoXY (44,17); WriteLn ('--'); GotoXY (39,20); WriteLn ('------------');
       GotoXY (41,23); WriteLn ('|'); GotoXY (41,22); WriteLn ('|');
       textcolor (4); GotoXY (31,3); WriteLn ('F1 *******');
     
       If (x=41) AND ((y=22) OR (y=23)) then tour:=tour-1;
     
       GotoXY (63,3); Write ('Tour(s): '); WriteLn (tour);
       GotoXY (63,5); Write('Temps: ');
     End;
     
    Begin
     mv:='a';
     cursoroff;
     x:=40;
     y:=23;
     GotoXY (x,y); textcolor (4); WriteLn ('>');
     While not(keypressed) AND (mv<>#13) AND (tour>=0) do
        Begin
          textcolor (8);
          Circuit;
          GotoXY (x,y);
          textcolor (4);
          Case mv of
             'q' : WriteLn ('<');
             'd' : WriteLn ('>');
             'z' : WriteLn ('^');
             's' : WriteLn ('V');
            End;
          mv:=readkey;                                  (*Limite circuit extremite*)
     
          Case mv of
             'q' : If (x>6)  then x:=x-1;
             'd' : If (x<77) then x:=x+1;
             'z' : If (y>2)  then y:=y-1;
             's' : If (y<23) then y:=y+1;
            End;
                                                          (*Limites circuit entier*)
               If ((y=20) AND (x>38) AND (x<51)) OR ((y=12) AND (x>56) AND (x<74)) OR ((y=4) AND (x>50) AND (x<57)) OR ((y=9) AND (x>2) AND (x<39)) OR ((y=5) AND (x>9) AND (x<24))  then y:=y-1
          Else If ((y=21) AND (x>9) AND (x<74)) OR ((y=9) AND (x>60) AND (x<78)) OR ((y=17) AND (x>42) AND (x<47)) OR ((y=6) AND (x>25) AND (x<43))then y:=y+1
          Else If ((x=10) AND (y>5) AND (y<22)) OR ((x=26) AND (y>1) AND (y<6)) OR ((x=43) AND (y>6) AND (y<17)) OR ((x=51) AND (y>4) AND (y<20)) OR ((x=61) AND (y>1) AND (y<9)) then x:=x-1
          Else If ((x=23) AND (y>5) AND (y<10)) OR ((x=38) AND (y>8) AND (y<20)) OR ((x=46) AND (y>1) AND (y<18)) OR ((x=56) AND (y>4) AND (y<12)) OR ((x=73) AND (y>11) AND (y<21))then x:=x+1;
     
     
         Clrscr;
       End;
     clrscr;
     GotoXY (15,10); WriteLn ('Vous avez fait les 5 tours ! Relancez le jeu pour rejouez');
     ReadLn;
    End.


    Pour le temps, je dois donc utiliser ce record et ensuite faire une fonction utilisant ce record et gérant le temps? Ensuite où dois je appelé cette fonction pour que le compteur se change automatiquement?

  6. #6
    Responsable Pascal, Lazarus et Assembleur


    Avatar de Alcatîz
    Homme Profil pro
    Ressources humaines
    Inscrit en
    Mars 2003
    Messages
    8 049
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 58
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ressources humaines
    Secteur : Service public

    Informations forums :
    Inscription : Mars 2003
    Messages : 8 049
    Billets dans le blog
    2
    Par défaut
    La technique que tu utilises pour délimiter le circuit ne peut délimiter qu'un et un seul seul circuit. Tu pourrais opter pour une grille et, parallèlement au déplacement de la voiture à l'écran, tu "déplacerais" un curseur à l'intérieur de la grille, pour détecter les limites du circuit et la ligne de départ.
    De cette manière, tu pourrais très facilement changer de circuit : il suffirait de charger un autre tableau en mémoire.

    Exemple :

    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
    0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0
    0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0
    0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0
    0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0
    1 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 1 0
    1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1
    1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1
    1 2 2 2 1 0 0 0 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 1 0 0 0 1
    1 0 0 0 1 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 1
    1 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 1
    1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 1
    0 1 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 0 0 1 1 1 0 0 0 0 0 1
    0 0 1 0 0 0 0 1 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0
    0 0 0 1 1 1 1 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 1 0 0
    0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 0 0 0
    Les 0 seraient roulables, les 1 les limites à ne pas franchir et les 2 la ligne de départ.

    Pour la programmation de ton timer, il faudrait que tu précises quel compilateur tu utilises (je suppose que c'est Free Pascal ?) et pour quelle plateforme tu compiles.

    Règles du forum
    Cours et tutoriels Pascal, Delphi, Lazarus et Assembleur
    Avant de poser une question, consultez les FAQ Pascal, Delphi, Lazarus et Assembleur
    Mes tutoriels et sources Pascal

    Le problème en ce bas monde est que les imbéciles sont sûrs d'eux et fiers comme des coqs de basse cour, alors que les gens intelligents sont emplis de doute. [Bertrand Russell]
    La tolérance atteindra un tel niveau que les personnes intelligentes seront interdites de toute réflexion afin de ne pas offenser les imbéciles. [Fiodor Mikhaïlovitch Dostoïevski]

  7. #7
    Membre confirmé Avatar de samaury
    Homme Profil pro
    Chevalier Jedi
    Inscrit en
    Mars 2008
    Messages
    114
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Côte d'Ivoire

    Informations professionnelles :
    Activité : Chevalier Jedi
    Secteur : Finance

    Informations forums :
    Inscription : Mars 2008
    Messages : 114
    Par défaut
    Bonjour
    D'après ce que je comprends du code de Alcatiz, la fonction caseSuivante te renvoie "automatiquement" la valeur de la case sur laquelle se trouve la voiture.
    Pour rappel, ces valeurs sont définies dans
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    Const roulable=0;      (* Case sur laquelle on peut rouler *)
          bordure=1;       (* Bord du circuit *)
          lignedepart=2;   (* Ligne de départ *)
    C'est à toi lorsque tu "dessineras" ton circuit de déssiner
    - la zone "roulable" valeur 0
    - les "bordures" valeur 1
    - la ligne de "départ" valeur 2
    Cette methode a l'avantage de ne pas t'obliger à coder en dur le circuit...comme dis Alcatiz.

Discussions similaires

  1. Réponses: 4
    Dernier message: 21/03/2011, 11h54
  2. Création de virtualhost pour utilisation local
    Par BeRoots dans le forum Apache
    Réponses: 9
    Dernier message: 08/10/2007, 22h26
  3. Réponses: 14
    Dernier message: 08/08/2007, 18h36
  4. Problème : création de bibliothèque et utilisation
    Par damien77 dans le forum Code::Blocks
    Réponses: 8
    Dernier message: 21/03/2007, 22h56
  5. prb création d'une fonction utilisant des fonctions de postgis
    Par Benjamin_es dans le forum PostgreSQL
    Réponses: 2
    Dernier message: 13/03/2007, 11h34

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