Модератор: Модераторы
sudo apt-get install lazarus-ide
sudo apt-get install fpc-source
program Project1;
{$mode objfpc}{$H+}{$interfaces CORBA}
Uses sysutils, Crt;
Type
{ TCountry }
TCountry = Class
Private
fIsShitty: Boolean;
fName: String;
fXPosition: Integer;
Public
Property Name: String Read fName;
Property IsShitty: Boolean Read fIsShitty;
Property XPosition: Integer Read fXPosition;
Constructor Create(Const aName: String; Const aIsShitty: Boolean;
Const aXPosition: Integer);
End;
Type IDriver = Interface
Procedure SetXPosition(Const aNewXPosition: Integer);
Function GetXPosition: Integer;
End;
Type
{ TTransport }
TTransport = Class
Private
fDestination: TCountry;
fDiver: IDriver;
fDriver: IDriver;
fName: String;
fXPosition: Integer;
Function GetIsReached: Boolean;
Procedure SetDiver(aValue: IDriver);
Public
Property Name: String Read fName;
Property IsReached: Boolean Read GetIsReached;
Property Destination: TCountry Read fDestination Write fDestination;
Property XPosition: Integer Read fXPosition;
Property Driver: IDriver Read fDriver Write SetDiver;
Procedure Move;
Constructor Create(Const aName: String);
End;
Type
{ TPig }
TPig = Class(IDriver)
Private
fCountry: TCountry;
fName: String;
fXPosition: Integer;
Procedure SetXPosition(Const aNewXPosition: Integer);
Function GetXPosition: Integer;
Public
Property Name: String Read fName;
Property Country: TCountry Read fCountry;
Property XPosition: Integer Read fXPosition;
Constructor Create(Const aName: String; Const aCountry: TCountry);
End;
{ TPig }
Procedure TPig.SetXPosition(Const aNewXPosition: Integer);
Begin
fXPosition := aNewXPosition;
End;
Function TPig.GetXPosition: Integer;
Begin
Result := XPosition;
End;
Constructor TPig.Create(Const aName: String; Const aCountry: TCountry);
Begin
fName := aName;
fCountry := aCountry;
End;
{ TTransport }
Function TTransport.GetIsReached: Boolean;
Begin
Result := XPosition = Destination.XPosition;
end;
Procedure TTransport.SetDiver(aValue: IDriver);
Begin
If fDriver = aValue Then Exit;
If Not(XPosition = aValue.GetXPosition) Then
Raise Exception.Create('Сначала надо подойти к транспорту');
fDriver := aValue;
End;
Procedure TTransport.Move;
Begin
If Driver = nil Then Raise Exception.Create('Нет водителя!');
If XPosition < Destination.XPosition Then fXPosition := fXPosition + 1
Else fXPosition := fXPosition + 1;
Driver.SetXPosition(XPosition);
End;
Constructor TTransport.Create(Const aName: String);
Begin
fName := aName;
End;
{ TCountry }
Constructor TCountry.Create(Const aName: String; Const aIsShitty: Boolean;
Const aXPosition: Integer);
Begin
fName := aName;
fIsShitty := aIsShitty;
fXPosition := aXPosition;
End;
Var
aPetr: TPig;
aTraktor: TTransport;
aRusska, aAbroad: TCountry;
begin
aRusska := TCountry.Create('Рашка', TRUE, 0);
aAbroad := TCountry.Create('Заграница', FALSE, 40);
aPetr := TPig.Create('Петр', aRusska);
aTraktor := TTransport.Create('Трактор');
aTraktor.Driver := aPetr;
aTraktor.Destination := aAbroad;
While Not(aTraktor.IsReached) Do
Begin
GotoXY(aTraktor.XPosition, 1);
Write(' ');
aTraktor.Move;
GotoXY(aTraktor.XPosition, 1);
Write('t');
Sleep(100);
End;
WriteLn;
WriteLn('Трактор доехал по горизонтали');
end.
Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 25