Autor Beitrag
Fighter#1
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 787

Win XP, Ubuntu 8.04
Turbo Delphi 2006, Delphi 2005 Pe, Delphi 5 Pe, Netbeans 6.1, Eclipse, Microsoft VisualC#, Dev C++, PHP, HTML, CSS
BeitragVerfasst: Di 28.03.06 18:06 
Hallo,
ich hatte das Ziel ein keines Programm zu schreiben bei dem kleine Shapes sich auf einem Feld herumbewegen und wenn sie in der Nähe eines bestimmten Feldes sind dort hin zu 'gehen'.
Das klappt alles etwa so wie ich es mir vorgestellt habe, nur nach einiger Zeit verschwinden die Bubbles ( Shapes ) nach unten und das Programm stürtzt ab.
Ich habe keine Ahnung woran das liegt und deshalt stell ich das Programm in diese Sparte.
Ich weiß das man einiges hätte besser lösen können, aber könnt ihr mir bitte sagen was da nicht stimmt/ zum Abbruch führt.

Hier Der Code:
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:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
unit simu;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    Shape1: TShape;
    Shape2: TShape;
    Shape3: TShape;
    Shape4: TShape;
    Shape5: TShape;
    Shape6: TShape;
    Shape7: TShape;
    Shape8: TShape;
    Shape9: TShape;
    Shape10: TShape;
    Timer1: TTimer;
    Timer2: TTimer;
    Ziel: TShape;
    Timer3: TTimer;
    Label1: TLabel;
    Label2: TLabel;
    Button2: TButton;
    procedure Button2Click(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Timer2Timer(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Timer3Timer(Sender: TObject);
  private
  Richtungx:Array [1..10] of Integer;
  Richtungy:Array [1..10] of Integer;
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}
function Zufall(max:Integer):Integer;
begin
If Random(3) = 1 Then
result:=Random(max)*-1
else
result:=Random(max);

end;



procedure TForm1.Timer1Timer(Sender: TObject);
var i : Integer;

begin
Randomize;
  For i := 1 To 10 do begin
  With FindComponent('Shape'+IntToStr(i)) as TShape do begin
  // Im Rahmen bleiben
    While Left <= 50 do begin
    Left:=Left+Zufall(3);
    end ;
    While Left >= Form1.Width -50 do begin
    Left:=Left+Zufall(3);
    end;
    While Top <= 50 do begin
    Top := TOp +Zufall(3);
    end;
    While Top >= Form1.Height -50 do begin
    Top := Top +Zufall(3);
    end;
  //Rahmen fertig

          Left:=Left+Richtungx[i];
          Top:=Top+Richtungy[i];

  if Top <= Ziel.Top +50 Then begin
  If Top >= Ziel.Top -50 Then begin
  If Left <= Ziel.Left +50 Then begin
  If Left >= Ziel.Left - 50 Then begin
  Form1.Refresh;
          Left:=Left+Richtungx[i];
          Top:=Top+Richtungy[i];
  While Richtungx[i]>=5 do begin
  Richtungx[i]:=(Ziel.Left+15)div(Left+5);
  Richtungy[i]:=Richtungx[i]*((Ziel.Top+15 )div(Ziel.Left+15));
  end;
 {
 Form1.Canvas.Pen.Color:=clBlue;
 Form1.Canvas.MoveTo(Left+5,Top+5);
Form1.Canvas.LineTo(Ziel.Left+15,Ziel.Top+15);
}

  end;
  end;
  end;
  end;


  if Top >= Ziel.Top Then begin
  If Top <= Ziel.Top +Ziel.height Then begin
  If Left >= Ziel.Left Then begin
  If Left <= Ziel.Left + Ziel.Width Then begin
  Visible:=False;

  end;
  end;
  end;
  end;

end;
end;

end;

procedure TForm1.Button1Click(Sender: TObject);
var i : Integer;

begin
Randomize;
For i := 1 To 10 do begin
With FindComponent('Shape'+IntToStr(i)) as TShape do begin
Brush.Color:=Random(clYellow);
Randomize;
end;
end;


end;

procedure TForm1.Timer2Timer(Sender: TObject);
var i : Integer;
begin

Randomize;
For i := 1 To 10 do begin
With FindComponent('Shape'+IntToStr(i)) as TShape do begin
Richtungx[i]:=Zufall(3);
Richtungy[i]:=Zufall(3);
end;
end;
end;

procedure TForm1.FormCreate(Sender: TObject);
var i : Integer;
begin
Timer1.Enabled:=false;
Timer2.Enabled:=false;
Timer3.Enabled:=false;
ShowMessage('Es ist das Ziel eines jeden Bubbles ins gelbe Ziel zu gelangen');
Randomize;
Application.ProcessMessages;
Button1.Click;
 For i := 1 To 10 do begin
    With FindComponent('Shape'+IntToStr(i)) as TShape do begin
      Visible:=False;
    end;
    end;

end;

procedure TForm1.Timer3Timer(Sender: TObject);
var i : Integer;
begin
Form1.Refresh;
 Label1.Caption:='0';
  For i := 1 To 10 do begin
  With FindComponent('Shape'+IntToStr(i)) as TShape do begin
    If visible=False Then begin
      Label1.caption:=IntToStr(StrToInt(Label1.Caption)+1  )
    end;
  end;
  end;
end;

procedure TForm1.Button2Click(Sender: TObject);
var i : Integer;
begin
Timer1.Enabled:=True;
Timer2.Enabled:=True;
Timer3.Enabled:=True;
Ziel.Visible:=True;
 For i := 1 To 10 do begin
With FindComponent('Shape'+IntToStr(i)) as TShape do begin
Visible:=True;
end;
end;

end;

end.

_________________
Wer andere beherrscht ist stark,
wer sich selbst beherrscht ist mächtig. Lao Tse