| Autor |
Beitrag |
AvadeX
Hält's aus hier
Beiträge: 10
|
Verfasst: Fr 14.03.03 23:52
Hallo,
ich will ein kleines Quiz spiel programmieren, dass ca. 200 verschiedene Fragen enthält, die zufällig gefragt werden!
Was wäre am besten, um alle Fragen (bzw. Antworten) im Programm zu speichern? Und womit könnte ich überprüfen ob die angeklickte antwort richtig ist?
|
|
derDoc
      
Beiträge: 623
Win Vista Prof
D2007 Prof
|
Verfasst: Sa 15.03.03 10:49
Das hier ist bloß eine Idee, d.h. noch nicht wirklich ausgereift.
Du kannst deine Fragen in eine Datenbank schreiben, die möglichen Antworten dazu schreiben (jeweils extra Feld wie Antwort1, Antwort2, usw.) und ein Feld, in dem das richtige Feld (Antwort1) angegeben ist. Dann kannst du über Random(id) (ID der Fragen) diese zufällig auswählen und z.B. als gefragt in der DB markieren. Nun noch die Antworten in RadioButtons einlesen und einer Stringvariable die richtige Antwort übergeben. Wenn jetzt der Eingabe Button (oder was auch immer) gedrückt wird überprüfst du dei Caption von dem "gecheckten" RadioButton und vergleichst ihn mit dem String. Fertig.
_________________ MfG derDoc
There are only 10 types of people: those who understand binary and those who don't.
|
|
AvadeX 
Hält's aus hier
Beiträge: 10
|
Verfasst: Sa 15.03.03 12:49
hmm, und wenn ich einfach alle Fragen in einem Array speichere? für jede stufe des spiels einfach ein array mit 20 fragen, so ist ausgeschlossen, dass sich eine frage während des spiels wiederholt!
aber wie finde ich zu der frage die passenden antworten? also dass er auch nur die 4 antworten anzeigt, die zu der frage gehören sollen!
|
|
derDoc
      
Beiträge: 623
Win Vista Prof
D2007 Prof
|
Verfasst: Sa 15.03.03 13:53
Natürlich kannst du das ganze auch in Arrays schreiben, sodass du ein Array mit Fragen hast, 4 Arrays mit Antworten, wobei die Antworten den selben Index wie die Frage haben und ein Array mit Zahlen, mit denen du die richtige Antwort heraus findest (1, 2, 3 oder 4). Eine mögliche Anwendung wäre:
Quelltext 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11:
| ... case richtig[i] of 1: richtig := Antwort1[i]; 2: richtig := Antwort2[i]; 3: richtig := Antwort3[i]; 4: richtig := Antwort4[i]; end; if wahl = richtig then //wahl ist die Caption des gewählten RadioButtons ShowMessage('Ihre Antwort ist richtig') else ShowMessage('Ihre Antwort ist falsch'); |
Dann musst du nur noch den Anfang schreiben.
_________________ MfG derDoc
There are only 10 types of people: those who understand binary and those who don't.
|
|
AvadeX 
Hält's aus hier
Beiträge: 10
|
Verfasst: Sa 15.03.03 15:41
so ganz habe ich das nicht verstanden!
also am Anfang sieht es so bei mir aus:
Quelltext 1: 2: 3: 4:
| fragen : array[0..2] of string; fragen[0] := 'Hier Frage1 ?'; fragen[1] := 'Hier Frage2 ?'; fragen[2] := 'Hier Frage3 ?'; |
jetzt müsste ich praktisch für jedes Label eine OnClick Prozedur anlegen und da dann die Funktion einfügen, die die Richtigkeit überprüft! Wie meinst du das jetzt! Kannst du mal kleines beispiel für die fragen machen?
[/code]
|
|
derDoc
      
Beiträge: 623
Win Vista Prof
D2007 Prof
|
Verfasst: Sa 15.03.03 17:20
Ich ging davon aus, dass du 4 RadioButtons benutzt, denn mit 4 Labels hast du keine Chance auf einen zweiten Versuch. Um zu antworten musst du bei mir einen RadioButton auswählen und dann einen Button drücken. Ich schreibe dir nachmehr mal den Code, wie ich mir das vorstelle. Ich habe im moment keine Zeit dazu.
_________________ MfG derDoc
There are only 10 types of people: those who understand binary and those who don't.
|
|
derDoc
      
Beiträge: 623
Win Vista Prof
D2007 Prof
|
Verfasst: Sa 15.03.03 18:18
Hier ist nun der Code:
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:
| const Fragen: Integer = 2; //Anzahl der Fragen, wichtig!!!
var Form1: TForm1; Frage: array [0..1] of String = ('Test', 'Ziel'); Antwort1: array [0..1] of String = ('1', '1'); Antwort2: array [0..1] of String = ('2', '2'); Antwort3: array [0..1] of String = ('3', '3'); Antwort4: array [0..1] of String = ('4', '4'); Richtige: array [0..1] of Integer = (3, 1); //Gibt richtige Auswahl an i: Integer;
...
procedure TForm1.FormCreate(Sender: TObject); begin i := 0; RadioButton1.Caption := Antwort1[i]; RadioButton2.Caption := Antwort2[i]; RadioButton3.Caption := Antwort3[i]; RadioButton4.Caption := Antwort4[i]; end;
procedure TForm1.Button1Click(Sender: TObject); var antwort, richtig: String; begin if RadioButton1.Checked then begin antwort := RadioButton1.Caption; case Richtige[i] of 1: richtig := antwort1[i]; 2: richtig := antwort2[i]; 3: richtig := antwort3[i]; 4: richtig := antwort4[i]; end; if antwort = richtig then Label1.Caption := 'Richtige Antwort' else Label1.Caption := 'Falsch'; RadioButton1.Checked := false; end else begin if RadioButton2.Checked then begin antwort := RadioButton2.Caption; case Richtige[i] of 1: richtig := antwort1[i]; 2: richtig := antwort2[i]; 3: richtig := antwort3[i]; 4: richtig := antwort4[i]; end; if antwort = richtig then Label1.Caption := 'Richtige Antwort' else Label1.Caption := 'Falsch'; RadioButton2.Checked := false; end else begin if RadioButton3.Checked then begin antwort := RadioButton3.Caption; case Richtige[i] of 1: richtig := antwort1[i]; 2: richtig := antwort2[i]; 3: richtig := antwort3[i]; 4: richtig := antwort4[i]; end; if antwort = richtig then Label1.Caption := 'Richtige Antwort' else Label1.Caption := 'Falsch'; RadioButton3.Checked := false; end else begin antwort := RadioButton4.Caption; case Richtige[i] of 1: richtig := antwort1[i]; 2: richtig := antwort2[i]; 3: richtig := antwort3[i]; 4: richtig := antwort4[i]; end; if antwort = richtig then Label1.Caption := 'Richtige Antwort' else Label1.Caption := 'Falsch'; RadioButton4.Checked := false; end; end; end; Inc(i); if i = Fragen then ShowMessage('Quiz vorbei') else begin RadioButton1.Caption := Antwort1[i]; RadioButton2.Caption := Antwort2[i]; RadioButton3.Caption := Antwort3[i]; RadioButton4.Caption := Antwort4[i]; end; end;
... |
Das ist meine Vorstellung. Oben kannst du die Fragen und die Anzahl der Fragen eingeben.
_________________ MfG derDoc
There are only 10 types of people: those who understand binary and those who don't.
|
|
AvadeX 
Hält's aus hier
Beiträge: 10
|
Verfasst: Sa 15.03.03 20:31
ah danke!
dann werde ich jetzt noch den zufallsgenerator etwa so einbauen
Quelltext 1: 2: 3: 4: 5: 6:
| Label1.Caption := frage[random(j)]; case frage[i] of 1: RadioButton1.Caption := antwort1[j] 2: RadioButton2.Caption := antwort2[j] 3: RadioButton3.Caption := antwort3[j] 4: RadioButton4.Caption := antwort4[j] |
so müsste es doch klappen, oder
|
|
derDoc
      
Beiträge: 623
Win Vista Prof
D2007 Prof
|
Verfasst: Sa 15.03.03 20:42
Also davon abgesehen, dass es caso richtig[j] of heißen müsste geht das so.
_________________ MfG derDoc
There are only 10 types of people: those who understand binary and those who don't.
|
|
kiwicht
      
Beiträge: 1021
Win 7, MacOS
Delphi x, VBA, PHP, ...
|
Verfasst: So 16.03.03 11:17
Hm, warum so umständlich? Datenbanken sind doch dazu da uns die Arbeit zu erleichtern, was hälst du also hiervon:
Datenbank-Struktur:
ID / Integer
Frage / String
Antwort1 / String
Antwort2 / ...
Antwort3 / ...
Lösung / Integer
Schematischer Programmaufbau:
Quelltext 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17:
| 1 DB-EditFeld (oder auch Memo) zur Darstellung der Frage 3 DB-EditFelder für die Antworten 1 RadioGroup mit 3 Items 1 Edit-Feld zur Eingabe der Lösung
procedure NeueFrage;
Query1.SQL.Text := 'SELECT * FROM quiz WHERE id = ' + random(Query1.RecordCount)
procedure onButtonClick;
if Edit1.Text = Query1.FieldValues['lösung'] then Inc(Score, 1) else MessageBox('FALSCHE ANTWORT');
NeueFrage; |
Das alles verpackt in eine schöne Oberfläche, Syntax-Konform überarbeiten, fertig ist die Wurst!
mfg
|
|