Kółko i Krzy?żyk

0

Stworzyłem grę kółko i krzyżyk. Ale trochę dziwną. Wykorzystuje w obliczaniu wyniku zmienne. Kompilator nie chcę mi skąpilować pliku mówi że jest incompantible types w :
if tura = 0 then
begin
a1 := a1 + 1;
b1 := b1 + 1;
c1 := c1 + 1;
tura := tura + 1;
a1.Caption := 'X';
a1.Enabled := false;

Czy ktoś mógłby znaleźć błąd w:

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;

type
TForm1 = class(TForm)
Edit1: TEdit;
Label1: TLabel;
Edit6: TEdit;
Label2: TLabel;
Button1: TButton;
Button2: TButton;
a1: TBut4on;
a4: TButton;
a2: TButton;
a3: TButton;
a5: TButton;
a7: TButton;
a8: TButton;
a6: TButton;
a9: TButton;
Timer1: TTimer;
procedure a1Click(Sender: TObject);
procedure a2Click(Sender: TObject);
procedure a3Click(Sender: TObject);
procedure a4Click(Sender: TObject);
procedure a5Click(Sender: TObject);
procedure a6Click(Sender: TObject);
procedure a7Click(Sender: TObject);
procedure a8Click(Sender: TObject);
procedure a9Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}
var
tura : integer;
a1 : integer;
a2 : integer;
a3 : integer;
b1 : integer;
b2 : integer;
b3 : integer;
c1 : integer;
c2 : integer;
x1 : integer;
x2 : integer;
x3 : integer;
y1 : integer;
y2 : integer;
y3 : integer;
z1 : integer;
z2 : integer;
procedure TForm1.a1Click(Sender: TObject);
begin
if tura = 0 then
begin
a1 := a1 + 1;
b1 := b1 + 1;
c1 := c1 + 1;
tura := tura + 1;
a1.Caption := 'X';
a1.Enabled := false;
end;

if tura = 1 then
begin
x1 := x1 + 1;
y1 := y1 + 1;
z1 := z1 + 1;
tura := tura - 1;
a1.Caption := 'O';
a1.Enabled := false;
end;
end;

procedure TForm1.a2Click(Sender: TObject);
begin
if tura = 0 then
begin
a1 := a1 + 1;
b2 := b2 + 1;
tura := tura + 1;
a2.Caption := 'X';
a2.Enabled := false;
end;

if tura = 1 then
begin
x1 := x1 + 1;
y2 := y2 + 1;
tura := tura - 1;
a2.Caption := 'O';
a2.Enabled := false;
end;
end;

procedure TForm1.a3Click(Sender: TObject);
begin
if tura = 0 then
begin
a1 := a1 + 1;
b3 := b3 + 1;
c2 := c2 + 1;
tura := tura + 1;
a3.Caption := 'X';
a3.Enabled := false;
end;

if tura = 1 then
begin
x1 := x1 + 1;
y3 := y3 + 1;
z2 := z2 + 1;
tura := tura - 1;
a3.Caption := 'O';
a3.Enabled := false;
end;
end;

procedure TForm1.a4Click(Sender: TObject);
begin
if tura = 0 then
begin
a2 := a2 + 1;
b1 := b1 + 1;
tura := tura + 1;
a4.Caption := 'X';
a4.Enabled := false;
end;

if tura = 1 then
begin
x2 := x2 + 1;
y1 := y1 + 1;
tura := tura - 1;
a4.Caption := 'O';
a4.Enabled := false;
end;
end;

procedure TForm1.a5Click(Sender: TObject);
begin
if tura = 0 then
begin
a2 := a2 + 1;
b2 := b2 + 1;
tura := tura + 1;
a5.Caption := 'X';
a5.Enabled := false;
end;

if tura = 1 then
begin
x2 := x2 + 1;
y2 := y2 + 1;
z1 := z1 + 1;
z2 := z2 + 1;
tura := tura - 1;
a5.Caption := 'O';
a5.Enabled := false;
end;
end;

procedure TForm1.a6Click(Sender: TObject);
begin
if tura = 0 then
begin
a2 := a2 + 1;
b3 := b3 + 1;
tura := tura + 1;
a6.Caption := 'X';
a6.Enabled := false;
end;

if tura = 1 then
begin
x2 := x2 + 1;
y3 := y3 + 1;
tura := tura - 1;
a6.Caption := 'O';
a6.Enabled := false;
end;

end;

procedure TForm1.a7Click(Sender: TObject);
begin
if tura = 0 then
begin
a3 := a3 + 1;
b1 := b1 + 1;
c2 := c2 + 1;
tura := tura + 1;
a7.Caption := 'X';
a7.Enabled := false;
end;

if tura = 1 then
begin
x3 := x3 + 1;
y1 := y1 + 1;
z2 := z2 + 1;
tura := tura - 1;
a7.Caption := 'O';
a7.Enabled := false;
end;
end;

procedure TForm1.a8Click(Sender: TObject);
begin
if tura = 0 then
begin
a3 := a3 + 1;
b2 := b2 + 1;
tura := tura + 1;
a8.Caption := 'X';
a8.Enabled := false;
end;

if tura = 1 then
begin
x3 := x3 + 1;
y2 := y2 + 1;
tura := tura - 1;
a8.Caption := 'O';
a8.Enabled := false;
end;
end;

procedure TForm1.a9Click(Sender: TObject);
begin
if tura = 0 then
begin
a3 := a3 + 1;
b3 := b3 + 1;
c1 := c1 + 1;
tura := tura + 1;
a9.Caption := 'X';
a9.Enabled := false;
end;

if tura = 1 then
begin
x3 := x3 + 1;
y3 := y3 + 1;
z1 := z1 + 1;
tura := tura - 1;
a9.Caption := 'O';
a9.Enabled := false;
end;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
If a1 = 3 then
begin
ShowMessage('Wins');
end;

If a2 = 3 then
begin
ShowMessage('Wins');
end;

If a3 = 3 then
begin
ShowMessage('Wins');
end;

If b1 = 3 then
begin
ShowMessage('Wins');
end;

If b2 = 3 then
begin
ShowMessage('Wins');
end;

If b3 = 3 then
begin
ShowMessage('Wins');
end;

If c1 = 3 then
begin
ShowMessage('Wins');
end;

If c2 = 3 then
begin
ShowMessage('Wins');
end;

If x1 = 3 then
begin
ShowMessage('Wins');
end;

If x2 = 3 then
begin
ShowMessage('Wins');
end;

If x3 = 3 then
begin
ShowMessage('Wins');
end;

If y1 = 3 then
begin
ShowMessage('Wins');
end;

If y2 = 3 then
begin
ShowMessage('Wins');
end;

If y3 = 3 then
begin
ShowMessage('Wins');
end;

If z1 = 3 then
begin
ShowMessage('Wins');
end;

If z2 = 3 then
begin
ShowMessage('Wins');
end;
end;

end.

0

nazwij buttony inaczej niz zmienne integer. kompilator mysli ze chcesz dodac 1 do buttona co raczej nie ma za grosz sensu.

0

jeśli chcesz to ci pokaże przykładową gre kółko i krzyzyk ale w Pascalu

bo to co ty napisałes nie mozna nazwać programem...
i jest to totalnei nie czytelne...

i cięzko jest kontrolowac taki program.
więc jeśli chcesz przyklad daj znac na maila

0

O ile sie nie myle, kodzik gry moznabylo znalezc w dziale Gotowce albo KodyZrodlowe....

0

Wiem! JA znam lepsze, ale jestem początkującym. A tak w ogóle to dzięki!

0

kodzik troszku nieczytelny i poco timer? :-/ ja bym zrobil tablice [1..9] boolean i sprawdzal czy nie jezeli nie to tak itp.... poza tym a1 to zmienna integer a ty chciales caption mu ustawic ... rotfl :-D

0

...ja bym zrobil tablice [1..9] boolean...

Kiepski pomysł. Z dwóch powodów: tablica dwuwymiarowa [1..3, 1..3] byłaby dużo lepsza, no i nie można dać boolean jako typu tablicy, ponieważ każde pole musi mieć co najmniej 3 stany: kółko, krzyżyk oraz pusty, a boolean ma tylko 2 stany. Czyli proponuję string, lub integer (czy tam byte, albo shortint, jeśli nie potrzeba zakresu integer, a zwykle nie potrzeba :) )

0

tylko dziwne ze mi dzialo pole:array[1..9] of boolean; a z tymi dwuwymjarowymi to dobry pomysl:)) napisze se xo ;)

1 użytkowników online, w tym zalogowanych: 0, gości: 1