Autor Beitrag
guerkchen Threadstarter
Hält's aus hier
Beiträge: 13



BeitragVerfasst: Do 11.05.06 18:51 
user profile iconF34r0fTh3D4rk hat folgendes geschrieben:
sind 400 zeilen nicht ein wenig viel für ein tictactoe ?
meins kommt unoptmiert mit ki mit 224 aus, ich benutze shapes, ich kann
hier ja mal den code posten. das spielfeld ist ein eindimensionales array


- ääähm - da ich ja kaum ahnung von delphi habe, weis ich nicht was shapes sind -.-
das ist wie gesagt für die schule & ich hab noch nicht mal ein jahr delphi & nur einmal in der woche info - in den zwei stunden redet der lehrer dann die hälfte der zeit über was anderes, erklärt alles doppelt & oder schreibt arbeiten -.-
Einloggen, um Attachments anzusehen!
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Do 11.05.06 19:06 
F34r meint es sicher gut, aber der Lehrer würde bestimmt merken, wenn du etwas einbaust, was du selbst noch nicht verstehst. Da kann man es ruhig etwas umständlich aussehen lassen.
WordBool
Hält's aus hier
Beiträge: 3

WIN XP
Borland Developer Studio 2006 Prof., Lazarus(Free Pascal)
BeitragVerfasst: Do 11.05.06 19:18 
Mann, guerkchen!
Ich bin auch nur Schüler, und nicht so wrfahren wie es die meisten hier sind, aber ich kenne zumindest den zwischen := und =. Du solltest dir vielleicht erst mal grundlegendes wissen über Delphi aneignen bevor du ein Tic Tac Toe progst.
Neulich erst hab ich mir ein TicTacToe programmiert mit lernfähiger KI, hab´s aber leider auf nem anderen rechner!

Zitat:
Du nimmst einfach 9 Images (3*3) und in der OnClick-Procedure lädst du Bilder rein oder mals t mit canvas.textout eben ein X oder O.

@ Marco D: Hab´s auch mit images gemacht, und die bilder dann mit ressourcen an die exe angehängt.

@ jasocul: Der lehrer würde es bestimmt merken, aber was soll er den machen, wenn der lehrer das programm schon so bald verlangt?

@ guerkchen: muss es denn ein spiel sein?
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Do 11.05.06 19:31 
@WordBool: Gut gemeinter Rat, aber das Programm ist ja fast fertig :wink:
@guerkchen:
Ich habe mir den Source nichtmal inhaltlich angesehen und trotzdem den Fehler gefunden. Wenn du die Einrückungen sauber gemacht hättest, hättest du auch bemerkt, dass du ein Problem mit deinen Begin..End-Blöcken hast. So sollte es aussehen (exemplarisch für einen Source-Bereich):
ausblenden volle Höhe 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:
28:
29:
30:
31:
32:
33:
34:
35:
36:
procedure TForm2.l0Click(Sender: TObject);
var O:char;
    X:char;
    AO:string;
    AX:string;
begin
  X:='X';
  O:='O';
  AO:='Kreis ist an der Reihe!';
  AX:='Kreuz ist an der Reihe!';

  if lanweis.caption=AO then
  begin
    if l0.caption=X then
      lanweis.Caption:='FEHLER!';
    if l0.caption=O then
      lanweis.Caption:='FEHLER!';
    if l0.caption=' ' then
    begin
      l0.caption:=O;
      lanweis.Caption:=AX
    end
  end // Dieses end hat gefehlt
  else
  begin
    if l0.caption=X then
      lanweis.Caption:='FEHLER!';
    if l0.caption=O then
      lanweis.Caption:='FEHLER!';
    if l0.caption=' ' then
    begin
      l0.caption:=X;
      lanweis.Caption:=AO
    end;
  end; // und hier war eins zuviel
end;

Ich habe nur die Einrückungen nachgearbeitet. Dabei fallen solche Fehler sofort auf. Übrigens fehlen noch drei Felder in deinem Programm. :zwinker:
Du musst diese Änderungen nur noch auf alle anderen Klick-Ereignisse übertragen, dann hast du diesen Teil schon erledigt.
Das Programm hält den hohen Anforderungen der Profis sicher nicht stand, aber für eine erste Anwendung ist das doch gar nicht schlecht. Soweit wie es jetzt ist, macht es doch das, was es soll.
guerkchen Threadstarter
Hält's aus hier
Beiträge: 13



BeitragVerfasst: Do 01.06.06 14:40 
joa,...
ich bin nun - in der schule - ein bisschen weiter gekommen
ich hab nun folgende probleme:

-wie baue ich die prozedur, welche im moment nur ein kommentar ist ein? (sie dient zum prüben, ob es einen sieger gibt)

-warum versteht dalphi ein "and" wie ein oder (am ende von jeder *label przedur* soll geprüft werden, ob das feld voll ist & mein lehrer meinte man kann die bedingungen einer alternative mit and verbinden)

danke!!!!!!!
Einloggen, um Attachments anzusehen!
F34r0fTh3D4rk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5285
Erhaltene Danke: 29

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Do 01.06.06 14:44 
sagn wir mal so, ich hab auch erst 2 jahre informatik (noch nichmal) und auch nur einmal in der woche, aber ich interessiere mach da ein wenig mehr für ;)
The Who
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 25

Win XP Prof
D3 Prof, D8, D7E
BeitragVerfasst: Do 01.06.06 15:02 
Nur als Tipp du kannst eine Prozedur auch für mehrer Ereignisse benutzen.

Die Prozeduren l1Click bis l8Click sind ja eigentlich gleich (hoffe ich).

Du kannst nun eine Prozedur schreiben, und sie per Objektexplorer an mehrer Label-Ereignisse binden,
du musst nur bei jedem Label unter OnClick den selben Prozedurnamen hinschreiben.

Ich glaube das der Quelltext dann schon viel übersichtlicher ist.
guerkchen Threadstarter
Hält's aus hier
Beiträge: 13



BeitragVerfasst: Mo 05.06.06 18:30 
danke - lieb gemeint - hilft mir nur nich groß weiter
guerkchen Threadstarter
Hält's aus hier
Beiträge: 13



BeitragVerfasst: Do 08.06.06 14:27 
bitte, bitte ein letztes mal helfen & mit geübten augen durchlesen
sind bestimmt blos wider einrück- oder klammer fehler, aber die prozedur funktioniert nicht, wie sie soll -.-
das merkt man wenn man 1-2 mal versucht zu spielen & das program fälschlicherweise bahauptet einer hat gewonnen (siehe anhang)

ausblenden volle Höhe 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:
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:
procedure TForm2.test1;
  begin
     if
      ((l0.caption=X) and (l1.Caption=X) and (l2.Caption=X)) OR
      ((l3.Caption=X) and (l4.caption=X) and (l5.Caption=X)) OR
      ((l6.caption=X) and (l7.caption=X) and (l8.caption=X)) OR
      ((l0.caption=X) and (l3.caption=X) and (l6.caption=X)) OR
      ((l1.caption=X) and (l4.caption=X) and (l7.caption=X)) OR
      ((l2.caption=X) and (l5.caption=X) and (l8.caption=X)) OR
      ((l0.caption=X) and (l4.caption=X) and (l8.caption=X)) OR
      ((l2.caption=X) and (l4.caption=X) and (l6.caption=X))
     then
     test:=3;

     if
      ((l0.caption=O) and (l1.Caption=O) and (l2.Caption=O)) OR
      ((l3.Caption=O) and (l4.caption=O) and (l5.Caption=O)) OR
      ((l6.caption=O) and (l7.caption=O) and (l8.caption=O)) OR
      ((l0.caption=O) and (l3.caption=O) and (l6.caption=O)) OR
      ((l1.caption=O) and (l4.caption=O) and (l7.caption=O)) OR
      ((l2.caption=O) and (l5.caption=O) and (l8.caption=O)) OR
      ((l0.caption=O) and (l4.caption=O) and (l8.caption=O)) OR
      ((l2.caption=O) and (l4.caption=O) and (l6.caption=O))
      then
      test:=2;

     if test=3 then begin
      application.MessageBox('Kreuz hat gewonnen!','XXXXXXXXXXXXXXXXXX',MB_OK);
      test:=0;
      l0.caption:=' ';
      l1.caption:=' ';
      l2.caption:=' ';
      l3.caption:=' ';
      l4.caption:=' ';
      l5.caption:=' ';
      l6.caption:=' ';
      l7.caption:=' ';
      l8.caption:=' ';
      lanweis.caption:=' '
      end;

     if test=2 then begin
      application.MessageBox('Kreis hat gewonnen!','OOOOOOOOOOOOOOOOOO',MB_OK);
      test:=0;
      l0.caption:=' ';
      l1.caption:=' ';
      l2.caption:=' ';
      l3.caption:=' ';
      l4.caption:=' ';
      l5.caption:=' ';
      l6.caption:=' ';
      l7.caption:=' ';
      l8.caption:=' ';
      lanweis.caption:=' '
    end;

  end;
Einloggen, um Attachments anzusehen!
Fighter#1
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 787

Win XP, Ubuntu 8.04
Turbo Delphi 2006, Delphi 2005 Pe, Delphi 5 Pe, Netbeans 6.1, Eclipse, Microsoft VisualC#, Dev C++, PHP, HTML, CSS
BeitragVerfasst: Do 08.06.06 14:41 
Ich würd die Images dynamisch erstellen und dann ne allgemeine onClick bauen:
OnClick(Sender:Tobject);
begin
//hier dann einfach das was passieren soll
end;

Das kürtzt nen Code Extremst.

AChja, ich bringe mir Delphi seit Oktober selbst bei, es is nich unmöglich ^^...

_________________
Wer andere beherrscht ist stark,
wer sich selbst beherrscht ist mächtig. Lao Tse
azubi_20
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 593

WinXP SP2, Ubuntu 8.4
D7 Enterp., D2005 Prof., Java (Eclipse 3.4.0)
BeitragVerfasst: Do 08.06.06 14:43 
guck dir mal auf deiner Form die Positionen von l4 und l5 an :wink:


EDIT :
Ein paar Vorschläge (Schönheitsreparaturen):

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
procedure TForm1.bokClick(Sender: TObject);
begin
  form1.hide; //Form1 verschwindet
  form2.show; //Form2 taucht auf
end;

procedure TForm2.bcloseClick(Sender: TObject);
begin
  Application.terminate; //Programm wird auf jeden Fall beendet 
end;


Dann setz mal beim ibg im Objektinspektor "align" auf alClient
guerkchen Threadstarter
Hält's aus hier
Beiträge: 13



BeitragVerfasst: Do 08.06.06 20:18 
juhu - es funktioniert *spring*


user profile iconazubi_20 hat folgendes geschrieben:
guck dir mal auf deiner Form die Positionen von l4 und l5 an

*schääääääm* - darauf hätte ich auch von alleine kommen können,...

[quote="user profile iconazubi_20"
Dann setz mal beim ibg im Objektinspektor "align" auf alClient
[/quote]

was bedeutet das denn?
Fighter#1
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 787

Win XP, Ubuntu 8.04
Turbo Delphi 2006, Delphi 2005 Pe, Delphi 5 Pe, Netbeans 6.1, Eclipse, Microsoft VisualC#, Dev C++, PHP, HTML, CSS
BeitragVerfasst: Do 08.06.06 21:09 
Das es dem Form immer angepasst ist (gleiche höhe und breite)

_________________
Wer andere beherrscht ist stark,
wer sich selbst beherrscht ist mächtig. Lao Tse
fidionael
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 232

Win XP SP2, Ubuntu 6.06
Delphi 7 PE, Delphi 3 Prof
BeitragVerfasst: Fr 09.06.06 00:07 
Ich weiß nicht, ob das Problem nun schon gelöst ist, hier wäre jedenfalls ein vollständig implementiertes TicTacToe (allerdings ohne KI) ohne jegliche Komponenten wie TShape, TImage, etc. (sämtliches Zeichnen findet per Hand statt), dass ich mal rasch für dich geschrieben habe:

ausblenden volle Höhe Unit1.pas
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;

type
  TFeld = (Leer,Kreis,Kreuz);

  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure FormPaint(Sender: TObject);
    procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
                            Shift: TShiftState; X, Y: Integer);
  private
    Feld: Array[1..3,1..3] of TFeld;
    CurrentPlayer: 1..2;

    function HasWon(Player: Smallint) : Boolean;
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
var x,y: Integer;
begin
  for x:=1 to 3 do for y:=1 to 3 do Feld[x,y]:=Leer;
  CurrentPlayer:=1;

  with Form1.Canvas do begin
    Brush.Color:=clBtnFace;
    FillRect(rect(0,0,ClientWidth,ClientHeight));
  end;
  FormPaint(self);
end;

procedure TForm1.FormPaint(Sender: TObject);
var i: Integer;
    x,y: Integer;
begin
  with Form1.Canvas do begin
    Pen.Width:=1;
    for i:=1 to 2 do begin
      MoveTo(i * (ClientWidth div 3), 0);
      LineTo(i * (ClientWidth div 3), ClientHeight);
      MoveTo(0, i * (ClientHeight div 3));
      LineTo(ClientWidth, i * (ClientHeight div 3));
    end;
  end;

  with Form1.Canvas do begin
    Pen.Width:=3;
    for x:=1 to 3 do for y:=1 to 3 do
      case Feld[x,y] of
        Kreis: Ellipse((ClientWidth div 3)*(x-1)+5,(ClientHeight div 3)*(y-1)+5,
                       (ClientWidth div 3)*(x)-5, (ClientHeight div 3)*(y)-5);
        Kreuz:
          begin
            MoveTo((ClientWidth div 3)*(x-1)+5, (ClientHeight div 3)*(y-1)+5);
            LineTo((ClientWidth div 3)*(x)-5, (ClientHeight div 3)*(y)-5);
            MoveTo((ClientWidth div 3)*(x-1)+5, (ClientHeight div 3)*(y)-5);
            LineTo((ClientWidth div 3)*(x)-5, (ClientHeight div 3)*(y-1)+5);
          end;
      end;
  end;
end;

procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
                               Shift: TShiftState; X, Y: Integer);

  function Coord(X_in_Pixels,Y_in_Pixels: Integer) : TCoord;
  begin
    with Result do begin
      X:=X_in_Pixels div (ClientWidth div 3) + 1;
      Y:=Y_in_Pixels div (ClientHeight div 3) + 1;
    end;
  end;

  procedure SwitchPlayers;
  begin
    if CurrentPlayer = 1 then CurrentPlayer:=2
    else CurrentPlayer:=1;
  end;

begin
  if Feld[Coord(X,Y).X,Coord(X,Y).Y] = Leer then begin
    Feld[Coord(X,Y).X,Coord(X,Y).Y]:=TFeld(CurrentPlayer);
    FormPaint(self);

    if HasWon(CurrentPlayer) then with Application do
      if MessageBox(pChar(Format('Spieler %d hat gewonnen!',[CurrentPlayer])+#10
                    +#10+'Nochmal spielen?'),pChar(Caption),MB_YESNO) = 6 then
        FormCreate(self)
      else Application.Terminate
    else
      SwitchPlayers;
  end;
end;

function TForm1.HasWon(Player: Smallint) : Boolean;
var i,n: Integer;
begin
  Result:=False;
  for i:=1 to 3 do begin n:=0;
    while (Feld[i,n+1] = TFeld(Player)) and (n<3) do inc(n);
    if n = 3 then begin Result:=True; Exit; end; n:=0;
    while (Feld[n+1,i] = TFeld(Player)) and (n<3) do inc(n);
    if n = 3 then begin Result:=True; Exit; end; n:=0;
    while (Feld[n+1,n+1] = TFeld(Player)) and (n<3) do inc(n);
    if n = 3 then begin Result:=True; Exit; end; n:=0;
    while (Feld[3-n,n+1] = TFeld(Player)) and (n<3) do inc(n);
    if n = 3 then begin Result:=True; Exit; end;
  end;
end;

end.


Vielleicht hilft es dir ja. Mfg