想找这些东西很久了,却一直找不到,希望大家能帮忙找一下 !谢谢大家!

解决方案 »

  1.   

    //这个类是对ms的那个cards.dll的封装。
    unit Cards_San;interface
    uses
    windows,sysutils,classes,graphics,ExtCtrls;
    ////////////
    const
    CDFlower=1;
    CDPic=2;
    CDRed=3;
    CDBlack=4;
    CDKing=5;
    /////////////
    type
      TCardIndexRange=record
        Min:integer;
        Max:integer;
      end;
      TCardKind=CDFlower..CDKing;
      TCardPoint=1..13;
      //////////////////
      TCards_San=class
      private
        HRS:hmodule;
        indexes:tstringlist;
      protected
       CurrentCard:integer;
       CardIndexRange:TCardIndexRange;
       function HRSOK:boolean;
       function InRange(index:integer):boolean;
       function OK(index:integer):Boolean;
       procedure MixCards;
       function GetRandomIndex:integer;
      public    /////////
        constructor Create(CardFile:string='cards.dll';MinIndex:integer=1;MaxIndex:integer=52);virtual;
        destructor Destroy;override;
        /////////
        procedure Shuffle(RandomCards:boolean=false);    function GetCardPoint(CardIndex:integer):integer;virtual;
        function GetCardKind(CardIndex:integer):TCardKind;virtual;    function CardsLeft:integer;
        function CardsCount:integer;
        
        function GetCardByIndex(BMP:TBitMap;CardIndex:integer):boolean;overload;
        function GetCardByIndex(Image:TImage;CardIndex:integer):boolean;overload;    function GetRandomCard(CanRepeat:Boolean=false):integer;overload;
        function GetRandomCard(BMP: TBitMap;CanRepeat:Boolean=false): integer;overload;
        function GetRandomCard(Image: TImage;CanRepeat:Boolean=false): integer;overload;    function GetCard(BMP:TBitMap;Point: TCardPoint;Kind:TCardKind):integer;overload;virtual;
        function GetCard(Image:TImage;Point: TCardPoint;Kind:TCardKind):integer;overload;virtual;
      end;implementation{ TCards_San }function TCards_San.CardsCount: integer;
    begin
      result:=self.CardIndexRange.Max-cardindexrange.Min+1;
    end;function TCards_San.CardsLeft: integer;
    begin
      result:=indexes.Count;
    end;constructor TCards_San.Create(CardFile:string='cards.dll';MinIndex:integer=1;MaxIndex:integer=52);
    begin
      inherited create;
      try
      hrs:=loadlibrary(pchar(cardfile));
      finally  currentcard:=-1;
      cardindexrange.Min:=minindex;
      cardindexrange.Max:=maxindex;  indexes:=tstringlist.Create;
      self.Shuffle;
      end;
    end;destructor TCards_San.Destroy;
    begin
      try
      freelibrary(hrs);
      except
      end;
      
      indexes.Free;
      inherited;end;
    ///////////////////////////////
    function TCards_San.GetCardByIndex(BMP:TbitMap;CardIndex: integer): boolean;
    var
    tbmp:tbitmap;
    begin
      result:=ok(cardindex);
      
      if not result then exit;
      result:=false;  tbmp:=tbitmap.Create;
      try
        tbmp.LoadFromResourceID(hrs,cardindex);
        bmp.Width:=tbmp.Width;
        bmp.Height:=tbmp.Height;
        bmp.Canvas.CopyRect(rect(0,0,bmp.Width,bmp.Height),tbmp.Canvas,rect(0,0,tbmp.Width,tbmp.Height));
        result:=true;
      finally
        tbmp.Free;
        if result then currentcard:=cardindex;
      end;end;function TCards_San.GetCardByIndex(Image: TImage; CardIndex: integer): boolean;
    begin
      result:=self.GetCardbyindex(image.Picture.Bitmap,cardindex);end;
    /////////////////////////////////////////
    function TCards_San.GetRandomCard(BMP: TBitMap;CanRepeat:Boolean): integer;
    var
    index:integer;
    begin
      result:=-1;
      if (indexes.Count<=0)or (not hrsok) then exit;
      index:=getrandomindex;
      if getcardbyindex(bmp,strtoint(indexes.strings[index])) then
      begin
        result:=strtoint(indexes.strings[index]);
        if not canrepeat then indexes.Delete(index);
        if index>indexes.Count-1 then currentcard:=indexes.Count-1;
      end;
    end;function TCards_San.GetCardKind(CardIndex: integer): TCardKind;
    var
    i:integer;
    begin
      //i:=strtoint(indexes.strings[cardindex]);
      result:=1+((i-1) div 13);
    end;function TCards_San.GetCardPoint(CardIndex: integer): integer;
    var
    i:integer;
    begin
     
      if cardindex mod 13=0 then
        result:=13
      else
        result:=(cardindex mod 13);
    end;function TCards_San.GetRandomCard(Image: TImage;CanRepeat:Boolean): integer;
    begin
      result:=getrandomcard(image.Picture.Bitmap,canrepeat);
    end;
    ///////////////////////////////////////
    function TCards_San.GetRandomIndex: integer;
    begin
      result:=-1;
      if indexes.Count<=0 then exit;
      result:=random(indexes.Count);
    end;function TCards_San.HRSOK: boolean;
    begin
      if hrs>0 then
        result:=true
      else
        result:=false;  
    end;function TCards_San.InRange(index: integer): boolean;
    begin
      if index in [cardindexrange.Min..cardindexrange.Max] then
        result:=true
      else
        result:=false;end;procedure TCards_San.MixCards;
    var
    i,j,k:integer;
    t:string;
    begin
      randomize;
      for k:=cardindexrange.Min to cardindexrange.max do
      begin
        i:=getrandomindex;
        j:=getrandomindex;
        if i<>j then
        begin
          t:=indexes.Strings[i];
          indexes.Strings[i]:=indexes.Strings[j];
          indexes.Strings[j]:=t;
        end;
      end;
    end;function TCards_San.OK(index:integer): Boolean;
    begin
      result:=inrange(index) and hrsok;end;procedure TCards_San.Shuffle(RandomCards:boolean=false);
    var
    i:integer;
    begin
      randomize;
      indexes.Clear;  for i:=cardindexrange.Min to cardindexrange.Max do
      begin
        indexes.Add(inttostr(i));
      end;  if randomcards then
        MixCards;  
    end;function TCards_San.GetCard(BMP: TBitMap; Point:  TCardPoint;
      Kind: TCardKind): integer;
    var
    i:integer;
    begin
      result:=-1;
      //if point=0 then
      i:=point+13*(kind-1);
      if getcardbyindex(bmp,i) then
      begin
        result:=i;
      end;
    end;function TCards_San.GetCard(Image: TImage; Point:  TCardPoint;
      Kind: TCardKind): integer;
    begin
      result:=getcard(image.Picture.Bitmap,point,kind);
    end;function TCards_San.GetRandomCard(CanRepeat:Boolean=false): integer;
    var
    i:integer;
    begin
      result:=-1;
      if (indexes.Count<=0) or (not hrsok) then exit;
      i:=getrandomindex;  result:=strtoint(indexes.Strings[i]);
      if not canrepeat then
        indexes.Delete(i);
    end;end.
      

  2.   

    //使用起来很简单。下面是一个人机对战21点游戏的简单演示:
    unit Main;interfaceuses
      Windows, common_san,cards_San,Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, ExtCtrls, StdCtrls, ComCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        Button2: TButton;
        StatusBar1: TStatusBar;
        Button3: TButton;
        GroupBox1: TGroupBox;
        Image1: TImage;
        Image2: TImage;
        Image3: TImage;
        Image4: TImage;
        Image8: TImage;
        Image7: TImage;
        Image6: TImage;
        Image5: TImage;
        Image9: TImage;
        Image10: TImage;
        Image11: TImage;
        Image12: TImage;
        procedure FormCreate(Sender: TObject);
        procedure FormClose(Sender: TObject; var Action: TCloseAction);
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
        procedure Button3Click(Sender: TObject);
      private
        { Private declarations }
      public
        ended:boolean;
        procedure CallCard;
        function Compare:boolean; 
        procedure PCGO;
        procedure Init;
        procedure ShowResults(awin:boolean=true);
        function FindImage(ATag:integer):TImage;
        { Public declarations }
      end;var
      Form1: TForm1;
      cards:tcards_san;
      count:integer;
      pccount:integer;
      pcpoints:integer;
      points:integer;  win:integer=0;
      lost:integer=0;
    implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
    begin
    cards:=tcards_San.Create;
    //cards.Shuffle;
    showhint:=true;
    caption:=application.Title;
    fitfont(self);
    init;
    end;procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
    begin
    cards.Free;
    end;procedure TForm1.Button1Click(Sender: TObject);
    begin
    callcard;
    pcgo;
    end;procedure TForm1.CallCard;
    var
    img:timage;
    i:integer;
    begin
      if (ended)or(points>=21)or(count>12) then exit;
      img:=findimage(count);
      if img=nil then exit;
      i:=cards.GetRandomCard(img);  if i in [1..52] then
      begin
        points:=points+cards.GetCardPoint(i);
        statusbar1.Panels.Items[2].Text:='Points: '+inttostr(points);
        //msg2(cards.GetCardPoint(i));
        if points=21 then
        begin
          msg('It is: 21'+#13#10#13#10+'You Win!');
          ended:=true;
          showresults;
        end;
        if points>21 then
        begin
          ended:=true;
          msg('It is: '+inttostr(points)+#13#10#13#10+'You Lost.');
          showresults(false);
        end;
        inc(count);
      end;  
    end;procedure TForm1.Init;
    var
    img:timage;
    i:integer;
    begin
      ended:=false;
      cards.Shuffle;
      pccount:=1;
      pcpoints:=0;
      count:=1;
      points:=0;
      for i:=1 to 12 do
      begin
        img:=findimage(i);
        img.Picture.Bitmap.Canvas.Brush.Color:=clbtnface;
        img.Picture.Bitmap.Canvas.FillRect(img.ClientRect);
      end;
      statusbar1.Panels.Items[2].Text:='Points: '+inttostr(points);
    end;function TForm1.FindImage(ATag: integer): TImage;
    var
    i:integer;
    begin
      result:=nil;
      for i:=0 to self.ComponentCount-1 do
      begin
        if self.Components[i] is TImage then
        begin
           if self.Components[i].Tag=atag then
           begin
             result:=timage(self.Components[i]);
             break;
           end;
        end;
      end;
    end;procedure TForm1.Button2Click(Sender: TObject);
    begin
    init;
    end;procedure TForm1.PCGO;
    begin
      if ended then exit;
      if pcpoints>=18 then
      begin
        if compare then exit;
      end;
      pcpoints:=pcpoints+cards.GetCardPoint(cards.GetRandomCard);
      if pcpoints=21 then
      begin
        msg('PC is : '+inttostr(pcpoints)+#13#10#13#10+'You Lost!');
        ended:=true;
        showresults(false);
      end;
      if pcpoints>21 then
      begin
        msg('PC is : '+inttostr(pcpoints)+#13#10#13#10+'You Win!');
        ended:=true;
        showresults;
      end;
    end;procedure TForm1.Button3Click(Sender: TObject);
    begin
      compare;
    end;function TForm1.Compare: boolean;
    begin
      result:=true;
      if (ended)or(points<=0)or(pcpoints<=0) then exit;
      if pcpoints=points then
      begin
        msg('PC and You have the same points: '+inttostr(points)+#13#10#13#10+'Please continue the game.');
        result:=false;  end;
      if pcpoints>points then
      begin
        msg('PC has more points then you '+inttostr(pcpoints)+':'+inttostr(points)+#13#10#13#10+'You Lost!');
        ended:=true;
        showresults(false);
      end;
      if pcpoints<points then
      begin
        msg('You have more points then PC '+inttostr(points)+':'+inttostr(pcpoints)+#13#10#13#10+'You Win!');
        ended:=true;
        showresults;
      end;
    end;procedure TForm1.ShowResults(awin: boolean);
    begin
      if awin then
      begin
        inc(win);
        statusbar1.Panels.Items[0].Text:='Win: '+inttostr(win);
      end
      else
      begin
        inc(lost);
        statusbar1.Panels.Items[1].Text:='Lost: '+inttostr(lost);
      end;
    end;end.
      

  3.   

    //以下是窗体文件:
    object Form1: TForm1
      Left = 227
      Top = 104
      BorderIcons = [biSystemMenu, biMinimize]
      BorderStyle = bsSingle
      Caption = 'Form1'
      ClientHeight = 401
      ClientWidth = 330
      Color = clBtnFace
      Font.Charset = DEFAULT_CHARSET
      Font.Color = clWindowText
      Font.Height = -11
      Font.Name = 'MS Sans Serif'
      Font.Style = []
      OldCreateOrder = False
      Position = poDesktopCenter
      OnClose = FormClose
      OnCreate = FormCreate
      PixelsPerInch = 96
      TextHeight = 13
      object Button1: TButton
        Left = 120
        Top = 336
        Width = 89
        Height = 41
        Caption = 'Call Card'
        TabOrder = 0
        OnClick = Button1Click
      end
      object Button2: TButton
        Left = 8
        Top = 336
        Width = 89
        Height = 41
        Caption = 'New Game'
        TabOrder = 1
        OnClick = Button2Click
      end
      object StatusBar1: TStatusBar
        Left = 0
        Top = 382
        Width = 330
        Height = 19
        Panels = <
          item
            Text = 'Win: 0'
            Width = 80
          end
          item
            Text = 'Lost: 0'
            Width = 80
          end
          item
            Text = 'Points: 0'
            Width = 50
          end>
        SimplePanel = False
      end
      object Button3: TButton
        Left = 232
        Top = 336
        Width = 89
        Height = 41
        Caption = 'Compare'
        TabOrder = 3
        OnClick = Button3Click
      end
      object GroupBox1: TGroupBox
        Left = 0
        Top = 0
        Width = 330
        Height = 329
        Align = alTop
        Caption = 'Your Cards:'
        TabOrder = 4
        object Image1: TImage
          Tag = 1
          Left = 8
          Top = 16
          Width = 73
          Height = 97
          Center = True
          Proportional = True
        end
        object Image2: TImage
          Tag = 2
          Left = 88
          Top = 16
          Width = 73
          Height = 97
          Center = True
          Proportional = True
        end
        object Image3: TImage
          Tag = 3
          Left = 168
          Top = 16
          Width = 73
          Height = 97
          Center = True
          Proportional = True
        end
        object Image4: TImage
          Tag = 4
          Left = 248
          Top = 16
          Width = 73
          Height = 97
          Center = True
          Proportional = True
        end
        object Image8: TImage
          Tag = 8
          Left = 248
          Top = 120
          Width = 73
          Height = 97
          Center = True
          Proportional = True
        end
        object Image7: TImage
          Tag = 7
          Left = 168
          Top = 120
          Width = 73
          Height = 97
          Center = True
          Proportional = True
        end
        object Image6: TImage
          Tag = 6
          Left = 88
          Top = 120
          Width = 73
          Height = 97
          Center = True
          Proportional = True
        end
        object Image5: TImage
          Tag = 5
          Left = 8
          Top = 120
          Width = 73
          Height = 97
          Center = True
          Proportional = True
        end
        object Image9: TImage
          Tag = 9
          Left = 8
          Top = 224
          Width = 73
          Height = 97
          Center = True
          Proportional = True
        end
        object Image10: TImage
          Tag = 10
          Left = 88
          Top = 224
          Width = 73
          Height = 97
          Center = True
          Proportional = True
        end
        object Image11: TImage
          Tag = 11
          Left = 168
          Top = 224
          Width = 73
          Height = 97
          Center = True
          Proportional = True
        end
        object Image12: TImage
          Tag = 12
          Left = 248
          Top = 224
          Width = 73
          Height = 97
          Center = True
          Proportional = True
        end
      end
    end
      

  4.   

    最好是有图片,自己可以做资源文件,再问一下,如何把资源文件做成DLL