![]() |
Re: Ratezahl 2 Delphi (leicht)
Was klappt daran nicht?
PS: Mach mal Random(100) + 1. Ich glaub mit Random(100) geht das nur von 0 bis 99 :D |
Re: Ratezahl 2 Delphi (leicht)
Wenn man vorher 10 Versuche gebraucht hat und die lösung nicht herausgefunden hat wird einen ja die lösung gesagt und wenn ich auf den button "Neues SPiel" drücke bleibt das das alte ergebnis dort stehen
aber das habe ich jetzt einfach hiermit gelöst Label7.Caption := '' Wenn man das Programm startet ist das Ergebnis immer 0 das sieht man wenn man das programm startet ohne auf "NEue zahl" zu drücken 10 flasche antworten gibt Wie kann man das ändern? Die Scrollbar geht bei mir nur von 0-99 |
Re: Ratezahl 2 Delphi (leicht)
Einfach bei Form1.Create die zeile randomize; einfügen, dann ist es am anfang immer eine andere zahl :)
|
Re: Ratezahl 2 Delphi (leicht)
Das steht weiter oben auch schon das habe ich auch schon getan... es wird auch eine andere Zahl angezeigt aber trotzdem wenn man nichts macht auser falsche antworten am anfang geben oder auch die richtige sie wird als flasch angezeigt da 0 die richtige ist und zwar immer
|
Re: Ratezahl 2 Delphi (leicht)
Könntest du vielleicht nochmal den Source-Code hier rein schreiben? (abre nur die Prozeduren, den Rest brauch ich nicht ^^)
|
Re: Ratezahl 2 Delphi (leicht)
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 end; if StrToInt (EEingabe.Text) < Zahl then begin PAntwort.Caption := 'zu klein'; PAntwort.Color := clred 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; 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. |
Re: Ratezahl 2 Delphi (leicht)
An welcher Stelle des Codes rufst du denn eigentlich die prozeduren Neuezahl, bleibHier, Vergleiche auf?
Poste doch mal den ganzen Code (aber editiere deinen vorherigen und schreibs darein.) |
Re: Ratezahl 2 Delphi (leicht)
Ah, jetzt seh ichs, ist ja logisch. Es liegt daran das du im OnCreate der Variable Zahl keinen Wert zuweist, somit ist sie für das Programm immer noch eine 0
Also einfach zahl := Random(100) und die sache hat sich gegessen. |
Re: Ratezahl 2 Delphi (leicht)
alles klar danke hab jetzt bei oncreate noch
Delphi-Quellcode:
hinzugefügt.
Zahl := Random(100);
ScrollBar.Position := Zahl Jetzt brauch ich noch 2.Zur besseren unterstüzung beim raten soll auf einem weiteren panel die botschaft kalt warm heiß usw erscheinen je nachdem wie nahe man an der zahl dran ist. Dazu habe ich folgendes bekommen: Du könntest die 'richtige Zahl' von der geratenen abziehen und dann den Betrag von dem Ergebnis nehmen (ich glaube, dass ist bei delphi die Funktion abs().) Dann hast du den Abstand der beiden Zahlen und du kannst mit Hilfe von if und else entscheiden, ob es warm kalt oder heiß ist. (Das geht etwas eleganter, aber case wirst du wohl noch nicht gehabt haben). muss ich mal schauen wie ich das hinbekomm für weitere tipps bin ich imemr dankbar |
Re: Ratezahl 2 Delphi (leicht)
Ist eigentlich auch nicht sonderlich schwer. So als kleines Bsp:
Delphi-Quellcode:
Dürfte verständlich und selbsterklärend sein ;)
if (abs(zahl - eingabe) > 0) and (abs(zahl - eingabe) < 5) then Panel.caption := 'Du bist ganz nah dran!' else
if (abs(zahl - eingabe) > 5) and (abs(zahl - eingabe) < 15) then es Panel.captin := 'es wird wärmer...' else ... PS.: KA ob das mit abs() stimmt, ich habs einfach mal vorausgesetzt :) PPS: Wieso weißt du der Scrollbar.Position die Zufallszahl zu? Da sieht man doch was es in etwa für ne Zahl ist... |
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:
an welcher stelle muss dieser schnipel rein`?
if (abs(zahl - StrToInt (Eeingabe.Text)) > 0) and (abs(zahl - StrToInt (Eeingabe.Text)) < 5) then Panel1.caption := 'Du bist ganz nah dran!' else
|
Re: Ratezahl 2 Delphi (leicht)
Zitat:
|
Re: Ratezahl 2 Delphi (leicht)
Ich habe dieses codeschnipsel eingefügt
Delphi-Quellcode:
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
if (abs(zahl - StrToInt (Eeingabe.Text)) > 0) and (abs(zahl - StrToInt (Eeingabe.Text)) < 5) then Panel1.caption := 'Du bist ganz nah dran!' else
|
Re: Ratezahl 2 Delphi (leicht)
Das muss hier rein:
Delphi-Quellcode:
if StrToInt(EEingabe.Text) > Zahl then..
if StrToInt(EEingabe.Text) < Zahl then... |
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 |
Re: Ratezahl 2 Delphi (leicht)
Ich würde wie beschrieben mit Bereichen arbeiten.
|
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:
den nächsten post :
if (abs(zahl - StrToInt (Eeingabe.Text)) > 0) and (abs(zahl - StrToInt (Eeingabe.Text)) < 5) then Panel1.caption := 'Du bist ganz nah dran!' else
Das muss hier rein: Delphi-Quellcode: markieren if StrToInt(EEingabe.Text) > Zahl then.. if StrToInt(EEingabe.Text) < Zahl then... hab ich nicht verstanden |
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:
PS: Wieso wurde der Code nicht richtig formatiert? :gruebel:
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; PPS: schon besser :D |
Re: Ratezahl 2 Delphi (leicht)
Vielleicht solltest du den Leuten im DP sagen, dass du die Frage auch hier gestellt hast
![]() |
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. |
Re: Ratezahl 2 Delphi (leicht)
So könnte es aussehen. recht übersichtlich...
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.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; |
Alle Zeitangaben in WEZ +1. Es ist jetzt 01:43 Uhr. |
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