All pastes #920894 Raw Edit

Unnamed

public text v1 · immutable
#920894 ·published 2008-02-27 18:08 UTC
rendered paste body
unit Carta;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls;

type
  TCarta = class(TImage)

  private
    { Private declarations }
    procedure SetNCarta(carta2 : String);
    procedure SetFlip(flip2 : Boolean);
    procedure SetAtaqu(ataque2 : Boolean);
    procedure SetTipo(tipo2 : Integer);
    procedure SetSel(sele2 : Boolean);
    procedure SetNome(nome2 : Boolean);
    Function cartan(Texto:string;Posicao:integer;Caractere:Integer):string;
  protected
    { Protected declarations }
    Fncarta: String;
    Fflip: Boolean;
    Fataque: Boolean;
    FTipo: Integer;
    Fsel: Boolean;
    Fnome: Boolean;
  public
    { Public declarations }
    constructor Create(AOwner : TComponent); override;
    destructor Destroy; override;
    procedure repor;
  published
    { Published declarations }
    property NCarta: String read Fncarta write SetNCarta;
    property Flip: Boolean read Fflip write SetFlip default True;
    property Ataque: Boolean read Fataque write SetAtaqu default True;
    property Tipo: Integer read Ftipo write SetTipo default 1;
    property Seleci: Boolean read Fsel write SetSel default False;
    property Vnome: Boolean read Fnome write SetNome default True;
  end;

procedure Register;

var
  CartaS: TShape;
  CartaI: TImage;
  CartaL: TLabel;

implementation

constructor TCarta.Create(AOwner : TComponent);
begin
  inherited Create(AOwner);
  CartaS := TShape.Create(Self);
  CartaI := TImage.Create(Self);
  CartaL := TLabel.Create(Self);
  Height := 79;
  Width := 55;
  CartaS.Pen.Style := psClear;
  CartaS.Width := 60;
  CartaS.Height := 84;
  CartaS.Top := Top - 2;
  CartaS.Left := Left - 2;
  CartaI.Stretch := True;
  CartaI.Height := 43;
  CartaI.Width := 40;
  CartaI.Top := Top + 18;
  CartaI.Left := Left + 7;
  CartaL.Transparent := False;
  CartaL.Color := clWhite;
  CartaL.Constraints.MaxHeight := 11;
  CartaL.Constraints.MaxWidth := 58;
end;

destructor TCarta.Destroy;
begin
  CartaS.Free;
  CartaL.Free;
  CartaI.Free;
  inherited destroy;
end;


Function TCarta.cartan(Texto:string;Posicao:integer;Caractere:Integer):string;
var
i:integer;
ii:integer;
TextoF:string;
begin
i:=1;
ii:=1;
TextoF := '';
if Ord(Texto[1]) <> Caractere then Texto:=chr(Caractere)+Texto;
if Ord(Texto[Length(Texto)]) <> Caractere then Texto:=Texto+chr(Caractere);
while i < Length(Texto) do
begin
inc(i);
if ii = Posicao then TextoF:=TextoF + Texto[i];
if Ord(Texto[i]) = Caractere then inc(ii);
end;
if (Posicao <> 0) then result:=copy(TextoF,1,length(TextoF)-1)
else result:=IntToStr(ii-1);
end;

procedure TCarta.repor;
var
Tem: String;
Texto: String;
STop: Integer;
SLeft: Integer;
ITop: Integer;
ILeft: Integer;
LTop: Integer;
LLeft: Integer;
Carta: String;
Carta2: String;
Sett: String;

begin
  if (Fncarta = '') then
  begin
    exit;
  end;
  if (Fncarta <> '') then  
  CartaL.Caption := cartan(Fncarta,2,124);
  if (fataque = True) then
  begin
    Height := 79;
    Width := 55;
    STop := Top - 2;
    SLeft := Left - 2;
    CartaS.Top := STop;
    CartaS.Left := SLeft;
    CartaS.Height := 84;
    CartaS.Width := 60;
    ITop := Top + 18;
    ILeft := Left + 7;
    CartaI.Top := ITop;
    CartaI.Left := ILeft;
    CartaI.Height := 43;
    CartaI.Width := 40;
    LTop := Top + 12;
    LLeft := Left - 2;
    CartaL.Top := Ltop;
    CartaL.Left := LLeft;
    CartaL.Constraints.MaxHeight := 11;
    CartaL.Constraints.MaxWidth := 58;
  end;
  if (Fflip = False) then
  begin
  Carta := cartan(Fncarta,2,124);
  Carta2 := StringReplace(carta, ' ', '', [rfReplaceAll]);
  Sett := cartan(Fncarta,1,124);
  if (FileExists(ExtractFilePath(ParamStr(0)) +'imagens\cartas\'+ sett +'\'+ carta2 +'.gif')) then
  begin
    Tem := 'sim';
  end
  else
  begin
      Height := 79;
      Width := 55;
      STop := Top - 2;
      SLeft := Left - 2;
      CartaS.Top := STop;
      CartaS.Left := SLeft;
      CartaS.Height := 84;
      CartaS.Width := 60;
      ITop := Top + 18;
      ILeft := Left + 7;
      CartaI.Top := ITop;
      CartaI.Left := ILeft;
      CartaI.Height := 43;
      CartaI.Width := 40;
      LTop := Top + 12;
      LLeft := Left - 2;
      CartaL.Top := Ltop;
      CartaL.Left := LLeft;
      CartaL.Constraints.MaxHeight := 11;
      CartaL.Constraints.MaxWidth := 58;
      CartaL.Visible := False;
      CartaS.Visible := False;
      CartaI.Visible := False;
      Picture.LoadFromFile(ExtractFilePath(ParamStr(0)) +'imagens\ncarta.bmp');
      exit;
    end;
    if (Fnome = True) then
    begin
      CartaL.Visible := True;
    end;
    if (Fnome = False) then
    begin
      CartaL.Visible := False;
    end;
    CartaS.Visible := True;
    CartaI.Visible := True;
    if (Fataque = True) then
    begin
      if FileExists(ExtractFilePath(ParamStr(0)) +'imagens\abaixo.bmp') then
        begin
          Picture.LoadFromFile(ExtractFilePath(ParamStr(0)) +'imagens\abaixo.bmp');
        end;
        exit;
    end;
    if (Fataque = False) then
    begin
      if FileExists(ExtractFilePath(ParamStr(0)) +'imagens\dbaixo.bmp') then
        begin
          Picture.LoadFromFile(ExtractFilePath(ParamStr(0)) +'imagens\dbaixo.bmp');
        end;
        exit;
    end;
  end;
  if (Fflip = True) then

  begin
    if (fataque = True) then
    begin
      if (Ftipo = 1) then
      begin
        if FileExists(ExtractFilePath(ParamStr(0)) +'imagens\amonstro.bmp') then
        begin
          Picture.LoadFromFile(ExtractFilePath(ParamStr(0)) +'imagens\amonstro.bmp');
        end;
      end;
      if (Ftipo = 2) then
      begin
        if FileExists(ExtractFilePath(ParamStr(0)) +'imagens\aefeito.bmp') then
        begin
          Picture.LoadFromFile(ExtractFilePath(ParamStr(0)) +'imagens\aefeito.bmp');
        end;
      end;
      if (Ftipo = 3) then
      begin
        if FileExists(ExtractFilePath(ParamStr(0)) +'imagens\amagica.bmp') then
        begin
          Picture.LoadFromFile(ExtractFilePath(ParamStr(0)) +'imagens\amagica.bmp');
        end;
      end;
      if (Ftipo = 4) then
      begin
        if FileExists(ExtractFilePath(ParamStr(0)) +'imagens\aarmadilha.bmp') then
        begin
          Picture.LoadFromFile(ExtractFilePath(ParamStr(0)) +'imagens\aarmadilha.bmp');
        end;
      end;
      if (Ftipo = 5) then
      begin
        if FileExists(ExtractFilePath(ParamStr(0)) +'imagens\afusao.bmp') then
        begin
          Picture.LoadFromFile(ExtractFilePath(ParamStr(0)) +'imagens\afusao.bmp');
        end;
      end;
      if (Ftipo = 6) then
      begin
        if FileExists(ExtractFilePath(ParamStr(0)) +'imagens\ariual.bmp') then
        begin
          Picture.LoadFromFile(ExtractFilePath(ParamStr(0)) +'imagens\aritual.bmp');
        end;
      end;
      CartaI.Picture.LoadFromFile(ExtractFilePath(ParamStr(0)) +'imagens\cartas\'+ cartan(Fncarta,1,124) +'\'+ StringReplace(cartan(Fncarta,2,124), ' ', '', [rfReplaceAll]) +'.gif');
      exit;
    end;
  end;
end;

procedure TCarta.SetNCarta(carta2 : String);
begin
  if (carta2 = '') then
  begin
    Fncarta := '';
    CartaS.Visible := False;
    CartaL.Visible := False;
    CartaI.Visible := False;
    Visible := False;
    exit;
  end;
  Fncarta := carta2;
  repor;
end;

procedure TCarta.SetFlip(flip2 : Boolean);
begin
  Fflip := flip2;
  repor;
end;

procedure TCarta.SetAtaqu(ataque2 : Boolean);
begin
  Fataque := ataque2;
  repor;
end;

procedure TCarta.SetTipo(tipo2 : Integer);
begin
  if (tipo2 < 1) then
  begin
    tipo2 := 1;
  end;
  if (tipo2 > 6) then
  begin
    tipo2 := 1;
  end;
  ftipo := tipo2;
  repor;
end;

procedure TCarta.SetNome(nome2 : Boolean);
begin
  if (nome2 = True) then
  begin
    CartaL.Visible := True;
    fnome := nome2;
  end;
  if (nome2 = False) then
  begin
    CartaL.Visible := False;
    fnome := nome2;
  end;
end;

procedure TCarta.SetSel(sele2 : Boolean);
begin
  fsel := sele2;
end;

procedure Register;
begin
  RegisterComponents('Game', [TCarta]);
end;

end.