Autor Beitrag
MH1987
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 98



BeitragVerfasst: Sa 29.04.06 15:22 
Ich möchte gern ein Sudoku programm schreiben:

nun habe ich ein problem:

für jedes feld habe ich ein object ertellt, so dass jedes feld alle zahlen enthält (von 1 bis 9)

ich möchte nun aber das wenn man zB in einem Feld die 2 anklickt dass diese groß erscheint. Ich weiß aber nicht wie ich die onclick function anwenden soll. wie ich die 2 groß erscheinen lassen soll, das weiß ich schon, aber eben net wie ich das auslösen soll.

Kann mir jemand weiterhelfen?


(hab noch die externe Datei als anhang dazu gestellt)

ausblenden volle Höhe Delphi-Quelltext
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:
unit sudoku;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    procedure FormKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure FormActivate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

  TFeld = object
            feld: array [1..3,1..3] of TLabel;
            sichtbar: TLabel;
            hintergrund: TLabel;
            constructor init(pX,pY: integer);
            constructor erkenne;
          end;



var
  Form1: TForm1;

implementation


constructor TFeld.init(pX,pY: integer);
var i,j: integer;
begin
  hintergrund:= TLabel.Create(Form1);
  hintergrund.Parent:= Form1;
  hintergrund.Left:= pX;
  hintergrund.Top:= pY;
  hintergrund.Width:= 56;
  hintergrund.Height:= 56;
  hintergrund.Color:= clred;

  sichtbar:= TLabel.Create(Form1);
  sichtbar.Parent:= Form1;
  sichtbar.Left:= pX+2;
  sichtbar.Top:= pY+2;
  sichtbar.Width:= 52;
  sichtbar.Height:= 52;
  sichtbar.Color:= clSilver;
  sichtbar.Alignment:= taCenter;
  sichtbar.AutoSize:= false;
  sichtbar.Font.Color:= clblue;
  sichtbar.Font.Size:= 30;
  sichtbar.Visible:= false;
  for i:= 1 to 3 do
    begin
      for j:= 1 to 3 do
        begin
          feld[i,j]:= TLabel.Create(Form1);
          feld[i,j].Parent:= Form1;
          feld[i,j].Color:= clSilver;
          feld[i,j].Width:= 16;
          feld[i,j].Height:= 16;
          feld[i,j].Left:= pX + i*18 - 18 + 2;
          feld[i,j].Top:= pY + j*18 - 18 + 2;
          feld[i,j].AutoSize:= false;
          feld[i,j].Alignment:= taCenter;
          feld[i,j].Font.Color:= clgray;
          feld[i,j].Caption:= IntToStr(j*3 - 3 + i);
        end;
    end;
end;

{$R *.dfm}

var matrix: array [1..3,1..3] of array [1..3,1..3] of TFeld;

procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if key = 27 then self.Close;
end;

procedure TForm1.FormActivate(Sender: TObject);
var i,j,k,l: integer;
    neu: TLabel;
begin
  for i:= 1 to 3 do
    for j:= 1 to 3 do
      for k:= 1 to 3 do
        for l:= 1 to 3 do
          matrix[i,j][k,l].init(i*190+k*60-230,j*190+l*60-230);
end;



procedure TForm1.Button1Click(Sender: TObject);
var F: textfile;
    s: string;
    i,j,k,l: integer;
begin
  assignFile(f,'maps.txt');
  reset(f);

  for j:= 1 to 3 do
    begin
      for l:= 1 to 3 do
        begin
          readln(f,s);
          for i:= 1 to 3 do
            begin
              for k:= 1 to 3 do
                begin
                  if s[i*3-3+k] <> '0'
                  then
                    begin
                      matrix[i,j][k,l].sichtbar.BringToFront;
                      matrix[i,j][k,l].sichtbar.Visible:= true;
                      matrix[i,j][k,l].sichtbar.Caption:= s[i*3-3+k];
                      
                    end;
                end;
            end;
        end;
    end;

end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  self.Close;
end;

end.
Einloggen, um Attachments anzusehen!


Zuletzt bearbeitet von MH1987 am Sa 29.04.06 17:42, insgesamt 1-mal bearbeitet
Ferrari
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 30

Win XP
Delphi 6 Personal
BeitragVerfasst: Sa 29.04.06 16:02 
Du musst zwischen Zeile 77 und 78 OnClick:=LabelClick; schreiben
Und nach Zeile 17 musst du procedure LabelClick(Sender: TObject); schreiben;
In die Prozedur TForm1.LabelClick(Sender: TObject); schribst du dann etwa folgendes rein:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
procedure TForm1.LabelClick(Sender: TObject);
var
  i,j: byte;
begin
  for i := 1 to 9 do
  begin
   for j := 1 to 9 do
   begin
    if Sender=Feld[i,j] then Feld[i,j].Font.Size := 20;
   end;
  end;
end;


Ich hoffe das klappt.

Moderiert von user profile iconraziel: Code- durch Delphi-Tags ersetzt

_________________
Mehr als ein Hesse kann der Mensch kaum werden.
MH1987 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 98



BeitragVerfasst: Sa 29.04.06 18:52 
jo danke funzt :-)