| Autor |
Beitrag |
wurstuk
      
Beiträge: 77
Win XP, Ubuntu
Delphi 7 personal
|
Verfasst: Mo 29.09.08 14:47
Hi,
Ich check den fehler einfach nicht....
bei meinem Würfel Spiel ist i-was nicht richtig, es zeigt manchmal den falschen Gewinner an....
wenn zb. Spieler1 ne 5 hat aber Spieler2 ne 3 dann zeigt er manchmal an das Spieler2 gewonnen hat und umgekehrt.
Das ganze spiel kann hier runter geladen werden: www.fileuploadx.de/211370
Hier der Quell text: (könnte sein das er ein bisschen unübersichtlich ist...  )
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: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156:
| unit wurfel;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;
type TForm1 = class(TForm) Button1: TButton; Button2: TButton; Label3: TLabel; Label4: TLabel; Label7: TLabel; Label8: TLabel; Button3: TButton; Button4: TButton; Label1: TLabel; Label2: TLabel; Button5: TButton; Button6: TButton; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button3Click(Sender: TObject); procedure Button4Click(Sender: TObject); procedure FormCreate(Sender: TObject); procedure Button6Click(Sender: TObject); procedure Button5Click(Sender: TObject); private public end; const max = 2; var zufall, zufall2, zahl, zahl2, zahl3, zahl4 : integer; spielende: boolean; Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject); begin
button1.Tag := zahl3; inc(zahl3); if button1.Tag = 3 then label8.visible := true; inc(zahl); randomize; zufall := random(6) + (1); Label3.caption := inttostr(zufall); if zahl <= max then label2.caption := inttostr(zahl) else label2.caption := 'Es Reicht!'; if zahl > max then button1.visible := False; if zufall > zufall2 then label8.caption := 'Spieler 1'; if zufall < zufall2 then label8.caption := 'Spieler 2'; spielende := false; end;
procedure TForm1.Button2Click(Sender: TObject); begin button2.Tag := zahl4; inc(zahl4); if button2.Tag = 3 then label8.visible := true;
if zufall > zufall2 then label8.caption := 'Spieler 1'; if zufall < zufall2 then label8.caption := 'Spieler 2';
if zahl2 <= max then label2.caption := inttostr(zahl2) else label2.caption := 'Es Reicht!'; if zahl2 > max then button2.visible := False; spielende := false; inc(zahl2); randomize; zufall2 := random(6) + (1); Label4.Caption := inttostr(zufall2); end;
procedure TForm1.Button3Click(Sender: TObject); begin if zufall = zufall2 then label8.caption := 'Beide Spieler'; button3.Tag := 1; if button4.Tag = 1 then label8.visible := true; if zufall > zufall2 then label8.caption := 'Spieler 1' else label8.Caption := 'Spieler 2'; label2.caption := ''; inc(zahl); button1.Visible := false; spielende := false;
end;
procedure TForm1.Button4Click(Sender: TObject); begin button4.Tag := 1; if button3.Tag = 1 then label8.visible := true;
if zufall > zufall2 then label8.caption := 'Spieler 1' else label8.Caption := 'Spieler 2'; if zufall = zufall2 then label8.caption := 'Beide Spieler';
inc(zahl2); Button2.Visible := false;
spielende := false;
end;
procedure TForm1.FormCreate(Sender: TObject); begin zahl3 := 0; zahl4 := 1; zahl2 := 1; zahl := 0; label8.Visible := false; spielende := false; end;
procedure TForm1.Button6Click(Sender: TObject); begin Spielende := true; if spielende = true then close; end;
procedure TForm1.Button5Click(Sender: TObject); begin Label2.Caption := ''; label3.caption := ''; label4.caption := ''; label8.caption := ''; button1.Visible := true; button2.Visible := true; zahl := 0; zahl2 := 1; label8.Visible := false; zahl3 := 0; zahl4 := 1; end;
end. |
Ich glaube es hengt mit button5 zusammen... weil es immer erst in einer neuen runde passiert....
Hoffe ihr könnt mir helfen^^
mfg
|
|
jaenicke
      
Beiträge: 19346
Erhaltene Danke: 1754
W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
|
Verfasst: Mo 29.09.08 16:36
Wenn du deinen Quelltext einrücken würdest, würde ich ihn mir auch anschauen, aber so ists grausam.
Also: Delphi-Quelltext 1: 2: 3: 4: 5: 6: 7:
| procedure TForm1.Button1Click(Sender: TObject); begin if zahl <= max then label2.caption := inttostr(zahl) else label2.caption := 'Es Reicht!'; end; | Das nur als Beispiel.
Was vielleicht das Problem ist (ohne mir den Salat genauer angeschaut zu haben):
Wenn mehrere Befehle innerhalb von if..then drin stehen sollen, musst du begin..end benutzen: Delphi-Quelltext 1: 2: 3: 4: 5: 6: 7:
| if xy then begin Befehl1; Befehl2; end else Befehl3; |
|
|
wurstuk 
      
Beiträge: 77
Win XP, Ubuntu
Delphi 7 personal
|
Verfasst: Mo 29.09.08 16:38
ok ich werd den quelltext nochmal überarbeiten^^ sry hatte blos viel rumprobiert und dann si ein bisschen unübersichtlich geworden^^
|
|
wurstuk 
      
Beiträge: 77
Win XP, Ubuntu
Delphi 7 personal
|
Verfasst: Mo 29.09.08 16:48
So, ich hoffe ich habe diss einrücken richtig gemacht:D
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: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164:
| unit wurfel;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;
type TForm1 = class(TForm) Button1: TButton; Button2: TButton; Label3: TLabel; Label4: TLabel; Label7: TLabel; Label8: TLabel; Button3: TButton; Button4: TButton; Label1: TLabel; Label2: TLabel; Button5: TButton; Button6: TButton; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button3Click(Sender: TObject); procedure Button4Click(Sender: TObject); procedure FormCreate(Sender: TObject); procedure Button6Click(Sender: TObject); procedure Button5Click(Sender: TObject); private public end; const max = 2; var zufall, zufall2, zahl, zahl2, zahl3, zahl4 : integer; spielende: boolean; Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject); begin
button1.Tag := zahl3; inc(zahl3); if button1.Tag = 3 then label8.visible := true;
inc(zahl); randomize; zufall := random(6) + (1); Label3.caption := inttostr(zufall);
if zahl <= max then label2.caption := inttostr(zahl) else label2.caption := 'Es Reicht!'; if zahl > max then button1.visible := False; if zufall > zufall2 then label8.caption := 'Spieler 1'; if zufall < zufall2 then label8.caption := 'Spieler 2'; spielende := false; end;
procedure TForm1.Button2Click(Sender: TObject); begin button2.Tag := zahl4; inc(zahl4);
if button2.Tag = 3 then label8.visible := true;
if zufall > zufall2 then label8.caption := 'Spieler 1'; if zufall < zufall2 then label8.caption := 'Spieler 2';
if zahl2 <= max then label2.caption := inttostr(zahl2) else label2.caption := 'Es Reicht!'; if zahl2 > max then button2.visible := False;
spielende := false; inc(zahl2); randomize; zufall2 := random(6) + (1); Label4.Caption := inttostr(zufall2); end;
procedure TForm1.Button3Click(Sender: TObject); begin if zufall = zufall2 then label8.caption := 'Beide Spieler';
button3.Tag := 1; if button4.Tag = 1 then label8.visible := true; if zufall > zufall2 then label8.caption := 'Spieler 1' else label8.Caption := 'Spieler 2';
label2.caption := ''; inc(zahl); button1.Visible := false; spielende := false;
end;
procedure TForm1.Button4Click(Sender: TObject); begin button4.Tag := 1;
if button3.Tag = 1 then label8.visible := true;
if zufall > zufall2 then label8.caption := 'Spieler 1' else label8.Caption := 'Spieler 2'; if zufall = zufall2 then label8.caption := 'Beide Spieler';
inc(zahl2); Button2.Visible := false;
spielende := false;
end;
procedure TForm1.FormCreate(Sender: TObject); begin zahl3 := 0; zahl4 := 1; zahl2 := 1; zahl := 0; label8.Visible := false; spielende := false; end;
procedure TForm1.Button6Click(Sender: TObject); begin Spielende := true;
if spielende = true then close; end;
procedure TForm1.Button5Click(Sender: TObject); begin Label2.Caption := ''; label3.caption := ''; label4.caption := ''; label8.caption := ''; button1.Visible := true; button2.Visible := true; zahl := 0; zahl2 := 1; label8.Visible := false; zahl3 := 0; zahl4 := 1; end;
end. |
|
|
<TargeT>
      
Beiträge: 59
Win XP, Win 98
Delphi 7
|
Verfasst: Mo 29.09.08 16:52
Lad dir einfach "DelForEx" runter.... damit kannste den gesamten Quellcode einrücken lassen. Einfach Strg + D drücken und schon ist der Quellcode eingerückt....
|
|
wurstuk 
      
Beiträge: 77
Win XP, Ubuntu
Delphi 7 personal
|
Verfasst: Mo 29.09.08 16:53
|
|
wurstuk 
      
Beiträge: 77
Win XP, Ubuntu
Delphi 7 personal
|
Verfasst: Mo 29.09.08 16:56
bei mir funktionier diss i-wie nicht....
|
|
jaenicke
      
Beiträge: 19346
Erhaltene Danke: 1754
W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
|
Verfasst: Mo 29.09.08 17:00
Also das ist ziemlich viel Quelltext für das was da passieren soll, aber den Fehler habe ich nicht reproduzieren können, bei mir hat es immer den richtigen Gewinner angezeigt.
Wie wäre es, wenn du den Quelltext einfach mal etwas kürzt?
Was mir so aufgefallen ist: warum nur ein Label für die Anzeige der Anzahl der Versuche von beiden Spielern?
|
|
wurstuk 
      
Beiträge: 77
Win XP, Ubuntu
Delphi 7 personal
|
Verfasst: Mi 01.10.08 07:13
hmmmm ok werd mal gucken^^
Aber wenns bei dier einwandfrei funktioniert hat is ja alles in butter^^
_________________ Wer Rechtschreibfehler findet darf sie behalten!
<(^_^)> <[$_$]>
|
|
|