Advertisement
anticlown

Lab.6.1.Full(Delphi)

Apr 14th, 2023
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 7.70 KB | None | 0 0
  1. Unit RacingMain;
  2.  
  3. Interface
  4.  
  5. Uses
  6.     Winapi.Windows,
  7.     Winapi.Messages,
  8.     System.SysUtils,
  9.     System.Variants,
  10.     System.Classes,
  11.     Vcl.Graphics,
  12.     Vcl.Controls,
  13.     Vcl.Forms,
  14.     Vcl.Dialogs,
  15.     Vcl.StdCtrls,
  16.     Vcl.Buttons,
  17.     Vcl.ExtCtrls,
  18.     System.ImageList,
  19.     Vcl.ImgList,
  20.     Vcl.VirtualImageList,
  21.     Vcl.VirtualImage;
  22.  
  23. Type
  24.     TfrmMain = Class(TForm)
  25.         GrpBack: TGridPanel;
  26.         PButtons: TPanel;
  27.         SdbtHelp: TSpeedButton;
  28.         SdbtStart: TSpeedButton;
  29.         LbTaskInfo: TLabel;
  30.         VilImages_42: TVirtualImageList;
  31.         VilPictures: TVirtualImageList;
  32.         PRace: TPanel;
  33.         ShpSecondRunner: TShape;
  34.         ShpThirdRunner: TShape;
  35.         SdbtInfoAboutDeveloper: TSpeedButton;
  36.         SdbtExit: TSpeedButton;
  37.         ShpTrack: TShape;
  38.         ShpFirstSeparator: TShape;
  39.         ShpSecondSeparator: TShape;
  40.         ShpFirstRunner: TShape;
  41.         ShpStartLine: TShape;
  42.         ShpFinishLine: TShape;
  43.         PResult: TPanel;
  44.         LbAnswer: TLabel;
  45.         BllnhHint: TBalloonHint;
  46.         Procedure FormCloseQuery(Sender: TObject; Var CanClose: Boolean);
  47.         Procedure SdbtHelpClick(Sender: TObject);
  48.         Procedure SdbtExitClick(Sender: TObject);
  49.         Procedure SdbtInfoAboutDeveloperClick(Sender: TObject);
  50.         Procedure SdbtStartClick(Sender: TObject);
  51.         Procedure FormKeyDown(Sender: TObject; Var Key: Word; Shift: TShiftState);
  52.     End;
  53.  
  54. Var
  55.     FrmMain: TfrmMain;
  56.  
  57. Implementation
  58.  
  59. {$R *.dfm}
  60.  
  61. Uses RacingDataPictures;
  62.  
  63. Procedure Delay(Value: Cardinal);
  64. Var
  65.     F, N: Cardinal;
  66. Begin
  67.     N := 0;
  68.     While N <= (Value Div 10) Do
  69.     Begin
  70.         SleepEx(1, True);
  71.         Application.ProcessMessages;
  72.         Inc(N);
  73.     End;
  74.  
  75.     F := GetTickCount;
  76.  
  77.     Repeat
  78.         Application.ProcessMessages;
  79.         N := GetTickCount;
  80.     Until (N - F >= (Value Mod 10)) Or (N < F);
  81. End;
  82.  
  83. Procedure TfrmMain.FormCloseQuery(Sender: TObject; Var CanClose: Boolean);
  84. Begin
  85.     If Application.MessageBox(PChar('Вы уверены, что хотите выйти?'), PChar('Выход'),
  86.         MB_ICONQUESTION + MB_YESNO + MB_DEFBUTTON1 + MB_TASKMODAL) = IDYES Then
  87.         CanClose := True
  88.     Else
  89.         CanClose := False;
  90. End;
  91.  
  92. Procedure TfrmMain.FormKeyDown(Sender: TObject; Var Key: Word; Shift: TShiftState);
  93. Begin
  94.     If (Key = VK_RETURN) And (SdbtStart.Enabled = True) Then
  95.         SdbtStartClick(Sender);
  96. End;
  97.  
  98. Procedure TfrmMain.SdbtExitClick(Sender: TObject);
  99. Begin
  100.     Close;
  101. End;
  102.  
  103. Procedure TfrmMain.SdbtHelpClick(Sender: TObject);
  104. Const
  105.     FIRST_MESSAGE = 'В данной программе не нужно ничего вводить!' + #13#10;
  106.     SECOND_MESSAGE = 'Просто наслаждайтесь забегом лучших фигур во всем мире!' + #13#10;
  107.     THIRD_MESSAGE =
  108.         '- Для удобного использования программы представлена последовательсноть кнопок на верхней панели.';
  109. Begin
  110.     Application.MessageBox(FIRST_MESSAGE + SECOND_MESSAGE + THIRD_MESSAGE, 'Справка');
  111. End;
  112.  
  113. Procedure TfrmMain.SdbtInfoAboutDeveloperClick(Sender: TObject);
  114. Const
  115.     FIRST_MESSAGE = 'Ф.И.О.: Карась А.С. a.k.a Clownfish' + #13#10;
  116.     SECOND_MESSAGE = 'Группа: 251004' + #13#10;
  117.     THIRD_MESSAGE = 'Контакты: предварительная запись вживую по адресу' + #13#10;
  118.     FOURTH_MESSAGE = 'г.Гродно, ул.Мостовая, д.31';
  119. Begin
  120.     Application.MessageBox(FIRST_MESSAGE + SECOND_MESSAGE + THIRD_MESSAGE + FOURTH_MESSAGE,
  121.         'О разработчике');
  122. End;
  123.  
  124. Procedure TfrmMain.SdbtStartClick(Sender: TObject);
  125. Const
  126.     START_SPEED = 5;
  127.     MAX_SPEED = 15;
  128. Var
  129.     FirstRunnerSpeed, SecondRunnerSpeed, ThirdRunnerSpeed, FirstRunnerPlace, SecondRunnerPlace,
  130.         ThirdRunnerPlace: Integer;
  131. Begin
  132.     SdbtStart.Enabled := False;
  133.     Randomize;
  134.     FirstRunnerSpeed := START_SPEED;
  135.     SecondRunnerSpeed := START_SPEED;
  136.     ThirdRunnerSpeed := START_SPEED;
  137.  
  138.     While Not((ShpFinishLine.Left - ShpFirstRunner.Left < 1) And
  139.         (ShpFinishLine.Left - ShpSecondRunner.Left < 1) And
  140.         (ShpFinishLine.Left - ShpFirstRunner.Left < 1)) Do
  141.     Begin
  142.         Delay(15);
  143.         If ShpFirstRunner.Left > ShpFinishLine.Left Then
  144.             FirstRunnerSpeed := 0
  145.         Else
  146.         Begin
  147.             FirstRunnerSpeed := FirstRunnerSpeed + Random(21) - 10;
  148.             If FirstRunnerSpeed < 0 Then
  149.                 FirstRunnerSpeed := 1;
  150.             If FirstRunnerSpeed > MAX_SPEED Then
  151.                 FirstRunnerSpeed := MAX_SPEED;
  152.             ShpFirstRunner.Left := ShpFirstRunner.Left + FirstRunnerSpeed;
  153.         End;
  154.         If ShpSecondRunner.Left > ShpFinishLine.Left Then
  155.             SecondRunnerSpeed := 0
  156.         Else
  157.         Begin
  158.             SecondRunnerSpeed := SecondRunnerSpeed + Random(21) - 10;
  159.             If SecondRunnerSpeed < 0 Then
  160.                 SecondRunnerSpeed := 1;
  161.             If SecondRunnerSpeed > MAX_SPEED Then
  162.                 SecondRunnerSpeed := MAX_SPEED;
  163.             ShpSecondRunner.Left := ShpSecondRunner.Left + SecondRunnerSpeed;
  164.         End;
  165.         If ShpThirdRunner.Left > ShpFinishLine.Left Then
  166.             ThirdRunnerSpeed := 0
  167.         Else
  168.         Begin
  169.             ThirdRunnerSpeed := SecondRunnerSpeed + Random(20) - 10;
  170.             If ThirdRunnerSpeed < 0 Then
  171.                 ThirdRunnerSpeed := 1;
  172.             If ThirdRunnerSpeed > MAX_SPEED Then
  173.                 ThirdRunnerSpeed := MAX_SPEED;
  174.             ShpThirdRunner.Left := ShpThirdRunner.Left + ThirdRunnerSpeed;
  175.         End;
  176.     End;
  177.  
  178.     If (ShpFirstRunner.Left > ShpSecondRunner.Left) And
  179.         (ShpFirstRunner.Left > ShpThirdRunner.Left) Then
  180.     Begin
  181.         FirstRunnerPlace := 1;
  182.         If (ShpSecondRunner.Left > ShpThirdRunner.Left) Then
  183.         Begin
  184.             SecondRunnerPlace := 2;
  185.             ThirdRunnerPlace := 3;
  186.         End
  187.         Else
  188.         Begin
  189.             SecondRunnerPlace := 3;
  190.             ThirdRunnerPlace := 2;
  191.         End;
  192.     End
  193.     Else
  194.     Begin
  195.         If (ShpSecondRunner.Left > ShpThirdRunner.Left) Then
  196.         Begin
  197.             SecondRunnerPlace := 1;
  198.             If (ShpThirdRunner.Left > ShpFirstRunner.Left) Then
  199.             Begin
  200.                 ThirdRunnerPlace := 2;
  201.                 FirstRunnerPlace := 3;
  202.             End
  203.             Else
  204.             Begin
  205.                 ThirdRunnerPlace := 3;
  206.                 FirstRunnerPlace := 2;
  207.             End;
  208.         End
  209.         Else
  210.         Begin
  211.             ThirdRunnerPlace := 1;
  212.             If (ShpSecondRunner.Left > ShpFirstRunner.Left) Then
  213.             Begin
  214.                 SecondRunnerPlace := 2;
  215.                 FirstRunnerPlace := 3;
  216.             End
  217.             Else
  218.             Begin
  219.                 SecondRunnerPlace := 3;
  220.                 FirstRunnerPlace := 2;
  221.             End;
  222.         End;
  223.     End;
  224.  
  225.     LbAnswer.Visible := True;
  226.     LbAnswer.Caption := LbAnswer.Caption + ' красный - ' + IntToStr(FirstRunnerPlace) +
  227.         ' место, зеленый  - ' + IntToStr(SecondRunnerPlace) + ' место, синий  - ' +
  228.         IntToStr(ThirdRunnerPlace) + ' место! Поздравляем участников!!!';
  229. End;
  230.  
  231. End.
  232.  
  233. Unit RacingDataPictures;
  234.  
  235. Interface
  236.  
  237. Uses
  238.     System.SysUtils,
  239.     System.Classes,
  240.     Vcl.BaseImageCollection,
  241.     Vcl.ImageCollection;
  242.  
  243. Type
  244.     TdtmdPictures = Class(TDataModule)
  245.         ImcForButtons: TImageCollection;
  246.         ImcPictures: TImageCollection;
  247.     End;
  248.  
  249. Var
  250.     DtmdPictures: TdtmdPictures;
  251.  
  252. Implementation
  253.  
  254. {%CLASSGROUP 'Vcl.Controls.TControl'}
  255. {$R *.dfm}
  256.  
  257. End.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement