| Autor |
Beitrag |
whitesnake
      
Beiträge: 40
Win XP Home
Delphi 7 Personal, HTML
|
Verfasst: Di 05.12.06 15:23
hi,
also wir sollen jetzt -um uns an das StringGrid heranzutasten- ein tic tac toe - spiel (also "käsekästchen" mit X oder O zum eintragen in 3x3 Felder, bei 3 in einer reihe/spalte oder bei diagonale hat man gewonnen)
soll so aufgebaut sein, dass es für 2 spieler is und man ... spieler1 z.B. ein X und Spieler2 ein O nur durch anklicken des feldes im stringgrid hinzufügt...
hab bereits schon was, allerdings den code nicht zur hand, kanns also in worten schreiben
das stringrid (3x3)
ein panel in dem meldungen stehen wie "Spieler 1 ist am Zug" o.Ä.
2 radiobuttons mit denen man zwischen Spieler 1 und 2 wechseln kann
ein zähler der die züge zählt
meine probleme:
ich hab keine ahnung wie man das programm erkennen lässt, wann man gewonnen hat beim spiel, also wie man das umsetzt, außerdem funktioniert mein zähler nicht, ich weiß nicht warum, am anfang is die VAR zug (Integer) = 0 und mit jedem klick wird zug+1 gerechnet... das müsste doch eigentlich alles im OnMouseUp (nich sicher ob das so hieß) stehen? da wo man definiert dass der linke mousebutton die eingabe liefert??
hat vllt jemand ne gute idee um so etwas so einfach wie möglich zu machen? also ohne großartig komplizierte funktionen oder 10 ineinander verschachtelte schleifen??
wär euch sehr dankbar
MfG
|
|
Narses
      

Beiträge: 10185
Erhaltene Danke: 1261
W11x64
TP3 .. D7pro .. D10.2CE
|
Verfasst: Di 05.12.06 15:39
Moin!
Schau mal hier, da haben wir das schonmal "durchgekaut"...
cu
Narses
_________________ There are 10 types of people - those who understand binary and those who don´t.
|
|
whitesnake 
      
Beiträge: 40
Win XP Home
Delphi 7 Personal, HTML
|
Verfasst: Di 05.12.06 15:52
|
|
Narses
      

Beiträge: 10185
Erhaltene Danke: 1261
W11x64
TP3 .. D7pro .. D10.2CE
|
Verfasst: Di 05.12.06 16:05
Moin!
Hmmm....  Du hast keinen Code, nur vage Problembeschreibungen und willst dich mit vorhandenem Code nicht beschäftigen.
Und was stellst du dir nun vor, was wir machen sollen? Gedankenübertragung? Nürnberger Trichter?
cu
Narses
_________________ There are 10 types of people - those who understand binary and those who don´t.
|
|
whitesnake 
      
Beiträge: 40
Win XP Home
Delphi 7 Personal, HTML
|
Verfasst: Di 05.12.06 16:07
nein ich dachte nur daran, dass vllt jemand einen einfach geschriebenen code hat, den man als laie (wenn ich mich so nennen darf nach nichma nem halben jahr) nachvollziehen kann
|
|
Narses
      

Beiträge: 10185
Erhaltene Danke: 1261
W11x64
TP3 .. D7pro .. D10.2CE
|
Verfasst: Di 05.12.06 16:12
Moin!
Vorschlag: Du zeigst der Reihe nach die Teile, die du in dem gelinkten Code nicht verstehst und wir versuchen dir das ausführlicher zu erklären.
cu
Narses
_________________ There are 10 types of people - those who understand binary and those who don´t.
|
|
delphistart
      
Beiträge: 119
|
Verfasst: Di 05.12.06 20:16
Mach erstmal ein Spielfeld, dann setzt du auf jedes Feld ein Image mit einem Kreuz und eins mit einem Kreis und zum schluss noch ein leeres.
Dann setzt du im Objektinspektor alle Image mit Kreuzen und Kreisen auf Visible.false
Nun machst du eine Variable (z.B. AmZug) des Typs boolean.
Jetzt machst du zu jedem Image ein onclickereignis das folgendes tut:
Ifabfrage ob spieler true oder false ist. Wenn true dann:
1. XImage des feldes auf Visible:=true
2. LEERES Image des feldes auf Visible:=false
3. Variable AmZug auf false
Wenn false (also else):
1. OImage des feldes auf Visible:=true
2. LEERES Image des feldes auf Visible:=false
3. Variable AmZug auf true
Wenn du das für alle Felder gemacht hast (Kannst du ja immer kopieren), dann bist konnen 2 Spieler abwechselnd Kreuz und Kreis setzen.
|
|
whitesnake 
      
Beiträge: 40
Win XP Home
Delphi 7 Personal, HTML
|
Verfasst: Do 07.12.06 16:58
delphistart hat folgendes geschrieben: | Mach erstmal ein Spielfeld, dann setzt du auf jedes Feld ein Image mit einem Kreuz und eins mit einem Kreis und zum schluss noch ein leeres.
Dann setzt du im Objektinspektor alle Image mit Kreuzen und Kreisen auf Visible.false
Nun machst du eine Variable (z.B. AmZug) des Typs boolean.
Jetzt machst du zu jedem Image ein onclickereignis das folgendes tut:
Ifabfrage ob spieler true oder false ist. Wenn true dann:
1. XImage des feldes auf Visible:=true
2. LEERES Image des feldes auf Visible:=false
3. Variable AmZug auf false
Wenn false (also else):
1. OImage des feldes auf Visible:=true
2. LEERES Image des feldes auf Visible:=false
3. Variable AmZug auf true
Wenn du das für alle Felder gemacht hast (Kannst du ja immer kopieren), dann bist konnen 2 Spieler abwechselnd Kreuz und Kreis setzen. |
klingt ja ganz einfach, aber leider hatten wir sowas mit images noch nicht und mein lehrer wird es wohl schon merkwürdig finden wenn dann sowas drin vorkommt... außerdem sollen wir nach seinem schema vorgehen...
das heißt (das spielfeld hab ich ja schon... hab auch schon allesim OnMouseUp drin...also dass linker und rechter mousebutton jeweils X oder O schreiben...)
er meinte, wir sollen die koordinaten des stringgrid benutzen und da einfach sachen reinschreiben lassen vom programm
also es funzt bei mir ja schon alles... ich meine, ich kann mit linkem und rechtem MButton entweder X oder O in ein beliebiges Feld durch anklicken eintragen...
allerdings weiß ich nicht wie ich die einzelnen koordinaten ansprechen muss, was ich ja machen muss um mit lauter IF anweisungen zu checken, ob 3 in einer reihe/spalte/diagonalen sind
wie gesagt...ab dem punkt weiß ich nich weiter...
wenn ich mit den mousebuttons arbeite, müssten doch diese IF anweisungen auch in den OnMouseUp rein, oder??
|
|
Narses
      

Beiträge: 10185
Erhaltene Danke: 1261
W11x64
TP3 .. D7pro .. D10.2CE
|
Verfasst: Do 07.12.06 17:11
Moin!
whitesnake hat folgendes geschrieben: | | wenn ich mit den mousebuttons arbeite, müssten doch diese IF anweisungen auch in den OnMouseUp rein, oder?? |
Ja, im Prinzip schon, aber ich würde eine Prozedur daraus machen, falls du das an mehreren Stellen brauchst.
cu
Narses
_________________ There are 10 types of people - those who understand binary and those who don´t.
|
|
whitesnake 
      
Beiträge: 40
Win XP Home
Delphi 7 Personal, HTML
|
Verfasst: Di 12.12.06 23:16
also ich hab jetzt mal alles neu geschrieben und mal die unbearbeitete fassung genommen... also sind da teilweise unnötige stellen drin... aber darum gehts nich...
ich merke gerade...es funzt alles.. bis auf wenn ich mit spieler 1 der ja anfängt mit X (immer spieler 1 = X) .. also ein X in die koordinate (0,0) eintrage, also oben links, dann geht es nicht weiter... radiobutton springt nicht um und spieler 2 kann nichts setzen...
wenn ich das erste X woanders hinsetze klappts aber wunderbar..
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: 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: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262: 263: 264: 265: 266: 267: 268: 269:
| unit Unit1;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Grids, ExtCtrls, StdCtrls;
type TForm1 = class(TForm) StringGrid1: TStringGrid; RadioButton1: TRadioButton; RadioButton2: TRadioButton; Button1: TButton; Button2: TButton; Panel1: TPanel; Panel2: TPanel; procedure FormCreate(Sender: TObject); procedure StringGrid1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); private public end;
var Form1: TForm1; zug, zeiley, zeilex: Integer; p1done, p2done: BOOLEAN;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject); begin zug := 1; panel1.caption := 'Anzahl der Züge: '+IntToStr(zug); panel2.Caption := 'Spieler 1 ist am Zug!'; radiobutton1.Checked := true; p2done := true; end; procedure TForm1.StringGrid1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); var zeilex, zeiley: integer; begin panel1.Caption := 'Anzahl der Züge: '+IntToStr(zug);
If stringgrid1.Cells[zeilex,zeiley] = '' Then begin
if p2done = true Then begin
If button = mbLeft Then begin StringGrid1.MouseToCell(X,Y,zeilex,zeiley); StringGrid1.cells[zeilex,zeiley] := ' X'; zug := zug + 1; p1done := true; p2done := false; radiobutton1.Checked := false; radiobutton1.Checked := true;
end;
If p1done = true Then begin panel2.Caption := 'Spieler 2 ist am Zug!'; end; end;
If p1done = true Then begin
If button = mbRight Then begin Stringgrid1.MouseToCell(X,Y,zeilex,zeiley); Stringgrid1.Cells[zeilex,zeiley] := ' O'; zug := zug + 1; p2done := true; p1done := false; radiobutton1.Checked := true; radiobutton2.Checked := false; end;
If p2done = true Then begin panel2.Caption := 'Spieler 1 ist am Zug!'; end;
end;
end;
If (stringgrid1.Cells[0,0] = ' X') and (Stringgrid1.Cells[0,1] = ' X') and (Stringgrid1.Cells[0,2] = ' X') Then begin showmessage('Spieler 1 hat gewonnen!'); stringgrid1.Enabled := false; radiobutton1.enabled := false; radiobutton2.Enabled := false; end;
If (stringgrid1.Cells[1,0] = ' X') and (Stringgrid1.Cells[1,1] = ' X') and (Stringgrid1.Cells[1,2] = ' X') Then begin showmessage('Spieler 1 hat gewonnen!'); stringgrid1.Enabled := false; radiobutton1.enabled := false; radiobutton2.Enabled := false; end;
If (stringgrid1.Cells[2,0] = ' X') and (Stringgrid1.Cells[2,1] = ' X') and (Stringgrid1.Cells[2,2] = ' X') Then begin showmessage('Spieler 1 hat gewonnen!'); stringgrid1.Enabled := false; radiobutton1.enabled := false; radiobutton2.Enabled := false; end;
If (stringgrid1.Cells[0,0] = ' X') and (Stringgrid1.Cells[1,0] = ' X') and (Stringgrid1.Cells[2,0] = ' X') Then begin showmessage('Spieler 1 hat gewonnen!'); stringgrid1.Enabled := false; radiobutton1.enabled := false; radiobutton2.Enabled := false; end;
If (stringgrid1.Cells[0,1] = ' X') and (Stringgrid1.Cells[1,1] = ' X') and (Stringgrid1.Cells[2,1] = ' X') Then begin showmessage('Spieler 1 hat gewonnen!'); stringgrid1.Enabled := false; radiobutton1.enabled := false; radiobutton2.Enabled := false; end;
If (stringgrid1.Cells[0,2] = ' X') and (Stringgrid1.Cells[1,2] = ' X') and (Stringgrid1.Cells[2,2] = ' X') Then begin showmessage('Spieler 1 hat gewonnen!'); stringgrid1.Enabled := false; radiobutton1.enabled := false; radiobutton2.Enabled := false; end;
If (stringgrid1.Cells[0,0] = ' X') and (Stringgrid1.Cells[1,1] = ' X') and (Stringgrid1.Cells[2,2] = ' X') Then begin showmessage('Spieler 1 hat gewonnen!'); stringgrid1.Enabled := false; radiobutton1.enabled := false; radiobutton2.Enabled := false; end;
If (stringgrid1.Cells[2,0] = ' X') and (Stringgrid1.Cells[1,1] = ' X') and (Stringgrid1.Cells[0,2] = ' X') Then begin showmessage('Spieler 1 hat gewonnen!'); stringgrid1.Enabled := false; radiobutton1.enabled := false; radiobutton2.Enabled := false; end;
If (stringgrid1.Cells[0,0] = ' O') and (Stringgrid1.Cells[0,1] = ' O') and (Stringgrid1.Cells[0,2] = ' O') Then begin showmessage('Spieler 2 hat gewonnen!'); stringgrid1.Enabled := false; radiobutton1.enabled := false; radiobutton2.Enabled := false; end;
If (stringgrid1.Cells[1,0] = ' O') and (Stringgrid1.Cells[1,1] = ' O') and (Stringgrid1.Cells[1,2] = ' O') Then begin showmessage('Spieler 2 hat gewonnen!'); stringgrid1.Enabled := false; radiobutton1.enabled := false; radiobutton2.Enabled := false; end;
If (stringgrid1.Cells[2,0] = ' O') and (Stringgrid1.Cells[2,1] = ' O') and (Stringgrid1.Cells[2,2] = ' O') Then begin showmessage('Spieler 2 hat gewonnen!'); stringgrid1.Enabled := false; radiobutton1.enabled := false; radiobutton2.Enabled := false; end;
If (stringgrid1.Cells[0,0] = ' O') and (Stringgrid1.Cells[1,0] = ' O') and (Stringgrid1.Cells[2,0] = ' O') Then begin showmessage('Spieler 2 hat gewonnen!'); stringgrid1.Enabled := false; radiobutton1.enabled := false; radiobutton2.Enabled := false; end;
If (stringgrid1.Cells[0,1] = ' O') and (Stringgrid1.Cells[1,1] = ' O') and (Stringgrid1.Cells[2,1] = ' O') Then begin showmessage('Spieler 2 hat gewonnen!'); stringgrid1.Enabled := false; radiobutton1.enabled := false; radiobutton2.Enabled := false; end;
If (stringgrid1.Cells[0,2] = ' O') and (Stringgrid1.Cells[1,2] = ' O') and (Stringgrid1.Cells[2,2] = ' O') Then begin showmessage('Spieler 2 hat gewonnen!'); stringgrid1.Enabled := false; radiobutton1.enabled := false; radiobutton2.Enabled := false; end;
If (stringgrid1.Cells[0,0] = ' O') and (Stringgrid1.Cells[1,1] = ' O') and (Stringgrid1.Cells[2,2] = ' O') Then begin showmessage('Spieler 2 hat gewonnen!'); stringgrid1.Enabled := false; radiobutton1.enabled := false; radiobutton2.Enabled := false; end;
If (stringgrid1.Cells[2,0] = ' O') and (Stringgrid1.Cells[1,1] = ' O') and (Stringgrid1.Cells[0,2] = ' O') Then begin showmessage('Spieler 2 hat gewonnen!'); stringgrid1.Enabled := false; radiobutton1.enabled := false; radiobutton2.Enabled := false; end; end;
procedure TForm1.Button1Click(Sender: TObject); begin close; end;
procedure TForm1.Button2Click(Sender: TObject); begin radiobutton1.enabled := true; radiobutton2.Enabled := true; panel2.Caption := 'Spieler 1 ist am Zug!'; zug := 1; p2done := true; p1done := false; radiobutton1.Checked := true; radiobutton2.Checked := false; stringgrid1.Enabled := true; StringGrid1.Cells[0,0] := ''; StringGrid1.Cells[0,1] := ''; StringGrid1.Cells[0,2] := ''; StringGrid1.Cells[1,0] := ''; StringGrid1.Cells[1,1] := ''; StringGrid1.Cells[1,2] := ''; StringGrid1.Cells[2,0] := ''; StringGrid1.Cells[2,1] := ''; StringGrid1.Cells[2,2] := ''; end;
end. |
|
|
Narses
      

Beiträge: 10185
Erhaltene Danke: 1261
W11x64
TP3 .. D7pro .. D10.2CE
|
Verfasst: Di 12.12.06 23:51
Moin!
whitesnake hat folgendes geschrieben: | | es funzt alles.. bis auf wenn ich mit spieler 1 der ja anfängt mit X (immer spieler 1 = X) .. also ein X in die koordinate (0,0) eintrage, also oben links, dann geht es nicht weiter... radiobutton springt nicht um und spieler 2 kann nichts setzen... |
Das stimmt nicht ganz...  egal, wer die Position (0,0) besetzt, damit ist dann Ende.
Was willst du eigentlich mit dieser Abfrage bezwecken:
Delphi-Quelltext 1:
| If stringgrid1.Cells[zeilex,zeiley] = '' Then |
...weil du zeilex und zeiley ja erst in der begin-Klausel mit neuen Werten belegst...
Weiterhin: warum das Gehampel mit den beiden Maustasten? Da eh immer der Andere abwechselnd dran ist, kannst du das doch auch gleich nur mit der linken Maustaste machen.
Dann noch: warum zwei Bool´sche Variablen für den Spielzustand, eine reicht doch: z.B. Spieler1AmZug: Boolean; ist die Variable TRUE, dann ist Spieler1 dran, ist sie FALSE, ist der Andere dran - und da es da ja nun mal nicht überraschend viel Auswahl an Spielern gibt...
Und auch noch: die Gewinnbedingung ist doch für beide Spieler gleich, warum machst du denn nicht eine Prozedur daraus, der du übergibst, für wen die Prüfung stattfinden soll. So hast du doch den ganzen if-Sermon auch gleich noch zweimal...
cu
Narses
_________________ There are 10 types of people - those who understand binary and those who don´t.
|
|
Narses
      

Beiträge: 10185
Erhaltene Danke: 1261
W11x64
TP3 .. D7pro .. D10.2CE
|
Verfasst: Mi 13.12.06 00:35
Moin!
Ach, ich konnt´s nicht mit ansehen...
Ich habe mal deinen Code etwas gestrafft (heißt, Überflüssiges entfernt und etwas aufgeräumt):
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:
| unit Unit1;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Grids, ExtCtrls, StdCtrls;
type TForm1 = class(TForm) StringGrid1: TStringGrid; RadioButton1: TRadioButton; RadioButton2: TRadioButton; Button1: TButton; Button2: TButton; Panel1: TPanel; Panel2: TPanel; procedure FormCreate(Sender: TObject); procedure StringGrid1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); private public Zug: Integer; end;
var Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject); begin Button2Click(Self); end;
procedure TForm1.Button2Click(Sender: TObject); var i,j: Integer; begin Radiobutton1.Enabled := True; Radiobutton2.Enabled := True; Zug := 0; Panel1.Caption := 'Anzahl der Züge: 0'; Panel2.Caption := 'Spieler 1 ist am Zug!'; Radiobutton1.Checked := True; Stringgrid1.Enabled := True; for i := 0 to 2 do for j := 0 to 2 do StringGrid1.Cells[i,j] := ''; end;
procedure TForm1.StringGrid1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); var spaltex, zeiley: integer; begin StringGrid1.MouseToCell(X,Y,spaltex,zeiley); if (Stringgrid1.Cells[spaltex,zeiley] = '') then begin if (RadioButton1.Checked) and (Button = mbLeft) then begin StringGrid1.Cells[spaltex,zeiley] := ' X'; zug := zug +1; Radiobutton2.Checked := True; Panel2.Caption := 'Spieler 2 ist am Zug!'; end; if (RadioButton2.Checked) and (Button = mbRight) then begin Stringgrid1.Cells[spaltex,zeiley] := ' O'; zug := zug +1; Radiobutton1.Checked := True; Panel2.Caption := 'Spieler 1 ist am Zug!'; end; end; Panel1.Caption := 'Anzahl der Züge: '+IntToStr(zug);
if (stringgrid1.Cells[0,0] = ' X') and (Stringgrid1.Cells[0,1] = ' X') and (Stringgrid1.Cells[0,2] = ' X') or (stringgrid1.Cells[1,0] = ' X') and (Stringgrid1.Cells[1,1] = ' X') and (Stringgrid1.Cells[1,2] = ' X') or (stringgrid1.Cells[2,0] = ' X') and (Stringgrid1.Cells[2,1] = ' X') and (Stringgrid1.Cells[2,2] = ' X') or (stringgrid1.Cells[0,0] = ' X') and (Stringgrid1.Cells[1,0] = ' X') and (Stringgrid1.Cells[2,0] = ' X') or (stringgrid1.Cells[0,1] = ' X') and (Stringgrid1.Cells[1,1] = ' X') and (Stringgrid1.Cells[2,1] = ' X') or (stringgrid1.Cells[0,2] = ' X') and (Stringgrid1.Cells[1,2] = ' X') and (Stringgrid1.Cells[2,2] = ' X') or (stringgrid1.Cells[0,0] = ' X') and (Stringgrid1.Cells[1,1] = ' X') and (Stringgrid1.Cells[2,2] = ' X') or (stringgrid1.Cells[2,0] = ' X') and (Stringgrid1.Cells[1,1] = ' X') and (Stringgrid1.Cells[0,2] = ' X') then begin showmessage('Spieler 1 hat gewonnen!'); stringgrid1.Enabled := false; radiobutton1.enabled := false; radiobutton2.Enabled := false; end; if (stringgrid1.Cells[0,0] = ' O') and (Stringgrid1.Cells[0,1] = ' O') and (Stringgrid1.Cells[0,2] = ' O') or (stringgrid1.Cells[1,0] = ' O') and (Stringgrid1.Cells[1,1] = ' O') and (Stringgrid1.Cells[1,2] = ' O') or (stringgrid1.Cells[2,0] = ' O') and (Stringgrid1.Cells[2,1] = ' O') and (Stringgrid1.Cells[2,2] = ' O') or (stringgrid1.Cells[0,0] = ' O') and (Stringgrid1.Cells[1,0] = ' O') and (Stringgrid1.Cells[2,0] = ' O') or (stringgrid1.Cells[0,1] = ' O') and (Stringgrid1.Cells[1,1] = ' O') and (Stringgrid1.Cells[2,1] = ' O') or (stringgrid1.Cells[0,2] = ' O') and (Stringgrid1.Cells[1,2] = ' O') and (Stringgrid1.Cells[2,2] = ' O') or (stringgrid1.Cells[0,0] = ' O') and (Stringgrid1.Cells[1,1] = ' O') and (Stringgrid1.Cells[2,2] = ' O') or (stringgrid1.Cells[2,0] = ' O') and (Stringgrid1.Cells[1,1] = ' O') and (Stringgrid1.Cells[0,2] = ' O') then begin showmessage('Spieler 2 hat gewonnen!'); stringgrid1.Enabled := false; radiobutton1.enabled := false; radiobutton2.Enabled := false; end; end;
procedure TForm1.Button1Click(Sender: TObject); begin Close; end;
end. |
Einzige wirklich funktionale Änderung ist das hier:
Delphi-Quelltext 1: 2:
| StringGrid1.MouseToCell(X,Y,spaltex,zeiley); if (Stringgrid1.Cells[spaltex,zeiley] = '') then begin |
In deinem Code bestimmst du die Koordinaten erst nach der if-Anweisung, und genau das ist eigentlich auch nur der entscheidende Fehler; der Rest war zwar etwas "strubbelig", aber durchaus funktionsfähig.
Vielleicht kommst du ja damit weiter; vor allem solltest du die Gewinnbedingung unbedingt eleganter bestimmen, das ist so echt grausam ineffizient...
cu
Narses
_________________ There are 10 types of people - those who understand binary and those who don´t.
|
|
whitesnake 
      
Beiträge: 40
Win XP Home
Delphi 7 Personal, HTML
|
Verfasst: Mi 13.12.06 11:49
danke für deine mühe, werds nachher mal genau unter die lupe nehmen...
das problem is, dass wir einfach mal total komplexe sachen machen, aber einzelne methoden zur vereinfachung nie besprochen haben... wie z.b. eigene prozeduren oder sonstwas
sicher, man könnte sich das ja alles selbst aneignen, aber ich dachte mir, es muss auch so gehen
mit dem
Delphi-Quelltext 1:
| if (Stringgrid1.Cells[spaltex,zeiley] = '') |
wollte ich erreichen, dass er nur etwas einträgt, wenn das feld auch noch frei ist
|
|
|