关于Delphi开发“炸飞机的游戏”

来源:互联网 发布:阿里金融云服务 编辑:程序博客网 时间:2024/05/01 01:03

做了这么久开发,一直想做一个小游戏玩玩,回想起上学玩的“炸飞机”的游戏,就拿他开始吧。

先说一下游戏的规则:

在10×10的方格里,汇制1—5—1—3的形状,方向自选,共三组,每一个飞机不能与其他的飞机有任何的重叠,第一个1为飞机头!玩家根据作标选择位置,系统会告之“炸中,炸毁,炸空”,直至全部炸毁三架飞机为止!

程序需求:

1.绘制“地图”,10*10的区域,有点象扫雷游戏的布局

2.由系统随机生成三架飞机,方向随机,并开始计时

3.用户点击时,告知用户是否“炸中,炸毁,炸空”,计算用户的点击次数

4.当所有的飞机都被“炸毁”时,系统提示成功,游戏结束

5.提交玩家的游戏成绩

6.显示成绩排行榜

程序实现:

 

unit UnitMain;

 

interface

 

uses

  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

  Dialogs, ExtCtrls, StdCtrls, Buttons, WinSkinData, IdBaseComponent,

  IdComponent, IdTCPConnection, IdTCPClient, IdHTTP;

const

  MAPWIDTH = 10;

  MAPHEIGHT = 10;

  MAPPIX = 30;

  PLANELEN = 4;

  PLANEWLEN = 5;

  PLANEFLEN = 3;

  PLANECOUNT = 3;

  MAXMAKECOUNT = 5;

type

  TGameStatus = (psNone, psDesign, psFight, psAddPlane, psGameOver);

type

  TForm1 = class(TForm)

    pnlMap: TPanel;

    pnlLeftLine: TPanel;

    pnlRight: TPanel;

    pnlTop: TPanel;

    pnlBottom: TPanel;

    BitBtn1: TBitBtn;

    BitBtn2: TBitBtn;

    BitBtn3: TBitBtn;

    SkinData1: TSkinData;

    Memo1: TMemo;

    BitBtn4: TBitBtn;

    BitBtn5: TBitBtn;

    Panel1: TPanel;

    Label1: TLabel;

    Label2: TLabel;

    Timer1: TTimer;

    SpeedButton1: TSpeedButton;

    IdHTTP1: TIdHTTP;

    procedure FormCreate(Sender: TObject);

    procedure BitBtn2Click(Sender: TObject);

    procedure BitBtn4Click(Sender: TObject);

    procedure BitBtn3Click(Sender: TObject);

    procedure Panel1MouseMove(Sender: TObject; Shift: TShiftState; X,

      Y: Integer);

    procedure BitBtn5Click(Sender: TObject);

    procedure Timer1Timer(Sender: TObject);

    procedure BitBtn1Click(Sender: TObject);

  private

    { Private declarations }

    procedure planePointerClick(Sender: TObject);

    procedure ClearStatus;

    procedure MakeAPlane();

    procedure RandomPlane();

    procedure DisplayAll();

    procedure ClearSpcStatus();

    procedure planeMouseMove(Sender: TObject; Shift: TShiftState;

  X, Y: Integer);

  public

    { Public declarations }

  end;

 

var

  Form1: TForm1;

  planePointer: array[0..MAPWIDTH,0..MAPHEIGHT] of TSpeedButton;

  psStatus: TGameStatus;

  planeClass: TClass;

  iPlane, iRandom, iFindPlane, iClick: Integer;

  tmpplan: TSpeedButton;

implementation

 

uses UnitFrmCommit;

 

{$R *.dfm}

 

procedure TForm1.ClearStatus;

var

  i,j: Integer;

begin

  for i := 0 to MAPWIDTH - 1 do

  begin

    for j := 0 to MAPHEIGHT - 1 do

    begin

      planePointer[i, j].Tag := 0;

      planePointer[i, j].Glyph.LoadFromFile('./Glyph/colors.bmp');

    end;

  end;

end;

 

procedure TForm1.FormCreate(Sender: TObject);

var

  i,j: Integer;

begin

  Self.pnlMap.Width := MAPWIDTH * MAPPIX;

  Self.pnlMap.Height := MAPHEIGHT * MAPPIX;

 

  Self.pnlLeftLine.Width :=  MAPPIX;

  Self.pnlLeftLine.Height :=  MAPHEIGHT * MAPPIX;

  Self.pnlLeftLine.Left :=   Self.pnlMap.Left - MAPPIX;

  Self.pnlLeftLine.Top := Self.pnlMap.Top;

 

  Self.pnlRight.Width  :=  MAPPIX;

  Self.pnlRight.Height :=  MAPHEIGHT * MAPPIX;

  Self.pnlRight.Left :=   Self.pnlMap.Left + Self.pnlMap.Width;

  Self.pnlRight.Top := Self.pnlMap.Top;

 

  Self.pnlTop.Width :=  MAPWIDTH * MAPPIX + 2 * MAPPIX;

  Self.pnlTop.Height :=   MAPPIX;

  Self.pnlTop.Left :=   Self.pnlLeftLine.Left;

  Self.pnlTop.Top := Self.pnlMap.Top - MAPPIX;

 

  Self.pnlBottom.Width :=  MAPWIDTH * MAPPIX + 2 * MAPPIX;

  Self.pnlBottom.Height :=   MAPPIX;

  Self.pnlBottom.Left :=   Self.pnlLeftLine.Left;

  Self.pnlBottom.Top := Self.pnlMap.Top + Self.pnlMap.Height;

 

 

  for i := 0 to MAPWIDTH - 1 do

  begin

    for j := 0 to MAPHEIGHT - 1do

    begin

      planePointer[i, j] := TSpeedButton.Create(pnlMap);

      planePointer[i, j].Width := MAPPIX;

      planePointer[i, j].Height := MAPPIX;

      planePointer[i, j].Left := i* MAPPIX;

      planePointer[i, j].Top := j* MAPPIX;

      planePointer[i, j].Parent := pnlMap;

      planePointer[i, j].OnClick := planePointerClick;

      planePointer[i, j].Hint := IntToStr(i) + ',' + IntToStr(j);

      planePointer[i, j].Glyph.LoadFromFile('./Glyph/colors.bmp');

      planePointer[i, j].OnMouseMove := planeMouseMove;

    end;

  end;    

 

//  psStatus := psDesign;

  iPlane := 0;

  iRandom := 0;

  iFindPlane := 0;

  iClick := 0;

 

end;

 

procedure TForm1.planePointerClick(Sender: TObject);

begin

  case  psStatus of

    psDesign:

    begin

      (Sender as TSpeedButton).Tag := 1;

      (Sender as TSpeedButton).Glyph.LoadFromFile('./Glyph/colorsselected.bmp')

    end;

    psFight://binggo

    begin

      Label2.Caption := IntToStr((StrToInt(Label2.Caption) + 1));

      if (Sender as TSpeedButton).Tag = 1 then

        (Sender as TSpeedButton).Glyph.LoadFromFile('./Glyph/bdiag.bmp');

      //head

      if (Sender as TSpeedButton).Tag = 2 then

      begin

       (Sender as TSpeedButton).Glyph.LoadFromFile('./Glyph/head.bmp');

       (Sender as TSpeedButton).Tag := 3;

       Inc(iFindPlane);

 

       if iFindPlane = PLANECOUNT then

       begin

         psStatus := psGameOver;

         DisplayAll;

         ShowMessage('成功!');

         //在此处提交信息到网站

         Application.CreateForm(TfrmCommit, frmCommit);

         frmCommit.Edit1.Text := Label1.Caption;

         frmCommit.Edit2.Text := Label2.Caption;

         frmCommit.ShowModal;

         frmCommit.Free; 

       end;

 

      end;

      if (Sender as TSpeedButton).Tag = 0 then

      begin

        (Sender as TSpeedButton).Glyph.LoadFromFile('./Glyph/error.bmp');

      end;

 

    end;

  end;

 

end;

 

procedure TForm1.BitBtn2Click(Sender: TObject);

begin

  psStatus := psFight;

end;

 

procedure TForm1.MakeAPlane;

var

  i,j: integer;

  rNumber: Integer;

  rForward: Integer;

begin

  Randomize;

  //头,横

  i := Random(MAPWIDTH);

  Randomize;

  //头,纵

  j := Random(MAPHEIGHT);

  //方向

  Randomize;

  rForward := Random(4);

  //向下

  if rForward = 0 then

  begin

    //判断长度

    if ((j + PLANELEN - 1) in [0..MAPHEIGHT - 1]) and ((i + 2) in [0..MAPWIDTH - 1]) and ((i - 2) in [0..MAPWIDTH - 1]) then

    begin

      Memo1.Lines.Add(IntToStr(i) + '  ' + IntToStr(j) + '生成成功') ;

      planePointer[i, j].Tag := 2;

      planePointer[i, j + 1].Tag := 1;

      planePointer[i - 2 , j + 1].Tag := 1;

      planePointer[i - 1 , j + 1].Tag := 1;

      planePointer[i + 1 , j + 1].Tag := 1;

      planePointer[i + 2 , j + 1].Tag := 1;

      planePointer[i , j + 2].Tag := 1;

      planePointer[i , j + 3].Tag := 1;

      planePointer[i - 1 , j + 3].Tag := 1;

      planePointer[i + 1 , j + 3].Tag := 1;

    end

    else

    begin

      Memo1.Lines.Add(IntToStr(i) + '  ' + IntToStr(j) + '生成错误') ;

      MakeAPlane;

    end;

 

 

  end;

  //向下

  if rForward = 1 then

  begin

    //判断长度

    if ((j - PLANELEN + 1) in [0..MAPHEIGHT - 1]) and ((i - 2) in [0..MAPWIDTH - 1]) and ((i + 2) in [0..MAPWIDTH - 1]) then

    begin

      Memo1.Lines.Add(IntToStr(i) + '  ' + IntToStr(j) + '生成成功') ;

      planePointer[i, j].Tag := 2;

      planePointer[i, j - 1].Tag := 1;

      planePointer[i + 2 , j - 1].Tag := 1;

      planePointer[i + 1 , j - 1].Tag := 1;

      planePointer[i - 1 , j - 1].Tag := 1;

      planePointer[i - 2 , j - 1].Tag := 1;

      planePointer[i , j - 2].Tag := 1;

      planePointer[i , j - 3].Tag := 1;

      planePointer[i - 1 , j - 3].Tag := 1;

      planePointer[i + 1 , j - 3].Tag := 1;

    end

    else

    begin

      Memo1.Lines.Add(IntToStr(i) + '  ' + IntToStr(j) + '生成错误') ;

      MakeAPlane;

    end;

 

 

  end;

 

    //向左

  if rForward = 2 then

  begin

    //判断长度

    if ((i - PLANELEN + 1) in [0..MAPWIDTH - 1]) and ((j - 2) in [0..MAPHEIGHT - 1]) and ((j + 2) in [0..MAPHEIGHT - 1]) then

    begin

      Memo1.Lines.Add(IntToStr(i) + '  ' + IntToStr(j) + '生成成功') ;

 

      planePointer[i, j].Tag := 2;

      planePointer[i - 1, j ].Tag := 1;

      planePointer[i - 2 , j ].Tag := 1;

      planePointer[i - 1 , j - 2].Tag := 1;

      planePointer[i - 1 , j - 1].Tag := 1;

      planePointer[i - 1 , j + 1].Tag := 1;

      planePointer[i - 1 , j + 2].Tag := 1;

 

      planePointer[i - 3 , j ].Tag := 1;

      planePointer[i - 3, j - 1].Tag := 1;

      planePointer[i - 3 , j + 1].Tag := 1;

 

    end

    else

    begin

      Memo1.Lines.Add(IntToStr(i) + '  ' + IntToStr(j) + '生成错误') ;

      MakeAPlane;

    end;

 

  end;

    //向右

  if rForward = 3 then

  begin

    //判断长度

//    i := 7; j := 4;

    if ((i + PLANELEN - 1) in [0..MAPWIDTH - 1]) and ((j - 2) in [0..MAPHEIGHT - 1]) and ((j + 2) in [0..MAPHEIGHT - 1]) then

    begin

      Memo1.Lines.Add(IntToStr(i) + '  ' + IntToStr(j) + '生成成功') ;

 

      planePointer[i, j].Tag := 2;

      planePointer[i + 1, j ].Tag := 1;

 

      planePointer[i + 1 , j - 2].Tag := 1;

      planePointer[i + 1 , j - 1].Tag := 1;

      planePointer[i + 1 , j + 1].Tag := 1;

      planePointer[i + 1 , j + 2].Tag := 1; 

      planePointer[i + 2 , j ].Tag := 1;

      planePointer[i + 3 , j ].Tag := 1;

      planePointer[i + 3, j - 1].Tag := 1;

      planePointer[i + 3 , j + 1].Tag := 1;

    end

    else

    begin

      Memo1.Lines.Add(IntToStr(i) + '  ' + IntToStr(j) + '生成错误') ;

      MakeAPlane;

    end;

 

 

  end;

 

 

 

 

end;

 

procedure TForm1.BitBtn4Click(Sender: TObject);

begin

  ClearStatus;

end;

 

procedure TForm1.BitBtn3Click(Sender: TObject);

begin

  ClearStatus;

end;

 

procedure TForm1.RandomPlane;

var

  i,j: integer;

  rNumber: Integer;

  rForward: Integer;

begin

  if iRandom = MAXMAKECOUNT then

  begin

    Self.ClearStatus;

    iRandom := 0;

    iPlane := 0;

  end;

  Randomize;

  //头,横

  i := Random(MAPWIDTH);

  Randomize;

  //头,纵

  j := Random(MAPHEIGHT);

  //方向

  Randomize;

  rForward := Random(4);

  //向下

  if rForward = 0 then

  begin

    //判断长度

    if ((j + PLANELEN - 1) in [0..MAPHEIGHT - 1]) and ((i + 2) in [0..MAPWIDTH - 1])

       and ((i - 2) in [0..MAPWIDTH - 1]) and ( planePointer[i, j].Tag = 0)

       and (planePointer[i, j + 1].Tag = 0) and (planePointer[i - 2 , j + 1].Tag = 0)

       and (planePointer[i - 1 , j + 1].Tag = 0) and (planePointer[i + 1 , j + 1].Tag= 0)

       and (planePointer[i + 2 , j + 1].Tag = 0) and (planePointer[i , j + 2].Tag = 0)

       and (planePointer[i , j + 3].Tag = 0) and (planePointer[i - 1 , j + 3].Tag = 0)

       and (planePointer[i + 1 , j + 3].Tag = 0)    then

    begin

      Memo1.Lines.Add(IntToStr(i) + '  ' + IntToStr(j) + '生成成功') ;

      planePointer[i, j].Tag := 2;

      planePointer[i, j + 1].Tag := 1;

      planePointer[i - 2 , j + 1].Tag := 1;

      planePointer[i - 1 , j + 1].Tag := 1;

      planePointer[i + 1 , j + 1].Tag := 1;

      planePointer[i + 2 , j + 1].Tag := 1;

      planePointer[i , j + 2].Tag := 1;

      planePointer[i , j + 3].Tag := 1;

      planePointer[i - 1 , j + 3].Tag := 1;

      planePointer[i + 1 , j + 3].Tag := 1;

      Inc(iPlane);

      if iPlane < PLANECOUNT then

         RandomPlane;

    end

    else

    begin

      Memo1.Lines.Add(IntToStr(i) + '  ' + IntToStr(j) + '生成错误') ;

      Inc(iRandom);

      RandomPlane;

    end;

  end;

  //向下

  if rForward = 1 then

  begin

    //判断长度

    if ((j - PLANELEN + 1) in [0..MAPHEIGHT - 1]) and ((i - 2) in [0..MAPWIDTH - 1])

     and ((i + 2) in [0..MAPWIDTH - 1])  and ( planePointer[i, j].Tag = 0)

       and (planePointer[i, j - 1].Tag = 0) and (planePointer[i + 2 , j - 1].Tag = 0)

       and (planePointer[i + 1 , j - 1].Tag = 0) and (planePointer[i - 1 , j - 1].Tag= 0)

       and (planePointer[i - 2 , j - 1].Tag = 0) and (planePointer[i , j - 2].Tag = 0)

       and (planePointer[i , j - 3].Tag = 0) and (planePointer[i - 1 , j - 3].Tag = 0)

       and (planePointer[i + 1 , j - 3].Tag = 0)    then

    begin

      Memo1.Lines.Add(IntToStr(i) + '  ' + IntToStr(j) + '生成成功') ;

      planePointer[i, j].Tag := 2;

      planePointer[i, j - 1].Tag := 1;

      planePointer[i + 2 , j - 1].Tag := 1;

      planePointer[i + 1 , j - 1].Tag := 1;

      planePointer[i - 1 , j - 1].Tag := 1;

      planePointer[i - 2 , j - 1].Tag := 1;

      planePointer[i , j - 2].Tag := 1;

      planePointer[i , j - 3].Tag := 1;

      planePointer[i - 1 , j - 3].Tag := 1;

      planePointer[i + 1 , j - 3].Tag := 1;

      Inc(iPlane);

      if iPlane < PLANECOUNT then

         RandomPlane;

    end

    else

    begin

      Memo1.Lines.Add(IntToStr(i) + '  ' + IntToStr(j) + '生成错误') ;

      Inc(iRandom);

      RandomPlane;

    end;

  end;

 

  if rForward = 2 then

  begin

    //判断长度

    if ((i - PLANELEN + 1) in [0..MAPWIDTH - 1]) and ((j - 2) in [0..MAPHEIGHT - 1])

     and ((j + 2) in [0..MAPHEIGHT - 1])  and ( planePointer[i, j].Tag = 0)

       and (planePointer[i - 1, j].Tag = 0) and (planePointer[i - 2 , j].Tag = 0)

       and (planePointer[i - 1 , j - 2].Tag = 0) and (planePointer[i - 1 , j - 1].Tag= 0)

       and (planePointer[i - 1 , j + 1].Tag = 0) and (planePointer[i - 1 , j + 2].Tag = 0)

       and (planePointer[i - 3 , j].Tag = 0) and (planePointer[i - 3, j - 1].Tag = 0)

       and (planePointer[i - 3 , j + 1].Tag = 0)    then

    begin

      Memo1.Lines.Add(IntToStr(i) + '  ' + IntToStr(j) + '生成成功') ;

 

      planePointer[i, j].Tag := 2;

      planePointer[i - 1, j ].Tag := 1;

      planePointer[i - 2 , j ].Tag := 1;

      planePointer[i - 1 , j - 2].Tag := 1;

      planePointer[i - 1 , j - 1].Tag := 1;

      planePointer[i - 1 , j + 1].Tag := 1;

      planePointer[i - 1 , j + 2].Tag := 1;

 

      planePointer[i - 3 , j ].Tag := 1;

      planePointer[i - 3, j - 1].Tag := 1;

      planePointer[i - 3 , j + 1].Tag := 1;

      Inc(iPlane);

      if iPlane < PLANECOUNT then

         RandomPlane;

 

    end

    else

    begin

      Memo1.Lines.Add(IntToStr(i) + '  ' + IntToStr(j) + '生成错误') ;

      Inc(iRandom);

      RandomPlane;

    end;

 

  end;

 

    //向右

  if rForward = 3 then

  begin

    //判断长度

//    i := 7; j := 4;

    if ((i + PLANELEN - 1) in [0..MAPWIDTH - 1]) and ((j - 2) in [0..MAPHEIGHT - 1])

      and ((j + 2) in [0..MAPHEIGHT - 1]) and ( planePointer[i, j].Tag = 0)

       and (planePointer[i + 1, j].Tag = 0) and (planePointer[i + 1 , j - 2].Tag = 0)

       and (planePointer[i + 1 , j - 1].Tag = 0) and (planePointer[i + 1 , j + 1].Tag= 0)

       and (planePointer[i + 1 , j + 2].Tag = 0) and (planePointer[i + 2 , j].Tag = 0)

       and (planePointer[i + 3 , j].Tag = 0) and (planePointer[i + 3, j - 1].Tag = 0)

       and (planePointer[i + 3 , j + 1].Tag = 0)    then

    begin

      Memo1.Lines.Add(IntToStr(i) + '  ' + IntToStr(j) + '生成成功') ;

 

      planePointer[i, j].Tag := 2;

      planePointer[i + 1, j ].Tag := 1;

 

      planePointer[i + 1 , j - 2].Tag := 1;

      planePointer[i + 1 , j - 1].Tag := 1;

      planePointer[i + 1 , j + 1].Tag := 1;

      planePointer[i + 1 , j + 2].Tag := 1; 

      planePointer[i + 2 , j ].Tag := 1;

      planePointer[i + 3 , j ].Tag := 1;

      planePointer[i + 3, j - 1].Tag := 1;

      planePointer[i + 3 , j + 1].Tag := 1;

      Inc(iPlane);

      if iPlane < PLANECOUNT then

         RandomPlane;

    end

    else

    begin

      Memo1.Lines.Add(IntToStr(i) + '  ' + IntToStr(j) + '生成错误') ;

      Inc(iRandom);

      RandomPlane;

    end;

 

 

  end;

end;

 

procedure TForm1.Panel1MouseMove(Sender: TObject; Shift: TShiftState; X,

  Y: Integer);

begin

  Memo1.Lines.Add('x:' + IntToStr(x));

end;

 

procedure TForm1.BitBtn5Click(Sender: TObject);

begin

  Timer1.Enabled := False;

  iPlane := 0;

  iRandom := 0;

  iFindPlane := 0;

  iClick := 0;

  Label1.Caption := '0';

  Label2.Caption := '0';

  ClearStatus;

  Self.RandomPlane;

  psStatus := psFight;

  ShowMessage('start');

  Timer1.Enabled := True;

end;

 

procedure TForm1.Timer1Timer(Sender: TObject);

begin

  if psStatus = psFight then

    Label1.Caption := IntToStr(StrToInt(Label1.Caption) + 1);

  if psStatus = psGameOver then

    Timer1.Enabled := False;

end;

 

procedure TForm1.DisplayAll;

var

  i,j: Integer;

begin

  for i := 0 to MAPWIDTH - 1 do

  begin

    for j := 0 to MAPHEIGHT - 1 do

    begin

      if planePointer[i, j].Tag  = 2 then

        planePointer[i, j].Glyph.LoadFromFile('./Glyph/head.bmp');

      if planePointer[i, j].Tag  = 1 then

        planePointer[i, j].Glyph.LoadFromFile('./Glyph/bdiag.bmp');

    end;

  end;

 

end;

 

procedure TForm1.planeMouseMove(Sender: TObject; Shift: TShiftState; X,

  Y: Integer);

var

  i,j: integer;

  rNumber: Integer;

  rForward: Integer;

  value: string;

begin

  if Sender = tmpplan then Exit;

  tmpplan  := TSpeedButton(Sender);

  if psStatus <> psDesign then Exit;

 

  Self.ClearSpcStatus;

 

  value := (Sender as TSpeedButton).Hint;

  i := StrToInt(Copy(value, 1, Pos(',', value) - 1));

  j := StrToInt(Copy(value, Pos(',', value) + 1, Length(value) ));

 

  rForward := 1;

  if rForward = 1 then

  begin

    //判断长度

    if ((j - PLANELEN + 1) in [0..MAPHEIGHT - 1]) and ((i - 2) in [0..MAPWIDTH - 1])

     and ((i + 2) in [0..MAPWIDTH - 1])  and ( planePointer[i, j].Tag = 0)

       and (planePointer[i, j - 1].Tag = 0) and (planePointer[i + 2 , j - 1].Tag = 0)

       and (planePointer[i + 1 , j - 1].Tag = 0) and (planePointer[i - 1 , j - 1].Tag= 0)

       and (planePointer[i - 2 , j - 1].Tag = 0) and (planePointer[i , j - 2].Tag = 0)

       and (planePointer[i , j - 3].Tag = 0) and (planePointer[i - 1 , j - 3].Tag = 0)

       and (planePointer[i + 1 , j - 3].Tag = 0)    then

    begin

      planePointer[i, j].Tag := 2;

      planePointer[i, j - 1].Tag := 1;

      planePointer[i + 2 , j - 1].Tag := 1;

      planePointer[i + 1 , j - 1].Tag := 1;

      planePointer[i - 1 , j - 1].Tag := 1;

      planePointer[i - 2 , j - 1].Tag := 1;

      planePointer[i , j - 2].Tag := 1;

      planePointer[i , j - 3].Tag := 1;

      planePointer[i - 1 , j - 3].Tag := 1;

      planePointer[i + 1 , j - 3].Tag := 1;

      DisplayAll;

    end;

  end;

end;

 

 

 

{-------------------------------------------------------------------------------

  过程名:    TForm1.ClearSpcStatus

  功能:      改变状态

  作者:      wangpu

  日期:      2010-5-14 15:03:38

  参数:      无

  返回值:    无

-------------------------------------------------------------------------------}

procedure TForm1.ClearSpcStatus;

var

  i,j: Integer;

begin

  for i := 0 to MAPWIDTH - 1 do

  begin

    for j := 0 to MAPHEIGHT - 1 do

    begin

      if planePointer[i, j].Tag <> 0 then

      begin

        planePointer[i, j].Tag := 0;

        planePointer[i, j].Glyph.LoadFromFile('./Glyph/colors.bmp');

      end;

    end;

  end;

end;

 

procedure TForm1.BitBtn1Click(Sender: TObject);

begin

  psStatus := psDesign;

end;

 

end.

整个程序的代码就这么多,程序的重点是飞机的生成上,如何能快速生成三架随机的飞机是重点!目前的方式是,生成一架,再生成,再生成当出现重叠的状态时,重新生成,当达到MAXMAKECOUNT数时,重新生成三架飞机!!此处需要优化,通过优化算法的方式来形成,整个程序没有什么特别说明的地方,只是一个小游戏!以后打算在Flash/Flex,手机平台(IPhone,Android,WM)等平台实现;功能方面,加入联网对战等功能;

 源程序下载:http://www.danbao123.com/Plane.rar

中国担保黄页 开发组