Avis sur synthaxe de structure

Vous débutez et vous avez besoin d'aide ? N'hésitez pas à poser vos questions
Avatar de l’utilisateur
Ar-S
Messages : 9540
Inscription : dim. 09/oct./2005 16:51
Contact :

Avis sur synthaxe de structure

Message par Ar-S »

Salut,
Je suis sur un projet qui n'a pour autre but que de me divertir.. A vrai dire je ne sais même pas jusqu'où j'irai niveau interaction mais j'ai envie de faire un genre de Bot (robot) visuel permettant une interaction avec l'utilisateur. Ce bot (OGMA) sera représenté sous forme d'un simple smiley pouvant changer d'état selon le comportement de l'utilisateur. Un genre de tamagoshi sauf qu'on a pas à lui filer à bouffer pour pas qu'il ne crève. Mieux, un genre "d'assistant" virtuel.
Bref, vous devez donc avoir compris (je trouve ce style de programme passionnant à développer).

Je vais donc essayer de faire les choses proprement en utilisant les structures.
Je vous demande donc si la syntaxe de mes 1eres lignes vous parait correcte et judicieuse ou s'il y a un moyen plus "propre" d'agencer la chose.
Merci

Code : Tout sélectionner

; OGMA by Ar-S

Global Dodo=0
Global Neutre=1
Global Content=2
Global Triste=3
Global Colere=4

Structure Tete
  Couleur.l
  PosX.l
  PosY.l
  TailleX.l
  TailleY.l
  Rayon.l
EndStructure

Structure Yeux
  Couleur.l
  PosX.l
  PosY.l
  TailleX.l
  TailleY.l
  Rayon.l
EndStructure

Structure Bouche
  Couleur.l
  PosX.l
  PosY.l
  TailleX.l
  TailleY.l
  Rayon.l
EndStructure



Dim Ogma.Tete(4) ; 0 1 2 3 4 donc 5 apparences possibles 

;- TETE - DODO
Ogma(Dodo)\Couleur=RGB(255,255,20)



;- TETE - NEUTRE
Ogma(Neutre)\Couleur=RGB(255,255,0)



;- TETE - CONTENT
Ogma(Content)\Couleur=RGB(0,255,0)



;- TETE - TRISTE
Ogma(Triste)\Couleur=RGB(128,142,141)



;- TETE - COLERE
Ogma(Colere)\Couleur=RGB(255,0,0)






~~~~Règles du forum ~~~~
⋅.˳˳.⋅ॱ˙˙ॱ⋅.˳Ar-S ˳.⋅ॱ˙˙ॱ⋅.˳˳.⋅
W11x64 PB 6.x
Section HORS SUJET : ICI
LDV MULTIMEDIA : Dépannage informatique & mes Logiciels PB
UPLOAD D'IMAGES : Uploader des images de vos logiciels
comtois
Messages : 5186
Inscription : mer. 21/janv./2004 17:48
Contact :

Re: Avis sur synthaxe de structure

Message par comtois »

c'est une question de goût personnel, mais je ferais plutôt comme ça

Code : Tout sélectionner

Enumeration
#Dodo
#Neutre
#Content 
#Triste 
#Colere
EndEnumeration

Structure Propriete
  Couleur.l 
	PosX.l 
	PosY.l 
	TailleX.l 
	TailleY.l 
	Rayon.l 
EndStructure

Structure tamagoshi 
  Tete.Propriete[5]
  Yeux.Propriete
  Bouche.Propriete
EndStructure

Define toto.tamagoshi

toto\Tete[#Dodo]\Couleur = RGB(255,255,20)
Et pas de variables globales, j'évite.
http://purebasic.developpez.com/
Je ne réponds à aucune question technique en PV, utilisez le forum, il est fait pour ça, et la réponse peut profiter à tous.
Avatar de l’utilisateur
Ar-S
Messages : 9540
Inscription : dim. 09/oct./2005 16:51
Contact :

Re: Avis sur synthaxe de structure

Message par Ar-S »

Merci Comtois pour ton avis et pour cette orientation, c'est clair.
Je vais me rediriger dans ce sens. Je suis cependant à l’écoute d'autres avis.
~~~~Règles du forum ~~~~
⋅.˳˳.⋅ॱ˙˙ॱ⋅.˳Ar-S ˳.⋅ॱ˙˙ॱ⋅.˳˳.⋅
W11x64 PB 6.x
Section HORS SUJET : ICI
LDV MULTIMEDIA : Dépannage informatique & mes Logiciels PB
UPLOAD D'IMAGES : Uploader des images de vos logiciels
G-Rom
Messages : 3641
Inscription : dim. 10/janv./2010 5:29

Re: Avis sur synthaxe de structure

Message par G-Rom »

Je pousserais le bouchon un peu plus loin.
Structure Position
x.f
y.f
endstructure
et toutes les fonctions qui vont avec , déplacement , test basique de collisions avec un cercle , rectangle , etc...
Avec se genre de code , t'es paré à codé n'importe quoi ! ;)
Guimauve
Messages : 1015
Inscription : mer. 11/févr./2004 0:32
Localisation : Québec, Canada

Re: Avis sur synthaxe de structure

Message par Guimauve »

Primo, je ne suis pas trop sûr de comprendre le pourquoi d'avoir 3 structures différentes avec les champs identiques.
Deusio, je vois pas l'intérêt d'utiliser des variables globales pour donner un nom pour les différents indices de tableau. Les constantes sont plus appropriées pour cette tâche.

Moi je ferais un truc du genre :

Code : Tout sélectionner

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Nom du projet : Ar-S - Projet Ogma
; Nom du fichier : Ogma.pb
; Version du fichier : 1.0.0
; Programmation : En cours
; Programmé par : Guimauve
; Date : 20-06-2011
; Mise à jour : 20-06-2011
; Code PureBasic : 4.50
; Plateforme : Windows, Linux, MacOS X
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Constantes de dimensionnement <<<<<

Enumeration 
  
  #OGMA_ETAT_DODO
  #OGMA_ETAT_NEUTRE
  #OGMA_ETAT_CONTENT
  #OGMA_ETAT_TRISTE
  #OGMA_ETAT_COLERE
  
  ; AJOUTER D'AUTRE ÉTATS SI NÉCESSAIRE
  ; AVANT LA CONSTANTE #OGMA_ETAT_MAX. 
  ; CELA VA AJUSTER LA TAILLE DES TABLEAUX
  ; AUTOMATIQUEMENT.
  
  #OGMA_ETAT_MAX
  
EndEnumeration

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Déclaration des Structures <<<<<

Structure Info

  Couleur.l
  PosX.l
  PosY.l
  TailleX.l
  TailleY.l
  Rayon.l

EndStructure

Structure Ogma

  Tete.Info[#OGMA_ETAT_MAX]
  Yeux.Info[#OGMA_ETAT_MAX]
  Bouche.Info[#OGMA_ETAT_MAX]

EndStructure

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Les observateurs <<<<<

Macro GetInfoCouleur(InfoA)

  InfoA\Couleur

EndMacro

Macro GetInfoPosX(InfoA)

  InfoA\PosX

EndMacro

Macro GetInfoPosY(InfoA)

  InfoA\PosY

EndMacro

Macro GetInfoTailleX(InfoA)

  InfoA\TailleX

EndMacro

Macro GetInfoTailleY(InfoA)

  InfoA\TailleY

EndMacro

Macro GetInfoRayon(InfoA)

  InfoA\Rayon

EndMacro

Macro GetOgmaTete(OgmaA, EtatID)

  OgmaA\Tete[EtatID]

EndMacro

Macro GetOgmaYeux(OgmaA, EtatID)

  OgmaA\Yeux[EtatID]

EndMacro

Macro GetOgmaBouche(OgmaA, EtatID)

  OgmaA\Bouche[EtatID]

EndMacro

; <<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Les mutateurs <<<<<

Macro SetInfoCouleur(InfoA, P_Couleur)

  GetInfoCouleur(InfoA) = P_Couleur

EndMacro

Macro SetInfoPosX(InfoA, P_PosX)

  GetInfoPosX(InfoA) = P_PosX

EndMacro

Macro SetInfoPosY(InfoA, P_PosY)

  GetInfoPosY(InfoA) = P_PosY

EndMacro

Macro SetInfoTailleX(InfoA, P_TailleX)

  GetInfoTailleX(InfoA) = P_TailleX

EndMacro

Macro SetInfoTailleY(InfoA, P_TailleY)

  GetInfoTailleY(InfoA) = P_TailleY

EndMacro

Macro SetInfoRayon(InfoA, P_Rayon)

  GetInfoRayon(InfoA) = P_Rayon

EndMacro

Macro SetOgmaTete(OgmaA, EtatID, P_Tete)

  GetOgmaTete(OgmaA, EtatID) = P_Tete

EndMacro

Macro SetOgmaYeux(OgmaA, EtatID, P_Yeux)

  GetOgmaYeux(OgmaA, EtatID) = P_Yeux

EndMacro

Macro SetOgmaBouche(OgmaA, EtatID, P_Bouche)

  GetOgmaBouche(OgmaA, EtatID) = P_Bouche

EndMacro

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< L'opérateur Update <<<<<

Macro UpdateOgmaTeteInfo(OgmaA, EtatID, P_Couleur, P_PosX, P_PosY, P_TailleX, P_TailleY, P_Rayon)

  SetInfoCouleur(GetOgmaTete(OgmaA, EtatID), P_Couleur)
  SetInfoPosX(GetOgmaTete(OgmaA, EtatID), P_PosX)
  SetInfoPosY(GetOgmaTete(OgmaA, EtatID), P_PosY)
  SetInfoTailleX(GetOgmaTete(OgmaA, EtatID), P_TailleX)
  SetInfoTailleY(GetOgmaTete(OgmaA, EtatID), P_TailleY)
  SetInfoRayon(GetOgmaTete(OgmaA, EtatID), P_Rayon)

EndMacro

Macro UpdateOgmaYeuxInfo(OgmaA, EtatID, P_Couleur, P_PosX, P_PosY, P_TailleX, P_TailleY, P_Rayon)

  SetInfoCouleur(GetOgmaYeux(OgmaA, EtatID), P_Couleur)
  SetInfoPosX(GetOgmaYeux(OgmaA, EtatID), P_PosX)
  SetInfoPosY(GetOgmaYeux(OgmaA, EtatID), P_PosY)
  SetInfoTailleX(GetOgmaYeux(OgmaA, EtatID), P_TailleX)
  SetInfoTailleY(GetOgmaYeux(OgmaA, EtatID), P_TailleY)
  SetInfoRayon(GetOgmaYeux(OgmaA, EtatID), P_Rayon)

EndMacro

Macro UpdateOgmaBoucheInfo(OgmaA, EtatID, P_Couleur, P_PosX, P_PosY, P_TailleX, P_TailleY, P_Rayon)

  SetInfoCouleur(GetOgmaBouche(OgmaA, EtatID), P_Couleur)
  SetInfoPosX(GetOgmaBouche(OgmaA, EtatID), P_PosX)
  SetInfoPosY(GetOgmaBouche(OgmaA, EtatID), P_PosY)
  SetInfoTailleX(GetOgmaBouche(OgmaA, EtatID), P_TailleX)
  SetInfoTailleY(GetOgmaBouche(OgmaA, EtatID), P_TailleY)
  SetInfoRayon(GetOgmaBouche(OgmaA, EtatID), P_Rayon)

EndMacro

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Initialisation des données <<<<<

Declare.Ogma MonOgma 

UpdateOgmaTeteInfo(MonOgma, #OGMA_ETAT_DODO, RGB(255,255, 20), 25, 25, 64, 64, 32)
UpdateOgmaTeteInfo(MonOgma, #OGMA_ETAT_NEUTRE, RGB(255, 255, 000), 25, 25, 64, 64, 32)
UpdateOgmaTeteInfo(MonOgma, #OGMA_ETAT_CONTENT, RGB(255,255, 000), 25, 25, 64, 64, 32)
UpdateOgmaTeteInfo(MonOgma, #OGMA_ETAT_TRISTE, RGB(128, 142, 141), 25, 25, 64, 64, 32)
UpdateOgmaTeteInfo(MonOgma, #OGMA_ETAT_COLERE, RGB(255, 000, 000), 25, 25, 64, 64, 32)

; <<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< FIN DU FICHIER <<<<<
; <<<<<<<<<<<<<<<<<<<<<<<<<<
A+
Guimauve
Avatar de l’utilisateur
Ar-S
Messages : 9540
Inscription : dim. 09/oct./2005 16:51
Contact :

Re: Avis sur synthaxe de structure

Message par Ar-S »

Très sympa aussi Guimauve merci.
Image

Me reste à trouver le chemin qui me "parle" le plus.
~~~~Règles du forum ~~~~
⋅.˳˳.⋅ॱ˙˙ॱ⋅.˳Ar-S ˳.⋅ॱ˙˙ॱ⋅.˳˳.⋅
W11x64 PB 6.x
Section HORS SUJET : ICI
LDV MULTIMEDIA : Dépannage informatique & mes Logiciels PB
UPLOAD D'IMAGES : Uploader des images de vos logiciels
Répondre