Autor Beitrag
Dragonclaw
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 196

Windows Vista
Delphi 7 Prof.
BeitragVerfasst: Do 07.12.06 13:29 
Hallo, ich bin gerade dabei TicTacToe zu schreiben, da wir gerade im Info Unterricht KIs machen. Mein Problem ist folgendes

Ich lasse die Kreise bzw. Kreuze auf die Form zeichnen. Dies wird mittels 9 Buttons gemacht, die dann verschwinden, und durch das jeweilige Symbol ersetezt werden das mittels Canvas NACH dem verstecken des Buttons gezeichnet wird. Hier erstmal der Code für die Zeichen procedure:

ausblenden Delphi-Quelltext
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:
procedure TForm1.Zeichnen(x,y : Integer);
begin
  inc(Zug); //In welchem Zug sich das spiel befindet
  if ((not win) AND (Zug > 8)) then            //Überprüfung ob ein Unentschieden erreicht wurde.
    begin
      Label3.Caption := 'Unentschieden!';      
      Button2.Visible := true;                 //Vorbereitung für neues Spiel
      Button1.Visible := false;
    end;

  if Spieler1 then                             // Wenn Spieler1 true ist, ist Spieler1 an der Reihe, wenn false dann Spieler 2
    begin
      Spieler1 := false;                       
      Form1.Canvas.Brush.Color := clred;
      Form1.Canvas.Ellipse(x-40, y+40, x+40, y-40);  
      Label3.Caption := Edit1.text + ' ist am Zug!';
    end
      else
        begin
        Spieler1 := true;
        Form1.Canvas.MoveTo(x - (78 div 2),y - (78 div 2));
        Form1.Canvas.LineTo(x + (78 div 2),y + (78 div 2));
        Form1.Canvas.MoveTo(x - (78 div 2),y + (78 div 2));
        Form1.Canvas.LineTo(x + (78 div 2),y - (78 div 2));
        Label3.Caption := Edit2.text + ' ist am Zug!';
        end;
end;


Diese Prozedur wird über die einzelnen Buttons aufgerufen, z. B.:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
procedure TForm1.Button3Click(Sender: TObject);
begin
Button3.Visible := false;
Zeichnen(Button3.Left + (Button3.Width div 2),Button3.Top + (Button3.Height div 2));
end;



So jetzt enstehen 2 Fehler, einmal das er den letzen Kreis nicht zeichnet.
user defined image
Dies tritt immer dann auf wenn beide Spielernamen gleich sind.

Der 2te Fehler ist das er NUR den ersten Kreis zeichnet und den Rest nicht mehr.
user defined image
Dies tritt immer dann auf wenn beide Spieler unterscheidlich sind.

Was kann ich tun, damit die Symbole immer richtig da gestellt werden?

Vielen Dank

Dragonclaw
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Do 07.12.06 13:40 
Moin!

Du malst ja direkt auf das Canvas der Form! :? Das ist nicht so schlau, weil wenn du z.B. ein anderes Fenster über deins schiebst, deine Grafiken weg sind... :|

Besser ist es, du nimmst z.B. ein Image in malst in dessen Canvas, dann übernimmt die VCL das Neuzeichnen. Beispiel siehe hier. ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
jakobwenzel
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1889
Erhaltene Danke: 1

XP home, ubuntu
BDS 2006 Prof
BeitragVerfasst: Do 07.12.06 14:51 
Eine Alternative wär, das ganze in OnPaint neu zu zeichnen.

_________________
I thought what I'd do was, I'd pretend I was one of those deaf-mutes.
Dragonclaw Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 196

Windows Vista
Delphi 7 Prof.
BeitragVerfasst: Do 07.12.06 15:07 
Vielen Dank ihr beiden. Ich habe das jetzt so gemacht, wie von Narses im anderen Thread vorgeschlagen hat. Ist das in Ordung wenn ich Teile von deinem Code übernehme. Wenn nicht sag bitte bescheid, will nichts klauen.


Dragonclaw
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Do 07.12.06 15:18 
Moin!

user profile iconDragonclaw hat folgendes geschrieben:
Ist das in Ordung wenn ich Teile von deinem Code übernehme.

Jau, geht schon klar (ist ja auch nix überwältigendes) ;) sonst hätte ich den Code nicht veröffentlicht.

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.