All pastes #292565 Raw Edit

Miscellany

public text v1 · immutable
#292565 ·published 2006-12-26 18:17 UTC
rendered paste body
unit Unit2;

interface

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

type

  TDirection = class
  
  private

    lastkey   : byte;

    bNorth    : boolean;
    bSouth    : boolean;
    bEast     : boolean;
    bWeast    : boolean;

    function GetEast   : boolean;
    function GetNorth  : boolean;
    function GetSouth  : boolean;
    function GetWeast  : boolean;

    procedure SetEast  (const Value: boolean);
    procedure SetNorth (const Value: boolean);
    procedure SetSouth (const Value: boolean);
    procedure SetWeast (const Value: boolean);

    function GetNE: boolean;
    function GetNW: boolean;
    function GetSE: boolean;
    function GetSW: boolean;

    procedure SetNE(const Value: boolean=TRUE);
    procedure SetNW(const Value: boolean=TRUE);
    procedure SetSE(const Value: boolean=TRUE);
    procedure SetSW(const Value: boolean=TRUE);

  public

    function SimultanDir: byte;

    function isBlocked: boolean;

    property North : boolean read GetNorth write SetNorth;
    property South : boolean read GetSouth write SetSouth;
    property East  : boolean read GetEast  write SetEast;
    property Weast : boolean read GetWeast write SetWeast;

    property NE : boolean read GetNE write SetNE;
    property NW : boolean read GetNW write SetNW;
    property SE : boolean read GetSE write SetSE;
    property SW : boolean read GetSW write SetSW;

  end;

implementation

{ TGame }

function TDirection.GetNE: boolean;
begin
  if bNorth=TRUE and bEast=TRUE then Result:=TRUE else Result:=FALSE;
end;

function TDirection.GetNW: boolean;
begin
  if bNorth=TRUE and bWeast=TRUE then Result:=TRUE else Result:=FALSE;
end;

function TDirection.GetSE: boolean;
begin
  if bSouth=TRUE and bEast=TRUE then Result:=TRUE else Result:=FALSE;
end;

function TDirection.GetSW: boolean;
begin
  if bSouth=TRUE and bEast=TRUE then Result:=TRUE else Result:=FALSE;
end;

function TDirection.SimultanDir: byte;
begin
  Result:=0;
  if   bNorth  =  TRUE   then Inc(Result);
  if   bSouth  =  TRUE   then Inc(Result);
  if   bEast   =  TRUE   then Inc(Result);
  if   bWeast  =  TRUE   then Inc(Result);
end;

function TDirection.isBlocked: boolean;
begin
  Result:=FALSE;
  if SimultanDir>2 then Result:=TRUE
  else if (  bEast=TRUE and bWeast=TRUE   ) then Result:=TRUE
  else if (  bNorth=TRUE and bSouth=TRUE  ) then Result:=TRUE
end;

function TDirection.GetEast: boolean;
begin
  Result:=bEast;
end;

function TDirection.GetNorth: boolean;
begin
  Result:=bNorth;
end;

function TDirection.GetSouth: boolean;
begin
  Result:=bSouth;
end;

function TDirection.GetWeast: boolean;
begin
  Result:=bWeast;
end;

procedure TDirection.SetEast(const Value: boolean);
begin
  bEast:=Value;
end;

procedure TDirection.SetNorth(const Value: boolean);
begin
  bNorth:=Value;
end;

procedure TDirection.SetSouth(const Value: boolean);
begin
  bSouth:=Value;
end;

procedure TDirection.SetWeast(const Value: boolean);
begin
  bWeast:=Value;
end;

procedure TDirection.SetNE(const Value: boolean=TRUE);
begin
  if ( Value=TRUE ) then
                    begin
                      SetEast(TRUE);
                      SetNorth(TRUE);
                    end
end;

procedure TDirection.SetNW(const Value: boolean=TRUE);
begin
  if ( Value=TRUE ) then
                    begin
                      SetWeast(TRUE);
                      SetNorth(TRUE);
                    end
end;

procedure TDirection.SetSE(const Value: boolean=TRUE);
begin

end;

procedure TDirection.SetSW(const Value: boolean=TRUE);
begin

end;

end.