unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, Menus, ExtDlgs, StdCtrls, ScktComp, winsock, jpeg,
IdBaseComponent, IdComponent, IdIPWatch, AppEvnts;
type
TForm1 =
class(TForm)
Image1: TImage;
MainMenu1: TMainMenu;
Datei1: TMenuItem;
NeuesSpiel1: TMenuItem;
Hilfe1: TMenuItem;
OpenPictureDialog1: TOpenPictureDialog;
SpielSpeichern1: TMenuItem;
Spieloeffnen1: TMenuItem;
N1: TMenuItem;
Timer1: TTimer;
N2: TMenuItem;
Label9: TLabel;
Label1: TLabel;
Label4: TLabel;
Label3: TLabel;
Label5: TLabel;
Label2: TLabel;
Label6: TLabel;
Memo1: TMemo;
ClientSocket1: TClientSocket;
ServerSocket1: TServerSocket;
IdIPWatch1: TIdIPWatch;
Label7: TLabel;
Label8: TLabel;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
ApplicationEvents1: TApplicationEvents;
Label10: TLabel;
SaveDialog1: TSaveDialog;
OpenDialog1: TOpenDialog;
procedure FormCreate(Sender: TObject);
procedure NeuesSpiel1Click(Sender: TObject);
procedure Image1Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure N2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure pause(zeit: longint);
procedure Button1Click(Sender: TObject);
procedure ClientSocket1Connect(Sender: TObject;
Socket: TCustomWinSocket);
procedure Hilfe1Click(Sender: TObject);
procedure SpielSpeichern1Click(Sender: TObject);
procedure dateiOeffnen;
procedure dateiSpeichern;
procedure dateiErstellen;
// procedure ServerSocket1ClientRead(Sender: TObject;
//Socket: TCustomWinSocket);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
Nickname, Nachricht, verz:
string;
// Datei: File of figuren;
implementation
{$R *.dfm}
uses
StoffersUnit2,
UClientGame, StoffersUnit3, Unit4;
procedure TForm1.FormCreate(Sender: TObject);
// Procedure für die Form
var
i: Integer;
j: Integer;
w: Integer;
begin
image1.Canvas.Pen.Color:=clBlack;
// Stift-Farbe, bei Rectangle der Rahmen
image1.Canvas.Brush.Color:=clWhite;
// Pinselfarbe, bei Rectangle die Füllung
image1.Canvas.Rectangle(0,0,image1.Width,image1.Height);
// Rectangle = rechteck um das Brett
image1.Canvas.Brush.Color:=clBlack;
w:=image1.Width
div 8;
for i := 0
to 1
do // Für die Senkrechte Linie
begin
for j := 0
to 3
do // Für die waagerechte Linie / 4 blöcke / 1 block = 2zeilen
begin // X1 Y1 X2 Y2
Rectangle(image1.Canvas.Handle, 0+i*w, w+j*2*w-i*w, 1*w+i*w, 2*w+j*2*w-i*w);
Rectangle(image1.Canvas.Handle, 2*w+i*w, w+j*2*w-i*w, 3*w+i*w, 2*w+j*2*w-i*w);
Rectangle(image1.Canvas.Handle, 4*w+i*w, w+j*2*w-i*w, 5*w+i*w, 2*w+j*2*w-i*w);
Rectangle(image1.Canvas.Handle, 6*w+i*w, w+j*2*w-i*w, 7*w+i*w, 2*w+j*2*w-i*w);
end;
end;
Form1.Top:=((Screen.Monitors[0].Height
div 2)-(Form1.Height
div 2));
Form1.Left:=((Screen.Monitors[0].Width
div 2)-(Form1.Width
div 2));
Label6.Caption := DateToStr(Date);
// Datum
Label8.Caption:=IdIPWatch1.LocalIP;
//Anzeige der aktuelle IP-Adresse
Button1.Enabled:=false;
Button2.Enabled:=false;
end;
procedure TForm1.Image1Click(Sender: TObject);
var x,y : integer;
begin
x:= (Mouse.CursorPos.X-Form1.Left-((Form1.Width-Form1.ClientWidth)
div 2)-Form1.Image1.Left)
div (Form1.Image1.Width
div 8);
y:= (Mouse.CursorPos.Y-Form1.Top-(Form1.Height-Form1.ClientHeight
-((Form1.Width-Form1.ClientWidth)
div 2))-Form1.Image1.Top)
div (Form1.Image1.Height
div 8);
//--- Ausgabe der Koordinaten in den Labels
Label1.Caption := IntToStr(X);
Label2.Caption := IntToStr(Y);
if assigned(OClientGame)
then OClientGame.FeldAuswahl(X,Y);
end;
procedure TForm1.NeuesSpiel1Click(Sender: TObject);
begin
if assigned(OClientGame)
then OClientGame.Free;
OClientGame := TClientGame.create;
// Variable := Datentyp. wird erstellt
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
Label5.Caption := TimeToStr(now);
// Uhrzeit die aktualisiert wird
Label8.Caption:=IdIPWatch1.LocalIP;
end;
procedure TForm1.N2Click(Sender: TObject);
begin
Form2:=TForm2.Create(Form1);
Form2.ShowModal;
Form2.Free;
Form2:=nil;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
Nickname:=Edit3.Text;
Button3.Enabled:=false;
Edit3.Enabled:=false;
Button2.Enabled:=true;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
ClientSocket1.Host:=Edit2.Text;
ClientSocket1.Active:=true;
Button2.Enabled:=false;
Edit2.Enabled:=false;
Button1.Enabled:=true;
Nachricht:=Edit3.Text+'
hat den Raum betreten';
pause(500);
ClientSocket1.Socket.SendText(Nachricht);
end;
procedure TForm1.pause(zeit: longint);
var zeit1 : longint;
begin
zeit1 := GetTickCount;
repeat
Application.ProcessMessages;
until (GetTickCount - zeit1 > zeit);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if (ClientSocket1.Active=true)
and (Edit1.Text<>'
')
then
ClientSocket1.Socket.SendText(NickName+'
: '+Edit1.Text);
Edit1.Text:='
';
end;
procedure TForm1.ClientSocket1Connect(Sender: TObject;
Socket: TCustomWinSocket);
begin
ClientSocket1.Socket.SendText(Edit3.Text +'
hat den Chat verlassen.');
pause(500);
ClientSocket1.Close;
end;
{
procedure TForm1.ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
begin
var Text:string;
i: Integer;
begin
Text:=Socket.ReceiveText;
Memo1.Lines.add(Timetostr(now)+': '+Text);
For i := 0 to ServerSocket1.Socket.ActiveConnections - 1 do
begin
with ServerSocket1.Socket.Connections [I] do
if (Connected) then SendText(Text);
end;
end;
}
procedure TForm1.Hilfe1Click(Sender: TObject);
begin
Form4:=TForm4.Create(Form1);
Form4.ShowModal;
Form4.Free;
Form4:=nil;
end;
//------------------Speichern und Oeffnen---------------------------------------
procedure TForm1.SpielSpeichern1Click(Sender: TObject);
begin
if savedialog1.Execute = true
then
begin
verz := opendialog1.Filename;
try dateiOeffnen
except showmessage('
Datei nicht vohanden')
end;
end;
procedure TForm1.dateiOeffnen;
begin
AssignFile(datei, verz);
reset(datei);
read(datei, adr);
CloseFile(datei);
end;
end.