Télécharger le zip
SalutVoici quelques remarques :1- N'inclus pas les fichiers '.~dfm' '.~pas' et '.~dpr'. Ce sont des fichiers de sauvegarde qui ne servent à rien dans un source distribué.2- NOMME TES COMPOSANTS !!! Label1, Label2... ça fait brouillon et on ne comprend rien !3- 'New Party' en Anglais ne signifie pas 'Nouvelle partie', mais 'Nouvelle Fête'... Mets plutôt 'New Game' à la place...4- Pourquoi le fond est-il un TLabel ? Pourquoi pas utiliser un composant TShape ?5- A quoi servent les RadioButtons de sélection du niveau puisqu'ils sont grisés ?6- Tu peux remplacer toutes ces procédures :--------------------------------------------------------procedure TForm1.Label1Click(Sender: TObject);beginIF Label1.Caption='?' THEN BEGIN Label1.Font.Color:=clRed; Label1.Caption:='X'; Timer2.Enabled:=True; Timer1.Enabled:=True;END;end;procedure TForm1.Label2Click(Sender: TObject);beginIF Label2.Caption='?' THEN BEGIN Label2.Font.Color:=clRed; Label2.Caption:='X'; Timer2.Enabled:=True; Timer1.Enabled:=True;END;end;procedure TForm1.Label3Click(Sender: TObject);beginIF Label3.Caption='?' THEN BEGIN Label3.Font.Color:=clRed; Label3.Caption:='X'; Timer2.Enabled:=True; Timer1.Enabled:=True;END;end;procedure TForm1.Label4Click(Sender: TObject);beginIF Label4.Caption='?' THEN BEGIN Label4.Font.Color:=clRed; Label4.Caption:='X'; Timer2.Enabled:=True; Timer1.Enabled:=True;END;end;procedure TForm1.Label5Click(Sender: TObject);beginIF Label5.Caption='?' THEN BEGIN Label5.Font.Color:=clRed; Label5.Caption:='X'; Timer2.Enabled:=True; Timer1.Enabled:=True;END;end;procedure TForm1.Label6Click(Sender: TObject);beginIF Label6.Caption='?' THEN BEGIN Label6.Font.Color:=clRed; Label6.Caption:='X'; Timer2.Enabled:=True; Timer1.Enabled:=True;END;end;procedure TForm1.Label7Click(Sender: TObject);beginIF Label7.Caption='?' THEN BEGIN Label7.Font.Color:=clRed; Label7.Caption:='X'; Timer2.Enabled:=True; Timer1.Enabled:=True;END;end;procedure TForm1.Label8Click(Sender: TObject);beginIF Label8.Caption='?' THEN BEGIN Label8.Font.Color:=clRed; Label8.Caption:='X'; Timer2.Enabled:=True; Timer1.Enabled:=True;END;end;procedure TForm1.Label9Click(Sender: TObject);beginIF Label9.Caption='?' THEN BEGIN Label9.Font.Color:=clRed; Label9.Caption:='X'; Timer2.Enabled:=True; Timer1.Enabled:=True;END;end;--------------------------------------------------------par UNE SEULE : Assigne cet événement dans l'inspecteur d'objets à chacun de tes labels de Label1 à Label9 : procedure TForm1.LabelsClick(Sender: TObject); begin IF (Sender as TLabel).Caption='?' THEN BEGIN (Sender as TLabel).Font.Color:=clRed; (Sender as TLabel).Caption:='X'; Timer2.Enabled:=True; Timer1.Enabled:=True; END; end;7- Tu peux rajouter le changement de curseur dans la procédure qui modifie le Caption du label, c'est plus pratique que d'écrire des événements OnMouseMoveJe reprend la procédure au dessus (il faudra aussi modifier les procédures où l'ordinateur écrit un 'O' ) : procedure TForm1.LabelsClick(Sender: TObject); begin IF (Sender as TLabel).Caption='?' THEN BEGIN (Sender as TLabel).Font.Color:=clRed; (Sender as TLabel).Caption:='X'; (Sender as TLabel).Cursor:= crNo; Timer2.Enabled:=True; Timer1.Enabled:=True; END; end;8- Quand tu dois faire des opérations sur tous les labels, c'est possible de le regrouper dans une seule procédure : procedure OperationsSurLabels(param : string); var LabelsList : array [1..9] of Tlabel; i : integer; begin if param = 'désactiver' then for i := 1 to 9 do LabelsList[i].Enabled := false else if param = 'activer' then for i := 1 to 9 do LabelsList[i].Enabled := true else if param = 'réinit' then for i := 1 to 9 do begin LabelsList[i].Caption := '?'; LabelsList[i].Font.Color:=clSilver; end; end;Ainsi, si tu appelles la procédure OperationsSurLabels('réinit'), cela remplira tous les labels avec un '?' de couleur grise. Change la chaîne de paramètres pour effectuer les autres opérations (avec 'activer' ou 'désactiver')9- La procédure : procedure TForm1.Button1MouseMove(Sender: TObject; Shift: TShiftState; X,Y: Integer); begin Button1.Cursor:=crHandPoint; end;ne sert à rien. Il suffit d'ajuster le curseur du bouton dans l'inspecteur d'objets !10- Pour empêcher la taille de ta Form d'être modifié, ajuste sa propriété BorderStyle à bsSingle plutôt que d'utiliser l'événement OnFormResize.11- Les LABEL et GOTO sont très rarement utilisés en delphi. Le plus souvent, ils sont remplaçables par un autre code plus présentable (appels de procédures, …) 12- Je pense qu'il doit y avoir possibilité de faire plus court pour l'IA…Voilà, c'est tout ! ;)@+Nico
Désolé, je me suis trompé dans la procédure OperationsSurLabels(param : string) :Voilà la version corrigée et simplifiée : procedure OperationsSurLabels(param : string); var i : integer; begin if param = 'désactiver' then for i := 1 to 9 do (FindComponent('Case'+IntToStr(i)) as TLabel).Enabled := false else if param = 'activer' then for i := 1 to 9 do (FindComponent('Case'+IntToStr(i)) as TLabel).Enabled := true else if param = 'réinit' then for i := 1 to 9 do begin (FindComponent('Case'+IntToStr(i)) as TLabel).Caption := '?'; (FindComponent('Case'+IntToStr(i)) as TLabel).Font.Color:=clSilver; end; end;@+Nico
PS : Cette procédure ne marche que si tes Labels se nomment tous 'Case'+[leur numéro de 1 jusqu'à 9] ('Case1', 'Case2', ... 'Case9' )
Une autre possibilité : jouer avec le pavé numérique au lieu de la souris.Dans Form1 mettre KeyPreview à True, activer "onKeyUp" et saisir ce qui suit.procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);const tkey : array[97..105] of byte = (7,8,9,4,5,6,1,2,3);var tch : byte;begin tch := tkey[Key]; with (FindComponent('Label'+IntToStr(tch))) as TLabel do begin if Caption = '?' then begin Font.Color:=clRed; Caption:='X'; Timer2.Enabled:=True; Timer1.Enabled:=True; end; end;end;
C'est une bonne idée Debiars ;)@+Nico
Se souvenir du profil
Mot de passe oublié ? / Activation de compteCréer un compte