: - Turbo ascal.
: ᒺ , ᒺ,
'- () - , ', ( ),
:
1. , - '.
2. - ' ', , ("") "".
3. - , ' , ' , '.
'.
' Turbo Pascal (). , ' , () .
' ( ) , 䳿, - - ' - .
ᒺ .
, , , :
Type
TColumns ='a'..'h'; { }
TRows = 1..8;
{', }
TPosition =object { ' Object}
Column: TColomns; { }
Row: TRows;
Procedure Init (C1:TColumns; Rw:TRows); { ' }
Function GetColumn: TColomns;
Function GetRow: TRows;
end;
! ᒺ . - - .
{ }
{' TPosition}
Procedure TPosition. Init (C1: TColomns; Rw: TRows);
begin
Colomn:= C1;
Row:= Rw;
end;
Function TPosition. GetColomn: TColomns;
Begin
GetColomn: = Colomn;
End;
Function. GetRow: TRowss;
Begin
GetRow: =;
End;
...............................................
, Colomn Row ᒺ TPosition, , - Init, GetColomn, GetRow, , With.
ᒺ .
Var
KingCol: TColumns;
KingRow: TRows;
WKingPos: TPosition; { ᒺ ()}
|
|
Begin
WKingPos. Column: ='e';
WKingPos. Row: = 1;
KingCol: = WKingPos. Column;
KingRow: =WKingPos.Row;
End.
With.
:
Begin
With WKingPos do
Begin
Init ('e', 1);
KingCol: =Getcolemn;
KingRow: =GetRow;
End
ϳ object - ᒺ ' , .
TChessMan (', , ) - TPosition.
Type
TColour=(WhiteColour, BlackColour); { }
TChessMan = object (TPosition)
Private
Colour: TColour
Present: Boolean;
Procedure Init (C1: TColomns; Rw: TRows; BW: TColour);
Procedure Put (Name: String);
Public
Function GetColour: TColour;
Function IsPresent: Boolean;
Procedure Clear;
Procedure Del;
Procedure Display;
End;
Present - , Colour - ( ) - ᒺ - .
:
Ø GetColour, :
Function TChessMan. GetColour: TColour;
Begin
GetColour: = Colour;
End;
Ø IsPresent,
Function TChessMan. IsPresent: Boolean;
Begin
IsPresent: =;
End;
Ø Clear,
Procedure TChessMan. Clear;
Begin
Put (' ');
ErrorMesage (' ');
End;
Ø Del, Clear ;
Procedure. Del;
Begin
Clear
Present: = False;
End;
Ø Display, .
Procedure TChessMan. Display;
Begin
Put ('CM');
End;
Put, GetCoords , .
Procedure TChessMan. Put (Name: String);
var
x, y: Word;
begin
GetCoords (x, y);
Goto (x, y);
if (Row +Ord(Colomn)) mod 2 = 0 then
TextBackGround (Black);
else TextBackGround (White);
case Colour of
WhiteColour: TextColor (LightRed);
BlackColour: TextColor (LightGreen);
end;
Write(Name);
end;
GetCoords ErrorMesage ' TPosition Put ' , .
GetCoords . TPosition , .
GetCoords :
Procedure TPosition. GetCoords (var x, y: Word);
const
BagX=20; BagY=23;
StepX=7; StepY=-3;
begin
X:= BagX + StepX*(Ord(Colomn)-Ord('a'));
Y:= BagY+ StepY* (Row-1);
end;
ErrorMesage .
Procedure TPosition. ErrorMesage (Mes:String);
|
|
Const
BegY=23;
Begin
GotoXY (1,BegY);
TextBackGrond (Blue);
TextColor (LightRed+Blink);
Write (Mes);
End;
TKing = object (TChessMan);
Procedure Init (C1: TColomns; RW: TRows; BW: TColor);
Procedure Move (C1: TColomns; RW: TRows);
Function IsMoveRight (C1: TColomns; RW: TRows): Boolean;
Procedure Display;
End;
Procedure TKing. Init (C1: TColomns; RW: TRows; BW: TColor);
Begin
TChessMan.Init (C1, Rw, BW); { 70 - inherited Init(C1,Rw,BW);}
End;
Procedure TKing. Move (C1: TColomns; RW: TRows);
Begin
If IsMoveRight (C1, RW) then
Begin
Clear;
Colomn: = C1;
Row: = Rw;
Display;
End
Else ErrorMesage (' !');
End;
Function TKing.IsMoveRight (C1: TColomns; RW: TRows): Boolean;
Var DeltaC1, DeltaRw: Word;
Begin
DeltaC1: =Abs (Ord (Colomn) - Ord (C1));
DeltaRw: = Abs (Row - Rw);
If (DeltaC1 >1) or (DeltaRw >1)
Or (DeltaC1 =0) or (DeltaRw =0)
Then IsMoveRight: = False
Else IsMoveRight: = True;
End;
Procedure TKing. Display;
Begin
Put ('Kg');
End;
:
Ø Move ;
Ø IsMoveRigh , .
Ø Display ᒺ TChessMan, , "" ( 'Kg').