Vanilla_Fury

laba_7_3_del

Jun 9th, 2021
637
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 6.53 KB | None | 0 0
  1. unit MainForm;
  2.  
  3. interface
  4.  
  5. uses
  6.     Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
  7.     System.Classes, Vcl.Graphics,
  8.     Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, Vcl.StdCtrls, Vcl.Menus;
  9.  
  10. type
  11.     TAnimeForm = class(TForm)
  12.         Timer1: TTimer;
  13.     ImageCanvas: TImage;
  14.     LabelSpeed: TLabel;
  15.         MainMenu1: TMainMenu;
  16.         N5: TMenuItem;
  17.         LabelToMeasureScreenOfUser: TLabel;
  18.         procedure FormCreate(Sender: TObject);
  19.         procedure Timer1Timer(Sender: TObject);
  20.         procedure FormKeyDown(Sender: TObject; var Key: Word;
  21.           Shift: TShiftState);
  22.         procedure N5Click(Sender: TObject);
  23.     private
  24.         MultPix: Single;
  25.     public
  26.         function MultPixels(PixQuant: Integer): Integer;
  27.     end;
  28.  
  29. const
  30.     My300 = 300;
  31.     My500 = 500;
  32.  
  33. var
  34.     AnimeForm: TAnimeForm;
  35.     BackGround: TBitMap;
  36.     Ship: TBitMap;
  37.     Can: TBitMap;
  38.     Bomb: TBitMap;
  39.     X, Y, X1, Y1: Integer;
  40.     Shx, ShXBmb, ShYBmb, Time: Integer;
  41.     Napravlenie: Integer;
  42.     Speed: Integer;
  43.     BallIsFlying: Boolean;
  44.  
  45. procedure MyMessageBoxInfo(Form: TForm; CaptionWindow, TextMessage: String; IsWarning: Boolean = False); external 'Dll_MyMessageBox.dll';
  46. function MyMessageBoxYesNo(Form: TForm; CaptionWindow, TextMessage: String; IsWarning: Boolean = False) : Boolean; external 'Dll_MyMessageBox.dll';
  47.  
  48. implementation
  49.  
  50. {$R *.dfm}
  51.  
  52. procedure TAnimeForm.FormCreate(Sender: TObject);
  53. begin
  54.     MultPix := LabelToMeasureScreenOfUser.Width / 100;
  55.  
  56.     BallIsFlying := False;
  57.  
  58.     Shx := Random(4) + 1;
  59.  
  60.     Time := 0;
  61.     X := -My300;
  62.     Y1 := My500;
  63.     Y := 80;
  64.     X1 := 1000;
  65.     ShYBmb := 0;
  66.     ShXBmb := 1;
  67.     Speed := 1;
  68.     BackGround := TBitMap.Create;
  69.     Ship := TBitMap.Create;
  70.     Can := TBitMap.Create;
  71.     Bomb := TBitMap.Create;
  72.  
  73.     BackGround.LoadFromFile('more.bmp');
  74.  
  75.     Ship.LoadFromFile('ship.bmp');
  76.     Can.LoadFromFile('cn1.bmp');
  77.     Ship.transparent := true;
  78.     Can.transparent := true;
  79.     Bomb.transparent := true;
  80.  
  81.     ImageCanvas.Canvas.Draw(0, 0, BackGround);
  82.     ImageCanvas.Canvas.Draw(X, 80, Ship);
  83.     ImageCanvas.Canvas.Draw(My300, My300, Can);
  84.     Napravlenie := 0;
  85. end;
  86.  
  87. procedure ChangeCannnon(Num: Integer);
  88. Begin
  89.     case Num of
  90.         0:
  91.             Can.LoadFromFile('cn1.bmp');
  92.         1:
  93.             Can.LoadFromFile('cn2.bmp');
  94.         -1:
  95.             Can.LoadFromFile('cn4.bmp');
  96.     end;
  97. End;
  98.  
  99. procedure TAnimeForm.FormKeyDown(Sender: TObject; var Key: Word;
  100.   Shift: TShiftState);
  101. begin
  102.     if not BallIsFlying then
  103.     begin
  104.         case Key of
  105.             49, 97:
  106.                 begin
  107.                     Speed := 1;
  108.                 end;
  109.             50, 98:
  110.                 begin
  111.                     Speed := 2;
  112.                 end;
  113.             51, 99:
  114.                 begin
  115.                     Speed := 3;
  116.                 end;
  117.             52, 100:
  118.                 begin
  119.                     Speed := 4;
  120.                 end;
  121.             53, 101:
  122.                 begin
  123.                     Speed := 5;
  124.                 end;
  125.             54, 102:
  126.                 begin
  127.                     Speed := 6;
  128.                 end;
  129.             55, 103:
  130.                 begin
  131.                     Speed := 7;
  132.                 end;
  133.             56, 104:
  134.                 begin
  135.                     Speed := 8;
  136.                 end;
  137.             57, 105:
  138.                 begin
  139.                     Speed := 9;
  140.                 end;
  141.         end;
  142.         LabelSpeed.Caption := 'Скорость снаряда: ' + IntToStr(Speed);
  143.         ShXBmb := Speed;
  144.         ShYBmb := Speed;
  145.         if Napravlenie <> -1 then
  146.             if Key = 37 then
  147.             Begin
  148.                 Dec(Napravlenie);
  149.                 X1 := 2000;
  150.             End;
  151.         if Napravlenie <> 1 then
  152.             if Key = 39 then
  153.             begin
  154.                 Inc(Napravlenie);
  155.                 X1 := 2000;
  156.             end;
  157.         ChangeCannnon(Napravlenie);
  158.         if ((Key = 13) or (Key = 32)) then
  159.         Begin
  160.             BallIsFlying := True;
  161.             Y1 := 520;
  162.             case Napravlenie of
  163.                 0:
  164.                     Begin
  165.                         Y1 := My500;
  166.                         X1 := 450;
  167.                     End;
  168.                 1:
  169.                     X1 := 540;
  170.                 -1:
  171.                     X1 := 390;
  172.             end;
  173.             Bomb.LoadFromFile('bomb.bmp');
  174.         End;
  175.     end;
  176. end;
  177.  
  178. procedure TAnimeForm.N5Click(Sender: TObject);
  179. begin
  180.     MyMessageBoxInfo(AnimeForm, 'Справка', 'Данная программа представляет собой игру, целью которой стоит уничтожение плывущего корабля.'
  181.       + #10#10 +
  182.       'Управление пушкой происходит с помощью стрелок на клавиатуре.'
  183.       + #10 + 'Кнопки от 1 до 9 задают скорость снаряда.' + #10#10 +
  184.       'Для выстрела нажмите Enter или Пробел' + #10#10 +
  185.       'Автор: Панев Александр, гр. 051007' + #10 + 'Минск, 2021');
  186. end;
  187.  
  188. procedure TAnimeForm.Timer1Timer(Sender: TObject);
  189. begin
  190.     X := X + Shx;
  191.     Y1 := Y1 - ShYBmb;
  192.     if X > 950 then
  193.     begin
  194.         X := -600;
  195.         ShYBmb := 0;
  196.         Y1 := 1000;
  197.         BallIsFlying := False;
  198.     end;
  199.     ImageCanvas.Canvas.Draw(0, 0, BackGround);
  200.     ImageCanvas.Canvas.Draw(X, Y, Ship);
  201.     ImageCanvas.Canvas.Draw(-170, 30, Can);
  202.  
  203.     Y1 := Y1 - ShYBmb;
  204.     X1 := X1 + Napravlenie * ShXBmb;
  205.  
  206.     ImageCanvas.Canvas.Draw(X1, Y1, Bomb);
  207.     if ((Y1 < 195) and ((X1 - X) < My300) And ((X1 - X) > 0)) then
  208.     Begin
  209.         Ship.LoadFromFile('boom.bmp');
  210.         Shx := 0;
  211.         Time := 0;
  212.         BallIsFlying := False;
  213.     End;
  214.  
  215.     if Y1 < 195 then
  216.     begin
  217.         BallIsFlying := False;
  218.         X1 := 2000;
  219.     end;
  220.  
  221.  
  222.     if Shx = 0 then
  223.         Inc(Time);
  224.     if Time = 50 then
  225.         Y := 1000;
  226.     if Time = 30 then
  227.     begin
  228.         if MyMessageBoxYesNo(AnimeForm, 'Продолжить играть?', 'Отличный выстрел, хотите попробовать снова?') then
  229.         Begin
  230.             Ship.LoadFromFile('ship.bmp');
  231.             Y := 80;
  232.             X := -My300;
  233.             Shx := Random(4) + 1;
  234.         End
  235.         else
  236.             AnimeForm.Close;
  237.     end;
  238. end;
  239.  
  240. function TAnimeForm.MultPixels(PixQuant: Integer): Integer;
  241. begin
  242.     Result := Round(PixQuant * MultPix);
  243. end;
  244.  
  245. end.
Advertisement
Add Comment
Please, Sign In to add comment