Autor Beitrag
Hendi48
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 271



BeitragVerfasst: Do 05.07.07 19:30 
Hi,
also ich schreibe grad ein programm das eine Zufallszahl zwischen 0-9 generiert die man dann in ein Edit eingeben soll. Unter dem Edit is natürlich ein bestätigen Button ;)
Man hat insgesamt 3 Versuche dann geht das Prog zu.
Dann hab ich das so gemacht und in den Button getan:
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:
var
Fertig: Boolean;
begin
if label4.Caption='3' then
begin
  label4.caption:='2';
  Fertig:=true;
  if edit1.text=label5.caption then
  begin
    showmessage('Richtig! =)');
    Close;
    //Form1.show;
  end
  else
  begin
  showmessage('Falsch! =(');
  end;
end;

if label4.caption='2' then
begin
  if not Fertig then
  begin
   label4.caption:='1';
   Fertig:=true;
    if edit1.text=label5.caption then
  begin
    showmessage('Richtig! =)');
    Close;
    //Form1.show;
  end
  else
  begin
  showmessage('Falsch! =(');
  end;
 end;
end;

if label4.caption='1' then
begin
if not Fertig then
  begin
   label4.caption:='0';
   Fertig:=true;
    if edit1.text=label5.caption then
  begin
    showmessage('Richtig! =)');
    Close;
    //Form1.show;
  end
  else
  begin
  showmessage('Falsch! =(');
  showmessage('Versuch es nochmal! ;)');
  Application.Terminate;
  end;
 end;
end;
fertig:=false;
end;

Es funzt auch nur wenn es falsch war und ich nochmal drauf drück passiert nix (liegt an dem "Fertig") -
könnt ihr mir sagen was ich ändern muss? :D
Blackheart666
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2195

XP
D3Prof, D6Pers.
BeitragVerfasst: Do 05.07.07 20:51 
Du könntest das auch etwas einfacher machen in etwa so
ausblenden 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:
var
  Form1: TForm1;
  Zufall,Zaehler:Integer;
implementation

{$R *.dfm}

procedure TForm1.ZufallszahlClick(Sender: TObject);
begin
  Zufall:=Random(10); //Zufallszahl
  Button1.Enabled:=False;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Randomize;
end;

procedure TForm1.BestaetigenClick(Sender: TObject);
begin
  Inc(Zaehler); //Mitzählen
  if Zaehler = 10 then Close; //Wenn drei erreicht Form schließen
  If StrToInt(Edit1.Text) = Zufall then // Zahl Gleich oder Nicht
  Showmessage('Richtig Geraten !')
  else
  Showmessage('Das War Wohl Nix !!!')
end;

vieleicht kannst Du damit was anfangen.

_________________
Blackheart666
Der Irrsinn ist bei Einzelnen etwas Seltenes, - aber bei Gruppen, Parteien, Völkern, Zeiten die Regel. (Friedrich Nietzsche)
Hendi48 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 271



BeitragVerfasst: Do 05.07.07 21:20 
hm jetz gehts:
ausblenden Delphi-Quelltext
1:
2:
3:
public
 fertig: boolean;
 zähla: integer;

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:
procedure TForm2.SpeedButton1Click(Sender: TObject);
begin
if Zähla=3 then
begin
  Zähla:=2;
  Fertig:=true;
  if edit1.text=label5.caption then
  begin
    showmessage('Richtig! =)');
    Form1.show;
    Form2.visible:=false;
  end
  else
  begin
  showmessage('Falsch! =(');
  edit1.Clear;
  edit1.SetFocus;
  end;
 end;

if Zähla=2 then
begin
 if not fertig then
 begin
    zähla:=1;
    fertig:=true;
    if edit1.text=label5.caption then
  begin
    showmessage('Richtig! =)');
    Form1.show;
    Form2.visible:=false;
  end
  else
  begin
  showmessage('Falsch! =(');
  edit1.Clear;
  edit1.SetFocus;
  end;
 end;
end;

if Zähla=1 then
begin
   if not fertig then
   begin
   Zähla:=0;
   fertig:=true;
    if edit1.text=label5.caption then
  begin
    showmessage('Richtig! =)');
    Form1.show;
    Form2.visible:=false;
  end
  else
  begin
    showmessage('Falsch! =(');
    showmessage('Versuch es nochmal! ;)');
    Application.Terminate;
  end;
 end;
end;
Fertig:=false;
end;