home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 1998 October
/
PCWorld_1998-10_cd.bin
/
software
/
prehled
/
komix
/
DATA.Z
/
TicTacToe_CellUnit.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1997-08-20
|
4KB
|
180 lines
//
// File : TicTacToe_CellUnit.pas
//
// Project : PCProject
// Configuration : PCConfig 1
// Phase : Implementation 1
// System : TicTacToe 1
//
unit TicTacToe_CellUnit;
interface
uses
// Start user include section
// End user include section
ClassDict;
type
// Cell of the board.
TicTacToe_Cell = class
private
// User defined attributes
contents: String (* = ' ' *);
// Association attributes
neighbourDict: TClassDict;
// User defined methods
// Properties
protected
// User defined attributes
// User defined methods
// Properties
public
// User defined attributes
// Default constructor/destructor
constructor Create;
destructor Destroy; override;
// User defined methods
function getLine(dir: String; x: String): Integer;
function getMaxLine: Integer;
// Access methods
function getContents: String;
procedure setContents(newContents: String);
// Association methods
procedure setNeighbour(Direction: String; newTicTacToe_Cell: TicTacToe_Cell);
function getNeighbour(Direction: String): TicTacToe_Cell;
procedure removeNeighbour(Direction: String);
// Properties
published
// User defined attributes
// User defined methods
// Properties
end;
implementation
// Start user include section
// End user include section
constructor TicTacToe_Cell.Create;
// Start user section
// End user section
begin
contents := ' ';
inherited Create;
neighbourDict := TClassDict.Create;
// Start user section
// End user section
end;
destructor TicTacToe_Cell.Destroy;
// Start user section
// End user section
begin
// Start user section
// End user section
neighbourDict.Destroy;
inherited Destroy;
end;
// Returns the highest number of connected cells in a line in a specific
// direction, where each cell contains the same specified symbol.
function TicTacToe_Cell.getLine(dir: String; x: String): Integer;
var
temp : TicTacToe_Cell;
retValue : Integer;
begin
retValue := 0;
if getContents() = 'X' then
begin
retValue := 1;
temp := getNeighbour(dir);
if (temp <> NIL) then
retValue := retValue + temp.getLine(dir, x);
end;
getLine := retValue;
end;
// Returns the highest number of connected cells in a line,
// where each cell contains the same symbol as this cell.
function TicTacToe_Cell.getMaxLine: Integer;
var
MaxValue: Integer;
LineValue: Integer;
begin
MaxValue := getLine('N', getContents()) + getLine('S', getContents()) - 1;
LineValue := getLine('E', getContents()) + getLine('W', getContents()) - 1;
if (MaxValue < LineValue) then MaxValue := LineValue;
LineValue := getLine('NE', getContents()) + getLine('SW', getContents()) - 1;
if (MaxValue < LineValue) then MaxValue := LineValue;
LineValue := getLine('NW', getContents()) + getLine('SE', getContents()) - 1;
if (MaxValue < LineValue) then MaxValue := LineValue;
getMaxLine := MaxValue;
end;
// Do not delete this line -- regeneration marker
function TicTacToe_Cell.getContents: String;
begin
getContents := contents;
end;
procedure TicTacToe_Cell.setContents(newContents: String);
begin
contents := newContents;
end;
procedure TicTacToe_Cell.setNeighbour(Direction: String; newTicTacToe_Cell: TicTacToe_Cell);
begin
if (newTicTacToe_Cell <> NIL) then
begin
neighbourDict.Add(Direction, newTicTacToe_Cell);
end;
end;
function TicTacToe_Cell.getNeighbour(Direction: String): TicTacToe_Cell;
begin
getNeighbour := neighbourDict.Item(Direction);
end;
procedure TicTacToe_Cell.removeNeighbour(Direction: String);
begin
neighbourDict.RemoveUsingKey(Direction)
end;
end.