Форум: "Игры";
Текущий архив: 2004.04.11;
Скачать: [xml.tar.bz2];
ВнизКрестики-нолики Найти похожие ветки
← →
Nvart (2003-12-14 11:27) [0]Доброго времени суток!
Требуется помощь в написании крестиков-ноликов начало есть, а дальше - полный ступор Если кто может - помогите.
В игре должны меняться поля (3x3, 5x5, 10x10), должна быть возможность игры с компьютером и между пользователями.
Заранее бланодарен
← →
Nvart (2003-12-14 11:27) [0]Доброго времени суток!
Требуется помощь в написании крестиков-ноликов начало есть, а дальше - полный ступор Если кто может - помогите.
В игре должны меняться поля (3x3, 5x5, 10x10), должна быть возможность игры с компьютером и между пользователями.
Заранее бланодарен
← →
}{enon © (2003-12-14 16:01) [1]А что кое начало?
1)>должны меняться поля
Отображаешь на экране только левый-верхний кусок поля, в памяти при необходимости можешь держать динамический массив.
2)>должна быть возможность игры с компьютером и между пользователями.
Между пользователями -if usernumber = 1 then pole[cx,cy] := 1 else pole[cx,cy] := 2;
C компьютером аналогично, но нужно писать AI - поиск оптимального хода, что является наиболее трудной частью такой программы.
← →
}{enon © (2003-12-14 16:01) [1]А что кое начало?
1)>должны меняться поля
Отображаешь на экране только левый-верхний кусок поля, в памяти при необходимости можешь держать динамический массив.
2)>должна быть возможность игры с компьютером и между пользователями.
Между пользователями -if usernumber = 1 then pole[cx,cy] := 1 else pole[cx,cy] := 2;
C компьютером аналогично, но нужно писать AI - поиск оптимального хода, что является наиболее трудной частью такой программы.
← →
Vollter © (2003-12-14 19:00) [2]во есть у меня крестики-нолики. правдо, по сети играть. но ты его подредактируй.
← →
Vollter © (2003-12-14 19:00) [2]во есть у меня крестики-нолики. правдо, по сети играть. но ты его подредактируй.
← →
Vollter © (2003-12-14 19:00) [3]клиент
==pas file start==
unit XOclientUnit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ScktComp;
type
TForm1 = class(TForm)
B1: TButton;
B2: TButton;
B3: TButton;
B4: TButton;
B5: TButton;
B6: TButton;
B7: TButton;
B8: TButton;
B9: TButton;
Button10: TButton;
Label1: TLabel;
ClientSocket1: TClientSocket;
Button1: TButton;
Edit1: TEdit;
procedure FormDestroy(Sender: TObject);
procedure Button10Click(Sender: TObject);
procedure B1Click(Sender: TObject);
procedure B2Click(Sender: TObject);
procedure B3Click(Sender: TObject);
procedure B4Click(Sender: TObject);
procedure B5Click(Sender: TObject);
procedure B6Click(Sender: TObject);
procedure B7Click(Sender: TObject);
procedure B8Click(Sender: TObject);
procedure B9Click(Sender: TObject);
procedure ClientSocket1Connect(Sender: TObject;
Socket: TCustomWinSocket);
procedure ClientSocket1Disconnect(Sender: TObject;
Socket: TCustomWinSocket);
procedure Button1Click(Sender: TObject);
procedure ClientSocket1Read(Sender: TObject; Socket: TCustomWinSocket);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
v : Integer;
turn : boolean;
procedure check;
procedure win;
procedure lose;
procedure newgame(sender : ShortString);
implementation
{$R *.DFM}
procedure TForm1.FormDestroy(Sender: TObject);
begin
//Çàêðûòèå
ClientSocket1.Active := False;
ClientSocket1.Close;
end;
procedure check;
begin
//Ïðîâåðêà
If (Form1.B1.Caption = "X") and (Form1.B2.Caption = "X") and (Form1.B3.Caption = "X") then win;
If (Form1.B1.Caption = "X") and (Form1.B4.Caption = "X") and (Form1.B7.Caption = "X") then win;
If (Form1.B3.Caption = "X") and (Form1.B6.Caption = "X") and (Form1.B9.Caption = "X") then win;
If (Form1.B7.Caption = "X") and (Form1.B8.Caption = "X") and (Form1.B9.Caption = "X") then win;
If (Form1.B2.Caption = "X") and (Form1.B5.Caption = "X") and (Form1.B8.Caption = "X") then win;
If (Form1.B4.Caption = "X") and (Form1.B5.Caption = "X") and (Form1.B6.Caption = "X") then win;
If (Form1.B1.Caption = "X") and (Form1.B5.Caption = "X") and (Form1.B9.Caption = "X") then win;
If (Form1.B7.Caption = "X") and (Form1.B5.Caption = "X") and (Form1.B3.Caption = "X") then win;
If (Form1.B1.Caption = "O") and (Form1.B2.Caption = "O") and (Form1.B3.Caption = "O") then lose;
If (Form1.B1.Caption = "O") and (Form1.B4.Caption = "O") and (Form1.B7.Caption = "O") then lose;
If (Form1.B3.Caption = "O") and (Form1.B6.Caption = "O") and (Form1.B9.Caption = "O") then lose;
If (Form1.B7.Caption = "O") and (Form1.B8.Caption = "O") and (Form1.B9.Caption = "O") then lose;
If (Form1.B2.Caption = "O") and (Form1.B5.Caption = "O") and (Form1.B8.Caption = "O") then lose;
If (Form1.B4.Caption = "O") and (Form1.B5.Caption = "O") and (Form1.B6.Caption = "O") then lose;
If (Form1.B1.Caption = "O") and (Form1.B5.Caption = "O") and (Form1.B9.Caption = "O") then lose;
If (Form1.B7.Caption = "O") and (Form1.B5.Caption = "O") and (Form1.B3.Caption = "O") then lose;
end;
procedure win;
begin
//Ìû âûãðàëè
MessageBeep(MB_ICONASTERISK);
ShowMessage("You win!");
Form1.B1.Enabled := False;
Form1.B2.Enabled := False;
Form1.B3.Enabled := False;
Form1.B4.Enabled := False;
Form1.B5.Enabled := False;
Form1.B6.Enabled := False;
Form1.B7.Enabled := False;
Form1.B8.Enabled := False;
Form1.B9.Enabled := False;
end;
procedure lose;
begin
//Ìû ïðîèãðàëè
MessageBeep(MB_ICONHAND);
ShowMessage("You lose");
Form1.B1.Enabled := False;
Form1.B2.Enabled := False;
Form1.B3.Enabled := False;
Form1.B4.Enabled := False;
Form1.B5.Enabled := False;
Form1.B6.Enabled := False;
Form1.B7.Enabled := False;
Form1.B8.Enabled := False;
Form1.B9.Enabled := False;
end;
procedure TForm1.Button10Click(Sender: TObject);
begin
//Íîâàÿ èãðà
newgame("client");
end;
procedure TForm1.B1Click(Sender: TObject);
begin
//Ïðîâåðÿåì åñëè íàø õîä, òî ñòàâèì êðåñòèê, ïîñûëàåì ñîîáùåíèå è äåëàåì ïðîâåðêó
If turn then begin
turn := false;
B1.Caption := "X";
B1.Enabled := False;
ClientSocket1.Socket.SendText("1");
check;
end;
end;
procedure TForm1.B2Click(Sender: TObject);
begin
//Ïðîâåðÿåì åñëè íàø õîä, òî ñòàâèì êðåñòèê, ïîñûëàåì ñîîáùåíèå è äåëàåì ïðîâåðêó
If turn then begin
turn := false;
B2.Caption := "X";
B2.Enabled := False;
ClientSocket1.Socket.SendText("2");
check;
end;
end;
procedure TForm1.B3Click(Sender: TObject);
begin
//Ïðîâåðÿåì åñëè íàø õîä, òî ñòàâèì êðåñòèê, ïîñûëàåì ñîîáùåíèå è äåëàåì ïðîâåðêó
If turn then begin
turn := false;
B3.Caption := "X";
B3.Enabled := False;
ClientSocket1.Socket.SendText("3");
check;
end;
end;
← →
Vollter © (2003-12-14 19:00) [3]клиент
==pas file start==
unit XOclientUnit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ScktComp;
type
TForm1 = class(TForm)
B1: TButton;
B2: TButton;
B3: TButton;
B4: TButton;
B5: TButton;
B6: TButton;
B7: TButton;
B8: TButton;
B9: TButton;
Button10: TButton;
Label1: TLabel;
ClientSocket1: TClientSocket;
Button1: TButton;
Edit1: TEdit;
procedure FormDestroy(Sender: TObject);
procedure Button10Click(Sender: TObject);
procedure B1Click(Sender: TObject);
procedure B2Click(Sender: TObject);
procedure B3Click(Sender: TObject);
procedure B4Click(Sender: TObject);
procedure B5Click(Sender: TObject);
procedure B6Click(Sender: TObject);
procedure B7Click(Sender: TObject);
procedure B8Click(Sender: TObject);
procedure B9Click(Sender: TObject);
procedure ClientSocket1Connect(Sender: TObject;
Socket: TCustomWinSocket);
procedure ClientSocket1Disconnect(Sender: TObject;
Socket: TCustomWinSocket);
procedure Button1Click(Sender: TObject);
procedure ClientSocket1Read(Sender: TObject; Socket: TCustomWinSocket);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
v : Integer;
turn : boolean;
procedure check;
procedure win;
procedure lose;
procedure newgame(sender : ShortString);
implementation
{$R *.DFM}
procedure TForm1.FormDestroy(Sender: TObject);
begin
//Çàêðûòèå
ClientSocket1.Active := False;
ClientSocket1.Close;
end;
procedure check;
begin
//Ïðîâåðêà
If (Form1.B1.Caption = "X") and (Form1.B2.Caption = "X") and (Form1.B3.Caption = "X") then win;
If (Form1.B1.Caption = "X") and (Form1.B4.Caption = "X") and (Form1.B7.Caption = "X") then win;
If (Form1.B3.Caption = "X") and (Form1.B6.Caption = "X") and (Form1.B9.Caption = "X") then win;
If (Form1.B7.Caption = "X") and (Form1.B8.Caption = "X") and (Form1.B9.Caption = "X") then win;
If (Form1.B2.Caption = "X") and (Form1.B5.Caption = "X") and (Form1.B8.Caption = "X") then win;
If (Form1.B4.Caption = "X") and (Form1.B5.Caption = "X") and (Form1.B6.Caption = "X") then win;
If (Form1.B1.Caption = "X") and (Form1.B5.Caption = "X") and (Form1.B9.Caption = "X") then win;
If (Form1.B7.Caption = "X") and (Form1.B5.Caption = "X") and (Form1.B3.Caption = "X") then win;
If (Form1.B1.Caption = "O") and (Form1.B2.Caption = "O") and (Form1.B3.Caption = "O") then lose;
If (Form1.B1.Caption = "O") and (Form1.B4.Caption = "O") and (Form1.B7.Caption = "O") then lose;
If (Form1.B3.Caption = "O") and (Form1.B6.Caption = "O") and (Form1.B9.Caption = "O") then lose;
If (Form1.B7.Caption = "O") and (Form1.B8.Caption = "O") and (Form1.B9.Caption = "O") then lose;
If (Form1.B2.Caption = "O") and (Form1.B5.Caption = "O") and (Form1.B8.Caption = "O") then lose;
If (Form1.B4.Caption = "O") and (Form1.B5.Caption = "O") and (Form1.B6.Caption = "O") then lose;
If (Form1.B1.Caption = "O") and (Form1.B5.Caption = "O") and (Form1.B9.Caption = "O") then lose;
If (Form1.B7.Caption = "O") and (Form1.B5.Caption = "O") and (Form1.B3.Caption = "O") then lose;
end;
procedure win;
begin
//Ìû âûãðàëè
MessageBeep(MB_ICONASTERISK);
ShowMessage("You win!");
Form1.B1.Enabled := False;
Form1.B2.Enabled := False;
Form1.B3.Enabled := False;
Form1.B4.Enabled := False;
Form1.B5.Enabled := False;
Form1.B6.Enabled := False;
Form1.B7.Enabled := False;
Form1.B8.Enabled := False;
Form1.B9.Enabled := False;
end;
procedure lose;
begin
//Ìû ïðîèãðàëè
MessageBeep(MB_ICONHAND);
ShowMessage("You lose");
Form1.B1.Enabled := False;
Form1.B2.Enabled := False;
Form1.B3.Enabled := False;
Form1.B4.Enabled := False;
Form1.B5.Enabled := False;
Form1.B6.Enabled := False;
Form1.B7.Enabled := False;
Form1.B8.Enabled := False;
Form1.B9.Enabled := False;
end;
procedure TForm1.Button10Click(Sender: TObject);
begin
//Íîâàÿ èãðà
newgame("client");
end;
procedure TForm1.B1Click(Sender: TObject);
begin
//Ïðîâåðÿåì åñëè íàø õîä, òî ñòàâèì êðåñòèê, ïîñûëàåì ñîîáùåíèå è äåëàåì ïðîâåðêó
If turn then begin
turn := false;
B1.Caption := "X";
B1.Enabled := False;
ClientSocket1.Socket.SendText("1");
check;
end;
end;
procedure TForm1.B2Click(Sender: TObject);
begin
//Ïðîâåðÿåì åñëè íàø õîä, òî ñòàâèì êðåñòèê, ïîñûëàåì ñîîáùåíèå è äåëàåì ïðîâåðêó
If turn then begin
turn := false;
B2.Caption := "X";
B2.Enabled := False;
ClientSocket1.Socket.SendText("2");
check;
end;
end;
procedure TForm1.B3Click(Sender: TObject);
begin
//Ïðîâåðÿåì åñëè íàø õîä, òî ñòàâèì êðåñòèê, ïîñûëàåì ñîîáùåíèå è äåëàåì ïðîâåðêó
If turn then begin
turn := false;
B3.Caption := "X";
B3.Enabled := False;
ClientSocket1.Socket.SendText("3");
check;
end;
end;
← →
Vollter © (2003-12-14 19:01) [4]procedure TForm1.B4Click(Sender: TObject);
begin
//Ïðîâåðÿåì åñëè íàø õîä, òî ñòàâèì êðåñòèê, ïîñûëàåì ñîîáùåíèå è äåëàåì ïðîâåðêó
If turn then begin
turn := false;
B4.Caption := "X";
B4.Enabled := False;
ClientSocket1.Socket.SendText("4");
check;
end;
end;
procedure TForm1.B5Click(Sender: TObject);
begin
//Ïðîâåðÿåì åñëè íàø õîä, òî ñòàâèì êðåñòèê, ïîñûëàåì ñîîáùåíèå è äåëàåì ïðîâåðêó
If turn then begin
turn := false;
B5.Caption := "X";
B5.Enabled := False;
ClientSocket1.Socket.SendText("5");
check;
end;
end;
procedure TForm1.B6Click(Sender: TObject);
begin
//Ïðîâåðÿåì åñëè íàø õîä, òî ñòàâèì êðåñòèê, ïîñûëàåì ñîîáùåíèå è äåëàåì ïðîâåðêó
If turn then begin
turn := false;
B6.Caption := "X";
B6.Enabled := False;
ClientSocket1.Socket.SendText("6");
check;
end;
end;
procedure TForm1.B7Click(Sender: TObject);
begin
//Ïðîâåðÿåì åñëè íàø õîä, òî ñòàâèì êðåñòèê, ïîñûëàåì ñîîáùåíèå è äåëàåì ïðîâåðêó
If turn then begin
turn := false;
B7.Caption := "X";
B7.Enabled := False;
ClientSocket1.Socket.SendText("7");
check;
end;
end;
procedure TForm1.B8Click(Sender: TObject);
begin
//Ïðîâåðÿåì åñëè íàø õîä, òî ñòàâèì êðåñòèê, ïîñûëàåì ñîîáùåíèå è äåëàåì ïðîâåðêó
If turn then begin
turn := false;
B8.Caption := "X";
B8.Enabled := False;
ClientSocket1.Socket.SendText("8");
check;
end;
end;
procedure TForm1.B9Click(Sender: TObject);
begin
//Ïðîâåðÿåì åñëè íàø õîä, òî ñòàâèì êðåñòèê, ïîñûëàåì ñîîáùåíèå è äåëàåì ïðîâåðêó
If turn then begin
turn := false;
B9.Caption := "X";
B9.Enabled := false;
ClientSocket1.Socket.SendText("9");
check;
end;
end;
procedure TForm1.ClientSocket1Connect(Sender: TObject;
Socket: TCustomWinSocket);
begin
//Ñîåäèíåíèå
Label1.Caption := "Connected";
Button10.Enabled := True;
end;
procedure TForm1.ClientSocket1Disconnect(Sender: TObject;
Socket: TCustomWinSocket);
begin
//Ðàçðûâ ñâÿçè
Label1.Caption := "Disconnected";
Button10.Enabled := False;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
//Ñîåäèíåíèå
ClientSocket1.Address := Edit1.Text;
If not ClientSocket1.Active then ClientSocket1.Active := True;
end;
procedure TForm1.ClientSocket1Read(Sender: TObject;
Socket: TCustomWinSocket);
begin
//Ïðîâåðêà ïðèøåäøåãî ñîîáùåíèå
v := StrToInt(Socket.ReceiveText);
case v of
0 : begin newgame("server"); end; //Íîâàÿ èãðà
//Õîä ïðîòèâíîêà
1 : begin turn := true; B1.Caption := "O"; B1.Enabled := False; check; end;
2 : begin turn := true; B2.Caption := "O"; B2.Enabled := False; check; end;
3 : begin turn := true; B3.Caption := "O"; B3.Enabled := False; check; end;
4 : begin turn := true; B4.Caption := "O"; B4.Enabled := False; check; end;
5 : begin turn := true; B5.Caption := "O"; B5.Enabled := False; check; end;
6 : begin turn := true; B6.Caption := "O"; B6.Enabled := False; check; end;
7 : begin turn := true; B7.Caption := "O"; B7.Enabled := False; check; end;
8 : begin turn := true; B8.Caption := "O"; B8.Enabled := False; check; end;
9 : begin turn := true; B9.Caption := "O"; B9.Enabled := False; check; end;
end;
end;
procedure newgame(sender : ShortString);
begin
//Íîâàÿ èãðà
turn := true;
If sender = "client" then Form1.ClientSocket1.Socket.SendText("0")
else ShowMessage("Server begin new game");
//Î÷èñòêà êíîïîê
Form1.B1.Caption := "";
Form1.B1.Enabled := True;
Form1.B2.Caption := "";
Form1.B2.Enabled := True;
Form1.B3.Caption := "";
Form1.B3.Enabled := True;
Form1.B4.Caption := "";
Form1.B4.Enabled := True;
Form1.B5.Caption := "";
Form1.B5.Enabled := True;
Form1.B6.Caption := "";
Form1.B6.Enabled := True;
Form1.B7.Caption := "";
Form1.B7.Enabled := True;
Form1.B8.Caption := "";
Form1.B8.Enabled := True;
Form1.B9.Caption := "";
Form1.B9.Enabled := True;
end;
end.
==pas file end==
← →
Vollter © (2003-12-14 19:01) [4]procedure TForm1.B4Click(Sender: TObject);
begin
//Ïðîâåðÿåì åñëè íàø õîä, òî ñòàâèì êðåñòèê, ïîñûëàåì ñîîáùåíèå è äåëàåì ïðîâåðêó
If turn then begin
turn := false;
B4.Caption := "X";
B4.Enabled := False;
ClientSocket1.Socket.SendText("4");
check;
end;
end;
procedure TForm1.B5Click(Sender: TObject);
begin
//Ïðîâåðÿåì åñëè íàø õîä, òî ñòàâèì êðåñòèê, ïîñûëàåì ñîîáùåíèå è äåëàåì ïðîâåðêó
If turn then begin
turn := false;
B5.Caption := "X";
B5.Enabled := False;
ClientSocket1.Socket.SendText("5");
check;
end;
end;
procedure TForm1.B6Click(Sender: TObject);
begin
//Ïðîâåðÿåì åñëè íàø õîä, òî ñòàâèì êðåñòèê, ïîñûëàåì ñîîáùåíèå è äåëàåì ïðîâåðêó
If turn then begin
turn := false;
B6.Caption := "X";
B6.Enabled := False;
ClientSocket1.Socket.SendText("6");
check;
end;
end;
procedure TForm1.B7Click(Sender: TObject);
begin
//Ïðîâåðÿåì åñëè íàø õîä, òî ñòàâèì êðåñòèê, ïîñûëàåì ñîîáùåíèå è äåëàåì ïðîâåðêó
If turn then begin
turn := false;
B7.Caption := "X";
B7.Enabled := False;
ClientSocket1.Socket.SendText("7");
check;
end;
end;
procedure TForm1.B8Click(Sender: TObject);
begin
//Ïðîâåðÿåì åñëè íàø õîä, òî ñòàâèì êðåñòèê, ïîñûëàåì ñîîáùåíèå è äåëàåì ïðîâåðêó
If turn then begin
turn := false;
B8.Caption := "X";
B8.Enabled := False;
ClientSocket1.Socket.SendText("8");
check;
end;
end;
procedure TForm1.B9Click(Sender: TObject);
begin
//Ïðîâåðÿåì åñëè íàø õîä, òî ñòàâèì êðåñòèê, ïîñûëàåì ñîîáùåíèå è äåëàåì ïðîâåðêó
If turn then begin
turn := false;
B9.Caption := "X";
B9.Enabled := false;
ClientSocket1.Socket.SendText("9");
check;
end;
end;
procedure TForm1.ClientSocket1Connect(Sender: TObject;
Socket: TCustomWinSocket);
begin
//Ñîåäèíåíèå
Label1.Caption := "Connected";
Button10.Enabled := True;
end;
procedure TForm1.ClientSocket1Disconnect(Sender: TObject;
Socket: TCustomWinSocket);
begin
//Ðàçðûâ ñâÿçè
Label1.Caption := "Disconnected";
Button10.Enabled := False;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
//Ñîåäèíåíèå
ClientSocket1.Address := Edit1.Text;
If not ClientSocket1.Active then ClientSocket1.Active := True;
end;
procedure TForm1.ClientSocket1Read(Sender: TObject;
Socket: TCustomWinSocket);
begin
//Ïðîâåðêà ïðèøåäøåãî ñîîáùåíèå
v := StrToInt(Socket.ReceiveText);
case v of
0 : begin newgame("server"); end; //Íîâàÿ èãðà
//Õîä ïðîòèâíîêà
1 : begin turn := true; B1.Caption := "O"; B1.Enabled := False; check; end;
2 : begin turn := true; B2.Caption := "O"; B2.Enabled := False; check; end;
3 : begin turn := true; B3.Caption := "O"; B3.Enabled := False; check; end;
4 : begin turn := true; B4.Caption := "O"; B4.Enabled := False; check; end;
5 : begin turn := true; B5.Caption := "O"; B5.Enabled := False; check; end;
6 : begin turn := true; B6.Caption := "O"; B6.Enabled := False; check; end;
7 : begin turn := true; B7.Caption := "O"; B7.Enabled := False; check; end;
8 : begin turn := true; B8.Caption := "O"; B8.Enabled := False; check; end;
9 : begin turn := true; B9.Caption := "O"; B9.Enabled := False; check; end;
end;
end;
procedure newgame(sender : ShortString);
begin
//Íîâàÿ èãðà
turn := true;
If sender = "client" then Form1.ClientSocket1.Socket.SendText("0")
else ShowMessage("Server begin new game");
//Î÷èñòêà êíîïîê
Form1.B1.Caption := "";
Form1.B1.Enabled := True;
Form1.B2.Caption := "";
Form1.B2.Enabled := True;
Form1.B3.Caption := "";
Form1.B3.Enabled := True;
Form1.B4.Caption := "";
Form1.B4.Enabled := True;
Form1.B5.Caption := "";
Form1.B5.Enabled := True;
Form1.B6.Caption := "";
Form1.B6.Enabled := True;
Form1.B7.Caption := "";
Form1.B7.Enabled := True;
Form1.B8.Caption := "";
Form1.B8.Enabled := True;
Form1.B9.Caption := "";
Form1.B9.Enabled := True;
end;
end.
==pas file end==
← →
Vollter © (2003-12-14 19:03) [5]сервер
==server pas file start==
unit XOUnit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ScktComp;
type
TForm1 = class(TForm)
ServerSocket1: TServerSocket;
B1: TButton;
B2: TButton;
B3: TButton;
B4: TButton;
B5: TButton;
B6: TButton;
B7: TButton;
B8: TButton;
B9: TButton;
Button10: TButton;
Label1: TLabel;
procedure ServerSocket1ClientConnect(Sender: TObject;
Socket: TCustomWinSocket);
procedure ServerSocket1ClientDisconnect(Sender: TObject;
Socket: TCustomWinSocket);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Button10Click(Sender: TObject);
procedure B1Click(Sender: TObject);
procedure B2Click(Sender: TObject);
procedure B3Click(Sender: TObject);
procedure B4Click(Sender: TObject);
procedure B5Click(Sender: TObject);
procedure B6Click(Sender: TObject);
procedure B7Click(Sender: TObject);
procedure B8Click(Sender: TObject);
procedure B9Click(Sender: TObject);
procedure ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
private
procedure newgame(sender : ShortString);
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
v, temp : Integer;
turn : Boolean;
procedure check;
procedure win;
procedure lose;
implementation
{$R *.DFM}
procedure TForm1.ServerSocket1ClientConnect(Sender: TObject;
Socket: TCustomWinSocket);
begin
//Ñîåäèíåíèå ñ êëèåíòîì
Label1.Caption := "Connected";
Button10.Enabled := True;
end;
procedure TForm1.ServerSocket1ClientDisconnect(Sender: TObject;
Socket: TCustomWinSocket);
begin
//Êëèåíò îòñîåäèíèëñÿ
Label1.Caption := "Disconnected";
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
//Àêòèâèçàöèÿ ñåðâåðà
ServerSocket1.Active := true;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
//Çàêðûòèå
ServerSocket1.Active := False;
ServerSocket1.Close;
end;
procedure check;
begin
//Ïðîâåðêà âûãðàë ëè êòî
If (Form1.B1.Caption = "X") and (Form1.B2.Caption = "X") and (Form1.B3.Caption = "X") then win;
If (Form1.B1.Caption = "X") and (Form1.B4.Caption = "X") and (Form1.B7.Caption = "X") then win;
If (Form1.B3.Caption = "X") and (Form1.B6.Caption = "X") and (Form1.B9.Caption = "X") then win;
If (Form1.B7.Caption = "X") and (Form1.B8.Caption = "X") and (Form1.B9.Caption = "X") then win;
If (Form1.B2.Caption = "X") and (Form1.B5.Caption = "X") and (Form1.B8.Caption = "X") then win;
If (Form1.B4.Caption = "X") and (Form1.B5.Caption = "X") and (Form1.B6.Caption = "X") then win;
If (Form1.B1.Caption = "X") and (Form1.B5.Caption = "X") and (Form1.B9.Caption = "X") then win;
If (Form1.B7.Caption = "X") and (Form1.B5.Caption = "X") and (Form1.B3.Caption = "X") then win;
If (Form1.B1.Caption = "O") and (Form1.B2.Caption = "O") and (Form1.B3.Caption = "O") then lose;
If (Form1.B1.Caption = "O") and (Form1.B4.Caption = "O") and (Form1.B7.Caption = "O") then lose;
If (Form1.B3.Caption = "O") and (Form1.B6.Caption = "O") and (Form1.B9.Caption = "O") then lose;
If (Form1.B7.Caption = "O") and (Form1.B8.Caption = "O") and (Form1.B9.Caption = "O") then lose;
If (Form1.B2.Caption = "O") and (Form1.B5.Caption = "O") and (Form1.B8.Caption = "O") then lose;
If (Form1.B4.Caption = "O") and (Form1.B5.Caption = "O") and (Form1.B6.Caption = "O") then lose;
If (Form1.B1.Caption = "O") and (Form1.B5.Caption = "O") and (Form1.B9.Caption = "O") then lose;
If (Form1.B7.Caption = "O") and (Form1.B5.Caption = "O") and (Form1.B3.Caption = "O") then lose;
end;
procedure win;
begin
//Âûãðàëè ìû
MessageBeep(MB_ICONASTERISK);
ShowMessage("You win!");
//Îòêëþ÷åíèå êíîïîê
Form1.B1.Enabled := False;
Form1.B2.Enabled := False;
Form1.B3.Enabled := False;
Form1.B4.Enabled := False;
Form1.B5.Enabled := False;
Form1.B6.Enabled := False;
Form1.B7.Enabled := False;
Form1.B8.Enabled := False;
Form1.B9.Enabled := False;
end;
procedure lose;
begin
//Ìû ïðîèãðàëè
MessageBeep(MB_ICONHAND);
ShowMessage("You lose");
//Îòêëþ÷åíèå êíîïîê
Form1.B1.Enabled := False;
Form1.B2.Enabled := False;
Form1.B3.Enabled := False;
Form1.B4.Enabled := False;
Form1.B5.Enabled := False;
Form1.B6.Enabled := False;
Form1.B7.Enabled := False;
Form1.B8.Enabled := False;
Form1.B9.Enabled := False;
end;
procedure TForm1.Button10Click(Sender: TObject);
begin
//Íîâàÿ èãðà
newgame("server");
end;
procedure TForm1.B1Click(Sender: TObject);
begin
//Åñëè íàø õîä, òî ñòàâèì êðåñòèê, ïåðåäàåì õîä è äåëàåì ïðîâåðêó
If turn then begin
turn := false;
B1.Caption := "X";
B1.Enabled := False;
ServerSocket1.Socket.Connections[0].SendText("1");
check;
end;
end;
← →
Vollter © (2003-12-14 19:03) [5]сервер
==server pas file start==
unit XOUnit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ScktComp;
type
TForm1 = class(TForm)
ServerSocket1: TServerSocket;
B1: TButton;
B2: TButton;
B3: TButton;
B4: TButton;
B5: TButton;
B6: TButton;
B7: TButton;
B8: TButton;
B9: TButton;
Button10: TButton;
Label1: TLabel;
procedure ServerSocket1ClientConnect(Sender: TObject;
Socket: TCustomWinSocket);
procedure ServerSocket1ClientDisconnect(Sender: TObject;
Socket: TCustomWinSocket);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Button10Click(Sender: TObject);
procedure B1Click(Sender: TObject);
procedure B2Click(Sender: TObject);
procedure B3Click(Sender: TObject);
procedure B4Click(Sender: TObject);
procedure B5Click(Sender: TObject);
procedure B6Click(Sender: TObject);
procedure B7Click(Sender: TObject);
procedure B8Click(Sender: TObject);
procedure B9Click(Sender: TObject);
procedure ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
private
procedure newgame(sender : ShortString);
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
v, temp : Integer;
turn : Boolean;
procedure check;
procedure win;
procedure lose;
implementation
{$R *.DFM}
procedure TForm1.ServerSocket1ClientConnect(Sender: TObject;
Socket: TCustomWinSocket);
begin
//Ñîåäèíåíèå ñ êëèåíòîì
Label1.Caption := "Connected";
Button10.Enabled := True;
end;
procedure TForm1.ServerSocket1ClientDisconnect(Sender: TObject;
Socket: TCustomWinSocket);
begin
//Êëèåíò îòñîåäèíèëñÿ
Label1.Caption := "Disconnected";
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
//Àêòèâèçàöèÿ ñåðâåðà
ServerSocket1.Active := true;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
//Çàêðûòèå
ServerSocket1.Active := False;
ServerSocket1.Close;
end;
procedure check;
begin
//Ïðîâåðêà âûãðàë ëè êòî
If (Form1.B1.Caption = "X") and (Form1.B2.Caption = "X") and (Form1.B3.Caption = "X") then win;
If (Form1.B1.Caption = "X") and (Form1.B4.Caption = "X") and (Form1.B7.Caption = "X") then win;
If (Form1.B3.Caption = "X") and (Form1.B6.Caption = "X") and (Form1.B9.Caption = "X") then win;
If (Form1.B7.Caption = "X") and (Form1.B8.Caption = "X") and (Form1.B9.Caption = "X") then win;
If (Form1.B2.Caption = "X") and (Form1.B5.Caption = "X") and (Form1.B8.Caption = "X") then win;
If (Form1.B4.Caption = "X") and (Form1.B5.Caption = "X") and (Form1.B6.Caption = "X") then win;
If (Form1.B1.Caption = "X") and (Form1.B5.Caption = "X") and (Form1.B9.Caption = "X") then win;
If (Form1.B7.Caption = "X") and (Form1.B5.Caption = "X") and (Form1.B3.Caption = "X") then win;
If (Form1.B1.Caption = "O") and (Form1.B2.Caption = "O") and (Form1.B3.Caption = "O") then lose;
If (Form1.B1.Caption = "O") and (Form1.B4.Caption = "O") and (Form1.B7.Caption = "O") then lose;
If (Form1.B3.Caption = "O") and (Form1.B6.Caption = "O") and (Form1.B9.Caption = "O") then lose;
If (Form1.B7.Caption = "O") and (Form1.B8.Caption = "O") and (Form1.B9.Caption = "O") then lose;
If (Form1.B2.Caption = "O") and (Form1.B5.Caption = "O") and (Form1.B8.Caption = "O") then lose;
If (Form1.B4.Caption = "O") and (Form1.B5.Caption = "O") and (Form1.B6.Caption = "O") then lose;
If (Form1.B1.Caption = "O") and (Form1.B5.Caption = "O") and (Form1.B9.Caption = "O") then lose;
If (Form1.B7.Caption = "O") and (Form1.B5.Caption = "O") and (Form1.B3.Caption = "O") then lose;
end;
procedure win;
begin
//Âûãðàëè ìû
MessageBeep(MB_ICONASTERISK);
ShowMessage("You win!");
//Îòêëþ÷åíèå êíîïîê
Form1.B1.Enabled := False;
Form1.B2.Enabled := False;
Form1.B3.Enabled := False;
Form1.B4.Enabled := False;
Form1.B5.Enabled := False;
Form1.B6.Enabled := False;
Form1.B7.Enabled := False;
Form1.B8.Enabled := False;
Form1.B9.Enabled := False;
end;
procedure lose;
begin
//Ìû ïðîèãðàëè
MessageBeep(MB_ICONHAND);
ShowMessage("You lose");
//Îòêëþ÷åíèå êíîïîê
Form1.B1.Enabled := False;
Form1.B2.Enabled := False;
Form1.B3.Enabled := False;
Form1.B4.Enabled := False;
Form1.B5.Enabled := False;
Form1.B6.Enabled := False;
Form1.B7.Enabled := False;
Form1.B8.Enabled := False;
Form1.B9.Enabled := False;
end;
procedure TForm1.Button10Click(Sender: TObject);
begin
//Íîâàÿ èãðà
newgame("server");
end;
procedure TForm1.B1Click(Sender: TObject);
begin
//Åñëè íàø õîä, òî ñòàâèì êðåñòèê, ïåðåäàåì õîä è äåëàåì ïðîâåðêó
If turn then begin
turn := false;
B1.Caption := "X";
B1.Enabled := False;
ServerSocket1.Socket.Connections[0].SendText("1");
check;
end;
end;
← →
Vollter © (2003-12-14 19:04) [6]procedure TForm1.B2Click(Sender: TObject);
begin
//Åñëè íàø õîä, òî ñòàâèì êðåñòèê, ïåðåäàåì õîä è äåëàåì ïðîâåðêó
If turn then begin
turn := false;
B2.Caption := "X";
B2.Enabled := False;
ServerSocket1.Socket.Connections[0].SendText("2");
check;
end;
end;
procedure TForm1.B3Click(Sender: TObject);
begin
//Åñëè íàø õîä, òî ñòàâèì êðåñòèê, ïåðåäàåì õîä è äåëàåì ïðîâåðêó
If turn then begin
turn := false;
B3.Caption := "X";
B3.Enabled := False;
ServerSocket1.Socket.Connections[0].SendText("3");
check;
end;
end;
procedure TForm1.B4Click(Sender: TObject);
begin
//Åñëè íàø õîä, òî ñòàâèì êðåñòèê, ïåðåäàåì õîä è äåëàåì ïðîâåðêó
If turn then begin
turn := false;
B4.Caption := "X";
B4.Enabled := False;
ServerSocket1.Socket.Connections[0].SendText("4");
check;
end;
end;
procedure TForm1.B5Click(Sender: TObject);
begin
//Åñëè íàø õîä, òî ñòàâèì êðåñòèê, ïåðåäàåì õîä è äåëàåì ïðîâåðêó
If turn then begin
turn := false;
B5.Caption := "X";
B5.Enabled := False;
ServerSocket1.Socket.Connections[0].SendText("5");
check;
end;
end;
procedure TForm1.B6Click(Sender: TObject);
begin
//Åñëè íàø õîä, òî ñòàâèì êðåñòèê, ïåðåäàåì õîä è äåëàåì ïðîâåðêó
If turn then begin
turn := false;
B6.Caption := "X";
B6.Enabled := False;
ServerSocket1.Socket.Connections[0].SendText("6");
check;
end;
end;
procedure TForm1.B7Click(Sender: TObject);
begin
//Åñëè íàø õîä, òî ñòàâèì êðåñòèê, ïåðåäàåì õîä è äåëàåì ïðîâåðêó
If turn then begin
turn := false;
B7.Caption := "X";
B7.Enabled := False;
ServerSocket1.Socket.Connections[0].SendText("7");
check;
end;
end;
procedure TForm1.B8Click(Sender: TObject);
begin
//Åñëè íàø õîä, òî ñòàâèì êðåñòèê, ïåðåäàåì õîä è äåëàåì ïðîâåðêó
If turn then begin
turn := false;
B8.Caption := "X";
B8.Enabled := False;
ServerSocket1.Socket.Connections[0].SendText("8");
check;
end;
end;
procedure TForm1.B9Click(Sender: TObject);
begin
//Åñëè íàø õîä, òî ñòàâèì êðåñòèê, ïåðåäàåì õîä è äåëàåì ïðîâåðêó
If turn then begin
turn := false;
B9.Caption := "X";
B9.Enabled := False;
ServerSocket1.Socket.Connections[0].SendText("9");
check;
end;
end;
procedure TForm1.ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
begin
//Ïðîâåðÿåì ïðèøåäøåå ñîîáùåíèå
v := StrToInt(Socket.ReceiveText);
case v of
0 : begin ShowMessage("Clien begin new game"); button10click(Sender); end; // Íîâàÿ èãðà
// Õîä ïðîòèâíèêà
1 : begin turn := true; B1.Caption := "O"; B1.Enabled := False; check; end;
2 : begin turn := true; B2.Caption := "O"; B2.Enabled := False; check; end;
3 : begin turn := true; B3.Caption := "O"; B3.Enabled := False; check; end;
4 : begin turn := true; B4.Caption := "O"; B4.Enabled := False; check; end;
5 : begin turn := true; B5.Caption := "O"; B5.Enabled := False; check; end;
6 : begin turn := true; B6.Caption := "O"; B6.Enabled := False; check; end;
7 : begin turn := true; B7.Caption := "O"; B7.Enabled := False; check; end;
8 : begin turn := true; B8.Caption := "O"; B8.Enabled := False; check; end;
9 : begin turn := true; B9.Caption := "O"; B9.Enabled := False; check; end;
end;
end;
procedure TForm1.newgame(sender: ShortString);
begin
//Íîâàÿ èãðà
turn := false;
If sender = "server" then ServerSocket1.Socket.Connections[0].SendText("0")
else ShowMessage("Client begin new game");
//Î÷èùàåì êíîïêè
B1.Caption := "";
B1.Enabled := True;
B2.Caption := "";
B2.Enabled := True;
B3.Caption := "";
B3.Enabled := True;
B4.Caption := "";
B4.Enabled := True;
B5.Caption := "";
B5.Enabled := True;
B6.Caption := "";
B6.Enabled := True;
B7.Caption := "";
B7.Enabled := True;
B8.Caption := "";
B8.Enabled := True;
B9.Caption := "";
B9.Enabled := True;
end;
end.
==server pas file end==
← →
Vollter © (2003-12-14 19:04) [6]procedure TForm1.B2Click(Sender: TObject);
begin
//Åñëè íàø õîä, òî ñòàâèì êðåñòèê, ïåðåäàåì õîä è äåëàåì ïðîâåðêó
If turn then begin
turn := false;
B2.Caption := "X";
B2.Enabled := False;
ServerSocket1.Socket.Connections[0].SendText("2");
check;
end;
end;
procedure TForm1.B3Click(Sender: TObject);
begin
//Åñëè íàø õîä, òî ñòàâèì êðåñòèê, ïåðåäàåì õîä è äåëàåì ïðîâåðêó
If turn then begin
turn := false;
B3.Caption := "X";
B3.Enabled := False;
ServerSocket1.Socket.Connections[0].SendText("3");
check;
end;
end;
procedure TForm1.B4Click(Sender: TObject);
begin
//Åñëè íàø õîä, òî ñòàâèì êðåñòèê, ïåðåäàåì õîä è äåëàåì ïðîâåðêó
If turn then begin
turn := false;
B4.Caption := "X";
B4.Enabled := False;
ServerSocket1.Socket.Connections[0].SendText("4");
check;
end;
end;
procedure TForm1.B5Click(Sender: TObject);
begin
//Åñëè íàø õîä, òî ñòàâèì êðåñòèê, ïåðåäàåì õîä è äåëàåì ïðîâåðêó
If turn then begin
turn := false;
B5.Caption := "X";
B5.Enabled := False;
ServerSocket1.Socket.Connections[0].SendText("5");
check;
end;
end;
procedure TForm1.B6Click(Sender: TObject);
begin
//Åñëè íàø õîä, òî ñòàâèì êðåñòèê, ïåðåäàåì õîä è äåëàåì ïðîâåðêó
If turn then begin
turn := false;
B6.Caption := "X";
B6.Enabled := False;
ServerSocket1.Socket.Connections[0].SendText("6");
check;
end;
end;
procedure TForm1.B7Click(Sender: TObject);
begin
//Åñëè íàø õîä, òî ñòàâèì êðåñòèê, ïåðåäàåì õîä è äåëàåì ïðîâåðêó
If turn then begin
turn := false;
B7.Caption := "X";
B7.Enabled := False;
ServerSocket1.Socket.Connections[0].SendText("7");
check;
end;
end;
procedure TForm1.B8Click(Sender: TObject);
begin
//Åñëè íàø õîä, òî ñòàâèì êðåñòèê, ïåðåäàåì õîä è äåëàåì ïðîâåðêó
If turn then begin
turn := false;
B8.Caption := "X";
B8.Enabled := False;
ServerSocket1.Socket.Connections[0].SendText("8");
check;
end;
end;
procedure TForm1.B9Click(Sender: TObject);
begin
//Åñëè íàø õîä, òî ñòàâèì êðåñòèê, ïåðåäàåì õîä è äåëàåì ïðîâåðêó
If turn then begin
turn := false;
B9.Caption := "X";
B9.Enabled := False;
ServerSocket1.Socket.Connections[0].SendText("9");
check;
end;
end;
procedure TForm1.ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
begin
//Ïðîâåðÿåì ïðèøåäøåå ñîîáùåíèå
v := StrToInt(Socket.ReceiveText);
case v of
0 : begin ShowMessage("Clien begin new game"); button10click(Sender); end; // Íîâàÿ èãðà
// Õîä ïðîòèâíèêà
1 : begin turn := true; B1.Caption := "O"; B1.Enabled := False; check; end;
2 : begin turn := true; B2.Caption := "O"; B2.Enabled := False; check; end;
3 : begin turn := true; B3.Caption := "O"; B3.Enabled := False; check; end;
4 : begin turn := true; B4.Caption := "O"; B4.Enabled := False; check; end;
5 : begin turn := true; B5.Caption := "O"; B5.Enabled := False; check; end;
6 : begin turn := true; B6.Caption := "O"; B6.Enabled := False; check; end;
7 : begin turn := true; B7.Caption := "O"; B7.Enabled := False; check; end;
8 : begin turn := true; B8.Caption := "O"; B8.Enabled := False; check; end;
9 : begin turn := true; B9.Caption := "O"; B9.Enabled := False; check; end;
end;
end;
procedure TForm1.newgame(sender: ShortString);
begin
//Íîâàÿ èãðà
turn := false;
If sender = "server" then ServerSocket1.Socket.Connections[0].SendText("0")
else ShowMessage("Client begin new game");
//Î÷èùàåì êíîïêè
B1.Caption := "";
B1.Enabled := True;
B2.Caption := "";
B2.Enabled := True;
B3.Caption := "";
B3.Enabled := True;
B4.Caption := "";
B4.Enabled := True;
B5.Caption := "";
B5.Enabled := True;
B6.Caption := "";
B6.Enabled := True;
B7.Caption := "";
B7.Enabled := True;
B8.Caption := "";
B8.Enabled := True;
B9.Caption := "";
B9.Enabled := True;
end;
end.
==server pas file end==
← →
Nvart (2003-12-14 22:24) [7]}{enon и Vollter спасибо за помощь попытаюсь разобраться
← →
Nvart (2003-12-14 22:24) [7]}{enon и Vollter спасибо за помощь попытаюсь разобраться
Страницы: 1 вся ветка
Форум: "Игры";
Текущий архив: 2004.04.11;
Скачать: [xml.tar.bz2];
Память: 0.61 MB
Время: 0.037 c