Autor |
Beitrag |
Narses
Beiträge: 10182
Erhaltene Danke: 1255
W10ent
TP3 .. D7pro .. D10.2CE
|
Verfasst: Mi 29.11.17 18:14
_________________ There are 10 types of people - those who understand binary and those who don´t.
|
|
Lena00
Beiträge: 65
Erhaltene Danke: 4
|
Verfasst: Mi 29.11.17 18:23
funktioniert ganz normal ohne Fehler wenn ich die Liste lösche und die Anweisung kommentiere
|
|
Narses
Beiträge: 10182
Erhaltene Danke: 1255
W10ent
TP3 .. D7pro .. D10.2CE
|
Verfasst: Mi 29.11.17 18:25
Gut, dann wieder eine neue Listbox auf das Formular legen, .Sorted auf TRUE stellen, den Code im Button-Handler wieder aktivieren und neu probieren. Sind die Zahlen jetzt (ja, aufsteigend) sortiert?
_________________ There are 10 types of people - those who understand binary and those who don´t.
|
|
Lena00
Beiträge: 65
Erhaltene Danke: 4
|
Verfasst: Mi 29.11.17 18:27
oh man, ich habe meinen Fehler gefunden!
Die liste nimmt ein selbst geschriebenes true im Objektinspektor nicht an, man muss es mit der Maus auswählen
Klappt jetzt!
|
|
Narses
Beiträge: 10182
Erhaltene Danke: 1255
W10ent
TP3 .. D7pro .. D10.2CE
|
Verfasst: Mi 29.11.17 18:33
Sehr schön, gut gemacht!
Dann kümmern wir uns jetzt darum, dass nicht irgendwas, sondern das Gewünschte in die Listbox eingetragen wird. Erstmal der Spielername:
Delphi-Quelltext 1:
| ListBox1.Items.Add(Format('%.04d %s', [Random(1000), EditX.Text])); |
Ich habe die neuen Text-Teile markiert. Was passiert: mit dem %s sagen wir der Format()-Funktion, dass noch ein String ausgegeben werden soll (nach der Zahl). Den String müssen wir dann noch im konstanten Parameter-Array ergänzen. Das "X" musst du natürlich noch auf dein Projekt anpassen.
Die Format()-Funktion ist also sowas wie eine Text-Schablone, in die man nachträglich noch was einfügen kann.
Testen und Rückmelden.
_________________ There are 10 types of people - those who understand binary and those who don´t.
|
|
Lena00
Beiträge: 65
Erhaltene Danke: 4
|
Verfasst: Mi 29.11.17 18:35
Alles klar, ich versuche es so
|
|
Lena00
Beiträge: 65
Erhaltene Danke: 4
|
Verfasst: Mi 29.11.17 18:42
Durch was muss ich die Random(1000) bei mir ersetzen? Ein Edit2.Text wird wohl nicht funktionieren
|
|
Narses
Beiträge: 10182
Erhaltene Danke: 1255
W10ent
TP3 .. D7pro .. D10.2CE
|
Verfasst: Mi 29.11.17 18:44
Kein Thema, mach so, wie du möchtest, ist dein Projekt, du entscheidest, was du erklären möchtest.
Oh, jetzt hast du es schon geändert.
Also, welche Version soll es sein (spielt letztlich keine Rolle)?
//Edit: du brauchst in dem Fall noch ein IntToStr() StrToInt() drum rum.
_________________ There are 10 types of people - those who understand binary and those who don´t.
Zuletzt bearbeitet von Narses am Mi 29.11.17 18:53, insgesamt 1-mal bearbeitet
|
|
Lena00
Beiträge: 65
Erhaltene Danke: 4
|
Verfasst: Mi 29.11.17 18:46
die Version nicht von dir ist für mich verständlicher/nachvollziehbarer
Funktioniert das mit dem string hier auch?
|
|
Narses
Beiträge: 10182
Erhaltene Danke: 1255
W10ent
TP3 .. D7pro .. D10.2CE
|
Verfasst: Mi 29.11.17 18:49
Also dann, Rolle rückwärts.
Dann kannst du auch gleich diese Zeile an die passende Stelle im Programm verschieben, wo der neue Highscore erfasst werden soll.
Den Button und den Handler brauchen wir noch, kannste drin lassen.
_________________ There are 10 types of people - those who understand binary and those who don´t.
|
|
Narses
Beiträge: 10182
Erhaltene Danke: 1255
W10ent
TP3 .. D7pro .. D10.2CE
|
Verfasst: Mi 29.11.17 18:51
_________________ There are 10 types of people - those who understand binary and those who don´t.
|
|
Lena00
Beiträge: 65
Erhaltene Danke: 4
|
Verfasst: Mi 29.11.17 18:59
Super hat funktioniert!!
|
|
Lena00
Beiträge: 65
Erhaltene Danke: 4
|
Verfasst: Mi 29.11.17 19:01
Endspurt: Jetzt müssen die Zahlen noch von Hoch nach Tief geordnet werden
|
|
Narses
Beiträge: 10182
Erhaltene Danke: 1255
W10ent
TP3 .. D7pro .. D10.2CE
|
Verfasst: Mi 29.11.17 19:02
Jup. Vorher noch die Begrenzung der Anzahl oder weglassen?
_________________ There are 10 types of people - those who understand binary and those who don´t.
|
|
Lena00
Beiträge: 65
Erhaltene Danke: 4
|
Verfasst: Mi 29.11.17 19:05
Würde ich mittlerweile weglassen
|
|
Narses
Beiträge: 10182
Erhaltene Danke: 1255
W10ent
TP3 .. D7pro .. D10.2CE
|
Verfasst: Mi 29.11.17 19:12
Dann also Endspurt: wie kriegt man die Liste umgedreht... Da gibt es mehrere Versionen, manche davon "eleganter" als Andere, ich schlage mal diese vor. Ist sicher nicht die beste Variante, weil die Datenhaltung in der GUI generell keine gute Idee ist, aber ich rate mal: das ist dir grade ziemlich egal, oder?
Wir werden jetzt einfach noch eine Listbox auf das Formular legen (erstmal einfach daneben), in der wir die Einträge aus der sortierten Liste umgekehrt für die Anzeige auf dem Bildschirm einfügen. Diese Listbox darf dann natürlich nicht automatisch sortieren! Die "originale" (erste) Listbox blenden wir dann einfach später aus (.Visible auf FALSE setzen, dann sieht man die nicht mehr, fertig).
In den Button-Handler kommt erstmal einfach nur rein:
Delphi-Quelltext
Vor dem Ausgeben der Liste in der neuen Listbox muss natürlich der alte Inhalt raus.
Sag bescheid, wenn du das soweit hast.
_________________ There are 10 types of people - those who understand binary and those who don´t.
|
|
Lena00
Beiträge: 65
Erhaltene Danke: 4
|
Verfasst: Mi 29.11.17 19:24
Bin soweit
Und jetzt muss in die neue Liste die alte andersrum ausgegeben werden
|
|
Narses
Beiträge: 10182
Erhaltene Danke: 1255
W10ent
TP3 .. D7pro .. D10.2CE
|
Verfasst: Mi 29.11.17 19:30
Konzept: Wir werden jetzt einfach alle Einträge aus der ersten Listbox immer wieder vorne (an der ersten Position) in der zweiten Listbox einfügen. Dabei dreht sich die Reihenfolge der Elemente automatisch um. Was brauchen wir dafür? - Wir bauchen die Anzahl der Elemente in der ersten Listbox: Listbox1.Count
- Wir brauchen eine for-Schleife, die über alle Elemente der ersten Listbox läuft.
- Wir brauchen einen Befehl, der ein Element an einer bestimmten Position einer Listbox einfügt (und nicht einfach immer ans Ende stellt): Listbox2.Items.Insert(<position>, <element>)
- Wir brauchen Zugriff auf ein Element einer Listbox: Listbox1.Items.Strings[<position>]
Damit solltest du alle "Bausteine" für die aktuelle Aufgabe beisammen haben. Was in spitzen Klammern oben angegeben ist, muss natürlich passend ersetzt werden.
Probier mal, dann sehen wir weiter.
_________________ There are 10 types of people - those who understand binary and those who don´t.
|
|
Lena00
Beiträge: 65
Erhaltene Danke: 4
|
Verfasst: Mi 29.11.17 19:38
|
|
Narses
Beiträge: 10182
Erhaltene Danke: 1255
W10ent
TP3 .. D7pro .. D10.2CE
|
Verfasst: Mi 29.11.17 19:46
Zunächstmal hast du noch die Zeile im Button-Handler drin, die einen neuen Highscore einträgt. Die sollte eigentlich bereits an die "richtige" Stelle in deinem Programm verschoben sein, nämlich da hin, wo das Spiel beendet wird. Der Button-Handler ist ja nur ein Test.
Allerdings könnte es sein, dass dein Spiel etwas aufwändiger ist und es deshalb unpraktisch zum testen, immer wieder eine Runde zu spielen, nur um einen Highscore-Test zu machen... Ist OK, in dem Fall brauchst du aber noch einen weiteren Test-Button, in dem wir dann jetzt die Übertragung von der ersten in die zweite Listbox programmieren.
Ansonsten ist dein "Code-Vorschlag" recht wenig... sagen wir mal "strukturiert". Sagtest du nicht, du hast bereits die for-Schleife im Unterricht gehabt?
_________________ There are 10 types of people - those who understand binary and those who don´t.
|
|