Delphi-PRAXiS
Seite 6 von 7   « Erste     456 7      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Ratezahl 2 Delphi (leicht) (https://www.delphipraxis.net/102653-ratezahl-2-delphi-leicht.html)

andiak 2. Nov 2007 11:15

Re: Ratezahl 2 Delphi (leicht)
 
Danke ich probiers mal aus mit dem abs... Das mit der Scrollbar mach ich als kleine unterstützung das man ungefähr sieht in welchem bereich die Zahl liegt... ich denke ich erhöhe den min und max bereich auf 1000

ist das so richtig ?
Delphi-Quellcode:
if (abs(zahl - StrToInt (Eeingabe.Text)) > 0) and (abs(zahl - StrToInt (Eeingabe.Text)) < 5) then Panel1.caption := 'Du bist ganz nah dran!' else
an welcher stelle muss dieser schnipel rein`?

cran7 2. Nov 2007 11:18

Re: Ratezahl 2 Delphi (leicht)
 
Zitat:

Zitat von xX0815Xx
PPS: Wieso weißt du der Scrollbar.Position die Zufallszahl zu? Da sieht man doch was es in etwa für ne Zahl ist...

er will ja das man raten muss wo die scrollbar ca. is, desshalb da ne zufallszahl

andiak 2. Nov 2007 11:54

Re: Ratezahl 2 Delphi (leicht)
 
Ich habe dieses codeschnipsel eingefügt
Delphi-Quellcode:
if (abs(zahl - StrToInt (Eeingabe.Text)) > 0) and (abs(zahl - StrToInt (Eeingabe.Text)) < 5) then Panel1.caption := 'Du bist ganz nah dran!' else
Er hat mir zwar angezeigt das ich nah drann bin und so aber ich könnte die richtige zahln icht mehr finden selbst wenn es wirklich die 28 war hat er mir beim tippen gesagt das sie falsch wäre... das bedeutet wohl ich habe ihn an der falschen stelle eingefügt

Aurelius 2. Nov 2007 12:01

Re: Ratezahl 2 Delphi (leicht)
 
Das muss hier rein:
Delphi-Quellcode:
if StrToInt(EEingabe.Text) > Zahl then..
if StrToInt(EEingabe.Text) < Zahl then...

andiak 2. Nov 2007 12:05

Re: Ratezahl 2 Delphi (leicht)
 
das versteh ich jetzt nicht :/ was muss hier rein?... ich hab grad volgenden code im internet gefunden kann ich den nicht verwenden

Delphi-Quellcode:
if StrToInt(EEingabe.Text) = Zahl+12 then
    begin
     Panel1.Caption := 'erfroren';
     Panel1.Color := clblue ;
     if StrToInt(EEingabe.Text) = Zahl+10 then
       begin
        Panel1.Caption := 'kalt';
        Panel1.Color := clblue ;
     if StrToInt(EEingabe.Text) = Zahl+8 then
       begin
        Panel1.Caption := 'kuehl';
        Panel1.Color := clblue ;
     if StrToInt(EEingabe.Text) = Zahl+6 then
       begin
        Panel1.Caption := 'lau warm';
        Panel1.Color := clred ;
     if StrToInt(EEingabe.Text) = Zahl+4 then
       begin
        Panel1.Caption := 'warm';
        Panel1.Color := clred ;
     if StrToInt(EEingabe.Text) = Zahl+3 then
       begin
        Panel1.Caption := 'waermer';
        Panel1.Color := clred;
     if StrToInt(EEingabe.Text) = Zahl+1 then
       begin
        Panel1.Caption := 'heiß';
        Panel1.Color := clred ;
    end
  else
     if StrToInt(EEingabe.Text) = Zahl-12 then
       begin
        Panel1.Caption := 'erfroren';
        Panel1.Color := clblue ;
     if StrToInt(EEingabe.Text) = Zahl-10 then
       begin
        Panel1.Caption := 'kalt';
        Panel1.Color := clblue ;
     if StrToInt(EEingabe.Text) = Zahl-8 then
       begin
        Panel1.Caption := 'kuehl';
        Panel1.Color := clblue ;
     if StrToInt(EEingabe.Text) = Zahl-6 then
       begin
        Panel1.Caption := 'lau warm';
        Panel1.Color := clred ;
     if StrToInt(EEingabe.Text) = Zahl-4 then
       begin
        Panel1.Caption := 'warm';
        Panel1.Color := clred ;
     if StrToInt(EEingabe.Text) = Zahl-3 then
       begin
        Panel1.Caption := 'waermer';
        Panel1.Color := clred;
     if StrToInt(EEingabe.Text) = Zahl-1 then
       begin
        Panel1.Caption := 'heiß';
        Panel1.Color := clred ;
    end;
  if StrToInt(EEingabe.Text) = Zahl then
    begin
      Panel1.Caption := 'und verbrannt';
      Panel1.Color := clred
    end

mkinzler 2. Nov 2007 12:08

Re: Ratezahl 2 Delphi (leicht)
 
Ich würde wie beschrieben mit Bereichen arbeiten.

andiak 2. Nov 2007 12:11

Re: Ratezahl 2 Delphi (leicht)
 
hm ok ich probiere es aber da habe ich noch nicht ganz durchgesehen das versteh ichn och nicht
wo muss ich den diesen hier einfügen damit er richtig funktionier
Delphi-Quellcode:
if (abs(zahl - StrToInt (Eeingabe.Text)) > 0) and (abs(zahl - StrToInt (Eeingabe.Text)) < 5) then Panel1.caption := 'Du bist ganz nah dran!' else
den nächsten post :
Das muss hier rein:
Delphi-Quellcode: markieren
if StrToInt(EEingabe.Text) > Zahl then..
if StrToInt(EEingabe.Text) < Zahl then...

hab ich nicht verstanden

Aurelius 2. Nov 2007 12:16

Re: Ratezahl 2 Delphi (leicht)
 
Hör auf mkinzler ;) Mit den Bereichen ist das besser und auch einfacher zu implementieren.

So ungefähr könnte die Abfrgae aussehen:
Delphi-Quellcode:
procedure TForm1.Vergleiche(Sender: TObject);
begin
count := count + 1;
Label4.Caption := IntToStr( count);
if count = 10 then
begin
  Label4.Caption := 'Maximale Rateanzahl erreicht, die Lösung ist:     , Neue runde?';
  BRaten.Enabled := false ;
  Label7.Caption := IntToStr ( Zahl);
end;

if StrToInt(EEingabe.Text) > Zahl then
begin
 PAntwort.Color := clred;
 if (abs(zahl - eingabe) > 0) and (abs(zahl - eingabe) < 5) then PAntwort.caption := 'Du bist ganz nah dran, aber die Zahl ist zu groß!' else
 if (abs(zahl - eingabe) > 5) and (abs(zahl - eingabe) < 15) then es PAntwort.captin := 'Es wird wärmer, aber noch ist die Zahl zu groß...' else
 ...
end;

if StrToInt (EEingabe.Text) < Zahl then
begin
 PAntwort.Color := clred;
 if (abs(zahl - eingabe) > 0) and (abs(zahl - eingabe) < 5) then PAntwort.caption := 'Du bist ganz nah dran, aber die Zahl ist noch etwas zu klein!' else
 if (abs(zahl - eingabe) > 5) and (abs(zahl - eingabe) < 15) then es PAntwort.caption := 'Es wird wärmer, aber noch ist die Zahl zu klein...' else
 ...
end;

if StrToInt (EEingabe.Text) = Zahl then
begin
 PAntwort.Caption := 'Richtig!';
 PAntwort.Color := cllime     ;
 Label6.Caption := 'Ihr habt gewonnen!!! Probiert es gleich nochmal'
end;
PS: Wieso wurde der Code nicht richtig formatiert? :gruebel:
PPS: schon besser :D

mkinzler 2. Nov 2007 12:33

Re: Ratezahl 2 Delphi (leicht)
 
Vielleicht solltest du den Leuten im DP sagen, dass du die Frage auch hier gestellt hast
http://www.delphi-forum.de/viewtopic.php?t=77869

andiak 2. Nov 2007 12:38

Re: Ratezahl 2 Delphi (leicht)
 
hm oki mach ich das nächste mal ich habe erst dort dann hier gepostet und da hier zu erst geholfen wurde bin ich hier geblieben und dort net mehr nachgeschaut....
ich glube ich bin jetzt soweit fertig... ich kann ja nochmall den kommpletten code posten kann mir jemand vieleicht nen tipp geben wie man den jetzt noch schön formatieren kann? Also nur Einrückungen z.b. alle if´s, 1Tabstop oder so

Delphi-Quellcode:
unit UZahl;

interface

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

type
  TForm1 = class(TForm)
    EEingabe: TEdit;
    BNeu: TButton;
    BRaten: TButton;
    PAntwort: TPanel;
    ScrollBar: TScrollBar;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Button1: TButton;
    Label7: TLabel;
    Label6: TLabel;
    procedure NeueZahl(Sender: TObject);
    procedure Vergleiche(Sender: TObject);
    procedure BleibHier(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);

  private
    { Private-Deklarationen }
    Zahl: Integer;
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
  count : integer;


implementation

{$R *.DFM}

procedure TForm1.NeueZahl(Sender: TObject);
begin
  Zahl := Random(100);
  ScrollBar.Position := Zahl
end;

procedure TForm1.BleibHier(Sender: TObject);
begin
  ScrollBar.Position := Zahl
end;

procedure TForm1.Vergleiche(Sender: TObject);
begin
count := count + 1;
Label4.Caption := IntToStr( count);
if count = 10 then
begin
  Label4.Caption := 'Maximale Rateanzahl erreicht, die Lösung ist:     , Neue runde?';
  BRaten.Enabled := false ;
  Label7.Caption := IntToStr ( Zahl);
    end;

  if StrToInt(EEingabe.Text) > Zahl then
begin
     PAntwort.Caption := 'zu groß' ;
    PAntwort.Color := clred   ;
    if (abs(zahl - StrtoInt (Eeingabe.Text)) > 0) and (abs(zahl - StrtoInt (Eeingabe.Text)) < 5) then PAntwort.caption := 'Du bist ganz nah dran, aber die Zahl ist zu groß!' else
if (abs(zahl - StrtoInt (Eeingabe.Text)) > 5) and (abs(zahl - StrtoInt (Eeingabe.Text)) < 15) then PAntwort.caption := 'Es wird wärmer, aber noch ist die Zahl zu groß...'
end;
if StrToInt (EEingabe.Text) < Zahl then
begin
     PAntwort.Caption := 'Zu klein' ;
    PAntwort.Color := clred  ;
    if (abs(zahl - StrtoInt (Eeingabe.Text)) > 0) and (abs(zahl - StrtoInt (Eeingabe.Text)) < 5) then PAntwort.caption := 'Du bist ganz nah dran, aber die Zahl ist noch etwas zu klein!' else
if (abs(zahl - StrtoInt (Eeingabe.Text)) > 5) and (abs(zahl - StrtoInt (Eeingabe.Text)) < 15) then PAntwort.caption := 'Es wird wärmer, aber noch ist die Zahl zu klein...'
end;
if StrToInt (EEingabe.Text) = Zahl then
begin
    PAntwort.Caption := 'Richtig!';
    PAntwort.Color := cllime     ;
    Label6.Caption := 'Ihr habt gewonnen!!! Probiert es gleich nochmal'
end;


end;

procedure TForm1.FormCreate(Sender: TObject);
begin
count := 0;
Randomize;
Zahl := Random(100);
  ScrollBar.Position := Zahl

end;

procedure TForm1.Button1Click(Sender: TObject);
begin
count := 0;
BRaten.Enabled := true ;
Label4.Caption := '' ;
Zahl := Random(100);
  ScrollBar.Position := Zahl    ;
  Label7.Caption := ''     ;
  Label6.Caption := ''

end;

end.


Alle Zeitangaben in WEZ +1. Es ist jetzt 16:30 Uhr.
Seite 6 von 7   « Erste     456 7      

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz