unit ddpdtut1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ddpd, StdCtrls, Buttons, ExtCtrls,DPlay;

type
  TForm1 = class(TForm)
    DDPD1: TDDPD;
    ChatMemo: TMemo;
    Panel1: TPanel;
    SendBtn: TButton;
    MessageEdit: TEdit;
    procedure FormCreate(Sender: TObject);
    procedure SendBtnClick(Sender: TObject);
    procedure DDPD1ComesNewChallenger(Sender: TObject; player: TDDPDPlayer;
      ShortName, LongName: String);
    procedure DDPD1EscapeChallenger(Sender: TObject; player: TDDPDPlayer;
      ShortName, LongName: String);
    procedure FormResize(Sender: TObject);
    procedure DDPD1ArriveMessage(Sender: TObject; from: TDDPDPlayer;
      data: Pointer; dataSize: Cardinal);
  private
    { Private 宣言 }
  public
    { Public 宣言 }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
begin
  //いきなり接続
  if not DDPD1.Execute then
    Application.Terminate;
end;

//メッセージを送る
procedure TForm1.SendBtnClick(Sender: TObject);
begin
  DDPD1.Send(DPID_ALLPLAYERS, PChar(MessageEdit.Text), Length(MessageEdit.Text)+1);

  //自分のメッセージ欄にも入れる
  ChatMemo.Lines.Add(DDPD1.MyPlayer.ShortName + ':' + #$09 + MessageEdit.Text);

  //メッセージ欄をクリア
  MessageEdit.Text:='';
end;


//メッセージが届いたよ
procedure TForm1.DDPD1ArriveMessage(Sender: TObject; from: TDDPDPlayer;
  data: Pointer; dataSize: Cardinal);
begin
  ChatMemo.Lines.Add(from.ShortName + ':' + #$09 + PChar(data));
end;

//誰か来たよ
procedure TForm1.DDPD1ComesNewChallenger(Sender: TObject;
  player: TDDPDPlayer; ShortName, LongName: String);
begin
  ChatMemo.Lines.Add(ShortName + 'さんが、来ました');
end;

//誰かが逃げたよ
procedure TForm1.DDPD1EscapeChallenger(Sender: TObject;
  player: TDDPDPlayer; ShortName, LongName: String);
begin
  ChatMemo.Lines.Add(ShortName + 'さんが、逃げました');
end;


//どうでもいいんだけど、ボタンの位置とかを自動調整
procedure TForm1.FormResize(Sender: TObject);
begin
  SendBtn.Left:=Panel1.ClientWidth - SendBtn.Width - 2;
  MessageEdit.Width:=Panel1.ClientWidth - SendBtn.Width - 8;
end;


end.
