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

Flash Pascal Discussion :

Projet d'un programme permettant de visualiser une position du jeu des échecs [Flash Pascal]


Sujet :

Flash Pascal

Mode arborescent

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Rédacteur/Modérateur

    Avatar de Roland Chastain
    Homme Profil pro
    Enseignant
    Inscrit en
    Décembre 2011
    Messages
    4 130
    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 130
    Billets dans le blog
    9
    Par défaut Projet d'un programme permettant de visualiser une position du jeu des échecs
    Bonjour ! Je me lance dans un projet que je médite depuis quelque temps, et je souhaiterais avoir des conseils. Il s'agit d'un programme qui permettrait, à partir d'une chaîne au format EPD saisie par l'utilisateur, de visualiser la position correspondante sur un échiquier. Le programme produirait aussi un code HTML que l'utilisateur pourrait copier. Enfin (mais c'est déjà un peu plus compliqué), l'utilisateur pourrait placer les pièces lui-même. J'ai un modèle qui est le programme EPD2diag.

    Voici une première étude.

    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
    (* EPD Visualizer *)
     
    program Etude;
     
    uses
      Flash8;
     
    {$FRAME_WIDTH 484}
    {$FRAME_HEIGHT 514} // 484 + 30
    {$BACKGROUND $FFFFFF}
     
    //{$FONT montreal 'Chess Montreal'}
    {$FONT alfonso 'Chess Alfonso-X'}
     
    (* Chess Montreal
       True Type font by Gary Katch
       http://alcor.concordia.ca/~gpkatch/montreal_font.html *)
     
    (* Chess Alfonso-X
       True Type Font by Armando H. Marroquin
       http://www.enpassant.dk/chess/fonteng.htm *)
     
    type
      tNature = (nothing, pawn, knight, rook, queen, king);
      tColor  = (none, white, black);
     
      tPiece  = record
        nature: tNature;
        color: tColor;
      end;
     
      tPosition = array[1..8, 1..8]of tPiece;
     
      tEditBox = class(textField)
        procedure onKeyDown;
      end;
     
    {  
    const
      stdPosition: tPosition = (
      ((nature: nothing; color: none), (nature: nothing; color: none), (nature: nothing; color: none), (nature: nothing; color: none), (nature: nothing; color: none), (nature: nothing; color: none), (nature: nothing; color: none), (nature: nothing; color: none)),
      ((nature: nothing; color: none), (nature: nothing; color: none), (nature: nothing; color: none), (nature: nothing; color: none), (nature: nothing; color: none), (nature: nothing; color: none), (nature: nothing; color: none), (nature: nothing; color: none)),
      ((nature: nothing; color: none), (nature: nothing; color: none), (nature: nothing; color: none), (nature: nothing; color: none), (nature: nothing; color: none), (nature: nothing; color: none), (nature: nothing; color: none), (nature: nothing; color: none)),
      ((nature: nothing; color: none), (nature: nothing; color: none), (nature: nothing; color: none), (nature: nothing; color: none), (nature: nothing; color: none), (nature: nothing; color: none), (nature: nothing; color: none), (nature: nothing; color: none)),
      ((nature: nothing; color: none), (nature: nothing; color: none), (nature: nothing; color: none), (nature: nothing; color: none), (nature: nothing; color: none), (nature: nothing; color: none), (nature: nothing; color: none), (nature: nothing; color: none)),
      ((nature: nothing; color: none), (nature: nothing; color: none), (nature: nothing; color: none), (nature: nothing; color: none), (nature: nothing; color: none), (nature: nothing; color: none), (nature: nothing; color: none), (nature: nothing; color: none)),
      ((nature: nothing; color: none), (nature: nothing; color: none), (nature: nothing; color: none), (nature: nothing; color: none), (nature: nothing; color: none), (nature: nothing; color: none), (nature: nothing; color: none), (nature: nothing; color: none)),
      ((nature: nothing; color: none), (nature: nothing; color: none), (nature: nothing; color: none), (nature: nothing; color: none), (nature: nothing; color: none), (nature: nothing; color: none), (nature: nothing; color: none), (nature: nothing; color: none))
      );
    }
     
    function stdPosition: tPosition;
    var
      x, y: integer;
    begin
      for x := 1 to 8 do
        for y := 1 to 8 do
        begin
          result[x, y].nature := nothing;
          result[x, y].color := none;
        end;
    end;
     
    function positionToText(aPosition: tPosition): string;
    var
      x, y: integer;
    begin
      result := '';
      for y := 8 downto 1 do
      begin
        for x := 1 to 8 do
          if (x + y) mod 2 = 0 then
            result := result + ' '
          else
            //result := result + '/';
            result := result + '+';
          result := result + #10;
      end;
    end;
     
    var
      p: tPosition;
      s: string;
      f: textFormat;
      t: textField;
      e: tEditBox;
     
    procedure tEditBox.onKeyDown;
    begin
      if Key.getAscii = 13 then
      begin
        //t.text := e.text;
        t.text := self.text;
        {
        if IsValidEPD(self.text) then
          t.text := EPDToText(self.text);
        }
      end;
    end;
     
    begin
      p := stdPosition;
      s := positionToText(p);
     
      //f := textFormat.Create('montreal', 48);
      f := textFormat.Create('alfonso', 48);
      f.color := 0;
      t := textField.Create(nil, '', 0, 0, 0, stage.width, 484);
      with t do
      begin
        embedFonts := true;
        SetNewTextFormat(f);
        text := s;
      end;
     
      e := tEditBox.Create(nil, 'input', 1, 0, 484, stage.width, 30);
      e.type := 'input';
      Selection.setFocus(e);
      Key.addListener(e);
    end.
    J'aimerais bien avoir des conseils pour l'organisation du code (la déclaration des objets, des méthodes, etc.), histoire de partir sur une bonne base et de faire quelque chose de joli.

    Je pense utiliser pour ce projet la police Chess Montreal (pièces jointes), qui est gratuite mais que l'auteur ne donne que sur demande. Comme FlashPascal permet d'utiliser une police intégrée, ça tombe bien : je n'aurais pas besoin de distribuer la police avec le programme. En revanche, pour les exemples de cette discussion, j'utiliserai la police Chess Alfonso-X, qui peut être librement téléchargée .

    Elle est drôlement belle, cette police Chess Montreal, non ?

    Au fait, une mise à jour de la bibliothèque FlashCL est-elle envisagée ? Elle est déjà très bien comme elle est, mais il manque le type Bouton.
    Images attachées Images attachées  
    Fichiers attachés Fichiers attachés

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

Discussions similaires

  1. Réponses: 4
    Dernier message: 05/07/2015, 10h51
  2. Réponses: 7
    Dernier message: 07/11/2014, 21h21
  3. Réponses: 1
    Dernier message: 12/03/2009, 08h54
  4. [VC++ 6] Boutons permettant d'afficher une form
    Par cooladn dans le forum MFC
    Réponses: 3
    Dernier message: 09/12/2004, 16h17
  5. Programme permettant de créer ses propres paquets TCP/UDP
    Par mat087 dans le forum Développement
    Réponses: 6
    Dernier message: 21/05/2004, 21h42

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