From fd6d48d3f1a5f07022fa3a821ff7fb0a5ebb2ccf Mon Sep 17 00:00:00 2001 From: goblinrf Date: Mon, 30 Oct 2023 23:31:52 +0300 Subject: [PATCH 1/3] Process --- .idea/.gitignore | 3 + .../PIbd_23_Kislitsa_E.D_AirFighter_Hard.iml | 12 ++ .idea/misc.xml | 6 + .idea/modules.xml | 8 + .idea/uiDesigner.xml | 124 +++++++++++ .idea/vcs.xml | 6 + DownButton.png | Bin 0 -> 532 bytes LeftButton.png | Bin 0 -> 740 bytes RightButton.png | Bin 0 -> 843 bytes UpButton.png | Bin 0 -> 1057 bytes src/AirFighterHard/DrawningAirFighter.java | 189 ----------------- src/AirFighterHard/EntityAirFighter.java | 38 ---- src/AirFighterHard/Main.java | 96 --------- src/{AirFighterHard => }/DirectionType.java | 3 +- src/DrawningObjects/DrawningAirFighter.java | 69 +++++++ src/DrawningObjects/DrawningAirplane.java | 161 +++++++++++++++ .../DrawningEngines.java | 19 +- src/DrawningObjects/IDraw.java | 10 + src/Entities/EntityAirFighter.java | 22 ++ src/Entities/EntityAirplane.java | 26 +++ src/FormAirFighter.java | 193 ++++++++++++++++++ src/Main.java | 19 ++ src/MovementStrategy/AbstractStrategy.java | 69 +++++++ .../DrawningObjectAirplane.java | 31 +++ src/MovementStrategy/IMoveableObject.java | 10 + src/MovementStrategy/MoveToBorder.java | 36 ++++ src/MovementStrategy/MoveToCenter.java | 52 +++++ src/MovementStrategy/ObjectParameters.java | 27 +++ src/MovementStrategy/Status.java | 7 + src/{AirFighterHard => }/NumberType.java | 5 +- src/README.md | 2 + 31 files changed, 907 insertions(+), 336 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/PIbd_23_Kislitsa_E.D_AirFighter_Hard.iml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/uiDesigner.xml create mode 100644 .idea/vcs.xml create mode 100644 DownButton.png create mode 100644 LeftButton.png create mode 100644 RightButton.png create mode 100644 UpButton.png delete mode 100644 src/AirFighterHard/DrawningAirFighter.java delete mode 100644 src/AirFighterHard/EntityAirFighter.java delete mode 100644 src/AirFighterHard/Main.java rename src/{AirFighterHard => }/DirectionType.java (73%) create mode 100644 src/DrawningObjects/DrawningAirFighter.java create mode 100644 src/DrawningObjects/DrawningAirplane.java rename src/{AirFighterHard => DrawningObjects}/DrawningEngines.java (81%) create mode 100644 src/DrawningObjects/IDraw.java create mode 100644 src/Entities/EntityAirFighter.java create mode 100644 src/Entities/EntityAirplane.java create mode 100644 src/FormAirFighter.java create mode 100644 src/Main.java create mode 100644 src/MovementStrategy/AbstractStrategy.java create mode 100644 src/MovementStrategy/DrawningObjectAirplane.java create mode 100644 src/MovementStrategy/IMoveableObject.java create mode 100644 src/MovementStrategy/MoveToBorder.java create mode 100644 src/MovementStrategy/MoveToCenter.java create mode 100644 src/MovementStrategy/ObjectParameters.java create mode 100644 src/MovementStrategy/Status.java rename src/{AirFighterHard => }/NumberType.java (65%) create mode 100644 src/README.md diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/PIbd_23_Kislitsa_E.D_AirFighter_Hard.iml b/.idea/PIbd_23_Kislitsa_E.D_AirFighter_Hard.iml new file mode 100644 index 0000000..852166e --- /dev/null +++ b/.idea/PIbd_23_Kislitsa_E.D_AirFighter_Hard.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..432b646 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..598c828 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..2b63946 --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/DownButton.png b/DownButton.png new file mode 100644 index 0000000000000000000000000000000000000000..01d7c5beabee287a4fa7e4b9d3c97f2f378f1129 GIT binary patch literal 532 zcmV+v0_**WP)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGh)c^nu)d4-$ zSn&V=02y>eSaefwW^{L9a%BK_cXuvnZfkR6VQ^(GZ*pgw?mQX*00DGKL_t(YOYN31 zio#G7MH3tAAYyGJVqsxpVPj(>xBz#P9avb|*|`}(uy6wbK@dSi#75^#{>@DMCf_i{ zR5>8zy?5_XEJW{FfZ1&3rC`*-Nkwrd=kr-lG1izzA@$!V)fT1NqEuUyYK#9>FPF<^ zv$@;tG&>j2=f3Zo zKGf^=&1Sc`{JZnqUosMTug_4-}Sl9T2H>PV!sK6MmDtyW9H zgdhkelZl2HMwS{9C{mXw#{RDN`+cX=QM@ozC`yrFtKo1sbh}-Z3P6~O$|*9`a6BG+ zy`HL0h!Ixpm25SfPN#mqFF_6jh^g>Kt{V8iF&GS_d4m%HMYC|J;c~eQheOFyu;ipr z4j literal 0 HcmV?d00001 diff --git a/LeftButton.png b/LeftButton.png new file mode 100644 index 0000000000000000000000000000000000000000..3a5f2a6484e25d385318ec148f103a770ddc0349 GIT binary patch literal 740 zcmVPx#1ZP1_K>z@;j|==^1poj532;bRa{vGmbN~PnbOGLGA9w%&0(nV9K~zXft(HGX za#0k(?|VuPV*Y{rGgy<8lTA8U4vGyU#5OeW-KuCK4N+3e-zWhRrMA;J8X zI+x4E<8fFp4Abp)4-O76E)bUf{zs?NNu^S_UM`n!Z*RC34u9&=XmomdI-AW1GF&d5b`+e$!+}_?ob}EA5Nqu*B_w@8cg^=^}^FSa#MGXIb#zv#z^ZDlU zIjYTOE0@bVJ3FYN*hu~H@!@nj2ZI5sR;#VmYG$(;RV?d*z>~teb9q^oeRz0~oEKQ9 zzPY)nR4P;mNhXtCua}A>XhBM)5_~Jz8yJPMJU%|kWHMA~tWv+ezCte8%NQ~mjrDqc zZ*LD(GR)`a=gG-QtJR_bLL!lf!{MMJ35`bMa=Az%k)VOC5{t!FhnU({QLEJ~bTw+* zh7E;6bh%Z+;V|>{_2qWE+wC@u5dyu*ZnsmB1QhxB_;|JXUS3{~j*hs^XEK?p)v8{v zN0rR#G{X3}zrW{-{{H@cadEL&EKnsQySlo9AB)8@olcw0CPuMY!>gc5W8L}SF`=Ep zIYfo_R45cY9uKMneru{ao$mShd4GQ&RV*7*#$YhO)j%$nqYj6|v$Hd9LW+gfngc#5 zq~^LS4D#>qZ)s)OC1ypNe33QUl}h7>W-29Tkp1uh&zlRHy>s zndks?#e6=mP$*F0@8R}@YvJ&x1`ZDoVWi<2PLqUv@?&ZMrZ8M2l}cqgofbWR3HbvL W)b{$S*}0Ga0000!lvI6-E$sR$z z3=CCj3=9n|3=F@3LJcn%7)lKo7+xhXFj&oCU=S~uvn$XBD8X6a5n0T@z%2;EjP)t; z6M=&4C7!;n?9W*_1tqogm0r9A3Na;lySp&_Z|^^|AIMWJag8WRNi0dVN-jzTQVd20 zM#j1Zrn&}}A%^BwMy6IKM%o4jRt5&Me;!(gq9HdwB{QuOw}w|ss)T^n*?GD+hIn{y zowmD6%Tb{1xZr#900YAy0pG8@JTAru4|se~WC>>Vt!3q9IXKqrY|P zt%`D1QoWOoNbt3<4eJ)+OZ{K`>+e3bj~*(U?!Q0TGi%vyft@jZi@YWsO)A`dcdA!w zj+L{&n(*qYT{|}ERNKgL@U%)O zCUa=#ZjXNAk<2sw^waOZKQg?`FSMFl@QizH!>P#i*NwJ0eSUZRvEb}t3mK34)6>s+ zRNBa8M<2^DNm}-^rf&D$j2G1pYWBuG?9t|38K}<@cjWcgBFO}2k6&!_&%0k*Z5%&g zdaes&;@cfOCTEv1MlUZ6`}5PRPUL=$nRD)f8CRC`6kU|DlIb}td0aEBa%+@kbHTB% zi+_AsV7IdJk=N-LTx(5sF-?2%-(=UXibqpUr*3-5`S)i4FALM|yM1S>_8Gk`lRiKB z&;j;1%O&$ZNV0e=zbw)u*nRXuYD#iPdT+aD(v{bxrPmogUU*nAL&ft{iczOalL+g) zJq-W<9K9G?b2ZCUg2zmX_fq`Nt@k}We=$4Cr~j{-b1@p2^cXx{{an^LB{Ts5a?f4W literal 0 HcmV?d00001 diff --git a/UpButton.png b/UpButton.png new file mode 100644 index 0000000000000000000000000000000000000000..996ae9941e70a5537d1a057e8a4bf6ccf78e9bff GIT binary patch literal 1057 zcmex= z&EU+y#K;IjP{7Q}3<7K{EX=IzZ0zhH%)!ac$-%+J!OqUb%f-db0|e}xeEhsTd>}T+ z5Ri6|E+FFJVCMj-APxLKz#z!MAjcrb%&5e`B*@4t$oT&VgFMi!tUw=uJOu@eOw25- zY(OV*aRU`>6#zP)nVAXbSXLGmpz2znJOhg$tB|6hBb#twBD+$dh*9Ijg&fLG8xM*G zUHqV8oK)1r$t5N(At|M*rmmr>WnyY(ZeeNV?BeR??&0Yb91<+v*#~fzWVs-^OvvRzW@073*;|G24;x2;66k1mmttz zOu#r`VF&q(k*OSrnFU!`6%E;h90S=C3x$=88aYIqCNA7~kW<+>=!0ld(M2vX6_bam zA3g>mD)gPX3 z-6FA1y<*X^kNn+_x9=BlTyXn8g9x`m7=MN1x%0bbNcZ`%udF|q{GTE7KSTd7-uKP> z*y_&SABT^Ie|*2^qv&a!*6m^{YZx}a=~kESOgeYw z2=lk@Z*G6r?P2|0_=oLco$?=xYY(s6n6EuPHSyE=R0HNS+vnLlvz#!;XnqoB5a*X& zf4crI+n>zex&MRn{99qazqS0GR%5&3$L= _pictureWidth || y + _airfighterHeight >= _pictureHeight) { - _startPosX = 0; - _startPosY = 70; - } - } - - public void MoveTransport(DirectionType direction){ - if (EntityAirFighter == null) - return; - AirFighterPanel.paint(AirFighterPanel.getGraphics()); - switch (direction) - { - case Left: - if (_startPosX - EntityAirFighter.Step() >= 0) - _startPosX -= (int) EntityAirFighter.Step(); - - break; - case Up: - if (_startPosY - EntityAirFighter.Step() - _airfighterHeight > 0) - _startPosY -= (int) EntityAirFighter.Step(); - - break; - case Right: - if (_startPosX + EntityAirFighter.Step() + _airfighterWidth < _pictureWidth) - _startPosX += (int) EntityAirFighter.Step(); - else - _startPosX = _pictureWidth - _airfighterWidth; - - break; - case Down: - if (_startPosY + EntityAirFighter.Step() + _airfighterwingkorpusHeight < _pictureHeight) - _startPosY += (int) EntityAirFighter.Step(); - break; - } - DrawningEngines.CurX = _startPosX; - DrawningEngines.CurY = _startPosY; - } - - public void DrawAirFighter(){ - Graphics2D g2d = (Graphics2D) AirFighterPanel.getGraphics(); - if (EntityAirFighter == null) - return; - DrawningEngines.DrawEngines(); -//тело самолёта - g2d.setColor(EntityAirFighter.BodyColor()); - g2d.fillRect(_startPosX + 20,_startPosY +4,140,20); - g2d.setColor(Color.BLACK); - g2d.drawRect(_startPosX + 20,_startPosY +4,140,20); -//Нос самолёта - int[] xPointsArrNose = {_startPosX + 20,_startPosX + 20,_startPosX-3}; - int[] yPointsArrNose = {_startPosY + 4,_startPosY + 24,_startPosY + 12}; - g2d.setColor(Color.BLACK); - g2d.fillPolygon(xPointsArrNose, yPointsArrNose, xPointsArrNose.length); - g2d.setColor(Color.BLACK); - g2d.drawPolygon(xPointsArrNose, yPointsArrNose, xPointsArrNose.length); - -// Правое крыло - int[] xPointsArrRightWing = {_startPosX + 80,_startPosX+80,_startPosX+85,_startPosX + 100}; - int[] yPointsArrRightWing = { _startPosY + 4,_startPosY - 66,_startPosY - 66, _startPosY + 4 }; - g2d.setColor(EntityAirFighter.BodyColor()); - g2d.fillPolygon(xPointsArrRightWing, yPointsArrRightWing, xPointsArrRightWing.length); - g2d.setColor(Color.BLACK); - g2d.drawPolygon(xPointsArrRightWing, yPointsArrRightWing, xPointsArrRightWing.length); - -// Левое крыло - int[] xPointsArrLeftWing = {_startPosX + 80,_startPosX + 100,_startPosX+85,_startPosX+80}; - int[] yPointsArrLeftWing = {_startPosY + 24,_startPosY + 24,_startPosY + 94,_startPosY + 94}; - g2d.setColor(EntityAirFighter.BodyColor()); - g2d.fillPolygon(xPointsArrLeftWing, yPointsArrLeftWing, xPointsArrLeftWing.length); - g2d.setColor(Color.BLACK); - g2d.drawPolygon(xPointsArrLeftWing, yPointsArrLeftWing, xPointsArrLeftWing.length); - -// Правое задние крыло - int[] xPointsArrRightBackWing={_startPosX + 140,_startPosX + 160,_startPosX+160,_startPosX+140}; - int[] yPointsArrRightBackWing={ _startPosY + 4,_startPosY + 4,_startPosY - 22,_startPosY -4}; - g2d.setColor(EntityAirFighter.BodyColor()); - g2d.fillPolygon(xPointsArrRightBackWing, yPointsArrRightBackWing, xPointsArrRightBackWing.length); - g2d.setColor(Color.BLACK); - g2d.drawPolygon(xPointsArrRightBackWing, yPointsArrRightBackWing, xPointsArrRightBackWing.length); -// Заднее левое крыло - int[] xPointsArrLeftBackWing= {_startPosX + 140,_startPosX + 160,_startPosX+160,_startPosX+140}; - int[] yPointsArrLeftBackWing= {_startPosY + 24,_startPosY + 24,_startPosY + 50,_startPosY + 32}; - g2d.setColor(EntityAirFighter.BodyColor()); - g2d.fillPolygon(xPointsArrLeftBackWing, yPointsArrLeftBackWing, xPointsArrLeftBackWing.length); - g2d.setColor(Color.BLACK); - g2d.drawPolygon(xPointsArrLeftBackWing, yPointsArrLeftBackWing, xPointsArrLeftBackWing.length); - //Ракеты - if (EntityAirFighter.Racket()) - { - g2d.setColor(Color.GRAY); - g2d.fillRect(_startPosX + 70, _startPosY - 15, 10, 10); - g2d.setColor(Color.BLACK); - g2d.drawRect(_startPosX + 70, _startPosY - 15, 10, 10); - int[] xPointsArrNoseRacket = {_startPosX + 70,_startPosX + 70,_startPosX + 60}; - int[] yPointsArrNoseRacket = {_startPosY -5,_startPosY - 15,_startPosY -10}; - - g2d.setColor(Color.RED); - g2d.fillPolygon(xPointsArrNoseRacket, yPointsArrNoseRacket, xPointsArrNoseRacket.length); - g2d.setColor(Color.BLACK); - g2d.drawPolygon(xPointsArrNoseRacket, yPointsArrNoseRacket, xPointsArrNoseRacket.length); - g2d.setColor(Color.GRAY); - g2d.fillRect(_startPosX + 70, _startPosY - 40, 10, 10); - g2d.setColor(Color.BLACK); - g2d.drawRect(_startPosX + 70, _startPosY - 40, 10, 10); - int[] xPoints2ArrNoseRacket = {_startPosX + 70,_startPosX + 70,_startPosX + 60}; - int[] yPoints2ArrNoseRacket = {_startPosY -30,_startPosY - 40,_startPosY -35}; - g2d.setColor(Color.RED); - g2d.fillPolygon(xPoints2ArrNoseRacket, yPoints2ArrNoseRacket, xPoints2ArrNoseRacket.length); - g2d.setColor(Color.BLACK); - g2d.drawPolygon(xPoints2ArrNoseRacket, yPoints2ArrNoseRacket, xPoints2ArrNoseRacket.length); - - g2d.setColor(Color.GRAY); - g2d.fillRect(_startPosX + 70, _startPosY + 59, 10, 10); - g2d.setColor(Color.BLACK); - g2d.drawRect(_startPosX + 70, _startPosY + 59, 10, 10); - int[] xPoints3ArrNoseRacket ={_startPosX + 70,_startPosX + 70,_startPosX + 60}; - int[] yPoints3ArrNoseRacket ={_startPosY +59,_startPosY + 69,_startPosY + 64}; - g2d.setColor(Color.RED); - g2d.fillPolygon(xPoints3ArrNoseRacket, yPoints3ArrNoseRacket, xPoints3ArrNoseRacket.length); - g2d.setColor(Color.BLACK); - g2d.drawPolygon(xPoints3ArrNoseRacket, yPoints3ArrNoseRacket, xPoints3ArrNoseRacket.length); - - g2d.setColor(Color.GRAY); - g2d.fillRect(_startPosX + 70, _startPosY + 34, 10, 10); - g2d.setColor(Color.BLACK); - g2d.drawRect(_startPosX + 70, _startPosY + 34, 10, 10); - int[] xPoints4ArrNoseRacket={_startPosX + 70,_startPosX + 70,_startPosX + 60}; - int[] yPoints4ArrNoseRacket={_startPosY +34,_startPosY + 44,_startPosY + 39}; - g2d.setColor(Color.RED); - g2d.fillPolygon(xPoints4ArrNoseRacket, yPoints4ArrNoseRacket, xPoints4ArrNoseRacket.length); - g2d.setColor(Color.BLACK); - g2d.drawPolygon(xPoints4ArrNoseRacket, yPoints4ArrNoseRacket, xPoints4ArrNoseRacket.length); - - } - - } - - -} diff --git a/src/AirFighterHard/EntityAirFighter.java b/src/AirFighterHard/EntityAirFighter.java deleted file mode 100644 index 8743420..0000000 --- a/src/AirFighterHard/EntityAirFighter.java +++ /dev/null @@ -1,38 +0,0 @@ -package AirFighterHard; -import java.awt.*; - -public class EntityAirFighter { - private int Speed, EngineNumb; - private double Weight, Step; - private Color BodyColor; - private boolean Wing; - private boolean Racket; - - public int Speed(){ - return Speed; - } - public int EngineNumb(){ - return EngineNumb; - } - public double Weight(){ - return Weight; - } - public double Step(){ - return Step; - } - public Color BodyColor(){ - return BodyColor; - } - public boolean Racket(){return Racket;} - public boolean Wing(){return Wing;} - public void Init(int speed, double weight, Color bodyColor, int engineNumb, - boolean racket, boolean wing){ - Speed = speed; - Weight = weight; - Step = (double)Speed * 100 / Weight; - BodyColor = bodyColor; - EngineNumb = engineNumb; - Racket = racket; - Wing = wing; - } -} diff --git a/src/AirFighterHard/Main.java b/src/AirFighterHard/Main.java deleted file mode 100644 index d60ae2e..0000000 --- a/src/AirFighterHard/Main.java +++ /dev/null @@ -1,96 +0,0 @@ -package AirFighterHard; -import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.image.BufferedImage; -import java.io.File; -import java.io.IOException; -import java.util.Random; -import javax.imageio.ImageIO; -import javax.swing.*; - -public class Main { - public static void main(String[] args) throws IOException { - JFrame AirFighterFrame = new JFrame(); - JPanel AirFighterPanel = new JPanel(); - AirFighterFrame.setLayout(new BorderLayout()); - AirFighterFrame.setSize(900, 500); - AirFighterFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - AirFighterFrame.setLayout(new BorderLayout(1,1)); - DrawningAirFighter DrawningAirFighter = new DrawningAirFighter(); - AirFighterPanel.setLayout(null); - - BufferedImage RightIcon = ImageIO.read(new File("RightButton.png")); - BufferedImage LeftIcon = ImageIO.read(new File("LeftButton.png")); - BufferedImage UpIcon = ImageIO.read(new File("UpButton.png")); - BufferedImage DownIcon = ImageIO.read(new File("DownButton.png")); - - JButton RightButton = new JButton(new ImageIcon(RightIcon)); - JButton LeftButton = new JButton(new ImageIcon(LeftIcon)); - JButton UpButton = new JButton(new ImageIcon(UpIcon)); - JButton DownButton = new JButton(new ImageIcon(DownIcon)); - - JButton CreateButton = new JButton(); - CreateButton.setText("Создать"); - CreateButton.setBounds(12, 401, 90, 40); - RightButton.setBounds(840,411,30,30); - LeftButton.setBounds(768,411,30,30); - UpButton.setBounds(804,375,30,30); - DownButton.setBounds(804,411,30,30); - AirFighterPanel.add(CreateButton); - AirFighterPanel.add(RightButton); - AirFighterPanel.add(LeftButton); - AirFighterPanel.add(UpButton); - AirFighterPanel.add(DownButton); - AirFighterFrame.add(AirFighterPanel, BorderLayout.CENTER); - Random random = new Random(); - CreateButton.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - DrawningAirFighter.Init(random.nextInt(100, 300), random.nextDouble(1000, 3000), - Color.getHSBColor(random.nextInt(0, 301), random.nextInt(0, 301), random.nextInt(0, 301)), - random.nextInt(1, 4), - AirFighterPanel.getWidth(), AirFighterPanel.getHeight(), random.nextBoolean(), random.nextBoolean(), AirFighterPanel); - DrawningAirFighter.DrawAirFighter(); - } - }); - RightButton.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - if(DrawningAirFighter.EntityAirFighter() == null) - return; - DrawningAirFighter.MoveTransport(DirectionType.Right); - DrawningAirFighter.DrawAirFighter(); - } - }); - LeftButton.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - if(DrawningAirFighter.EntityAirFighter() == null) - return; - DrawningAirFighter.MoveTransport(DirectionType.Left); - DrawningAirFighter.DrawAirFighter(); - } - }); - UpButton.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - if(DrawningAirFighter.EntityAirFighter() == null) - return; - DrawningAirFighter.MoveTransport(DirectionType.Up); - DrawningAirFighter.DrawAirFighter(); - } - }); - DownButton.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - if(DrawningAirFighter.EntityAirFighter() == null) - return; - DrawningAirFighter.MoveTransport(DirectionType.Down); - DrawningAirFighter.DrawAirFighter(); - } - }); - - AirFighterFrame.setVisible(true); - } -} diff --git a/src/AirFighterHard/DirectionType.java b/src/DirectionType.java similarity index 73% rename from src/AirFighterHard/DirectionType.java rename to src/DirectionType.java index 136b40a..6f8ee58 100644 --- a/src/AirFighterHard/DirectionType.java +++ b/src/DirectionType.java @@ -1,5 +1,4 @@ -package AirFighterHard; - +package src; public enum DirectionType { Up, Down, diff --git a/src/DrawningObjects/DrawningAirFighter.java b/src/DrawningObjects/DrawningAirFighter.java new file mode 100644 index 0000000..0908cea --- /dev/null +++ b/src/DrawningObjects/DrawningAirFighter.java @@ -0,0 +1,69 @@ +package src.DrawningObjects; +import src.Entities.EntityAirplane; +import src.Entities.EntityAirFighter; + +import java.awt.*; + +public class DrawningAirFighter extends DrawningAirplane { + public DrawningAirFighter(int speed, double weight, Color bodyColor, Color additionalColor, + boolean dopwings, boolean rackets, int width, int height ){ + super(speed,weight,bodyColor,width,height); + if(EntityAirplane!=null){ + EntityAirplane = new EntityAirFighter(speed, weight, bodyColor, additionalColor, dopwings,rackets); + } + } + @Override + public void DrawAirplane(Graphics2D g2d) { + if (!(EntityAirplane instanceof EntityAirFighter)) { + return; + } + super.DrawAirplane(g2d); + EntityAirFighter _airplaneAirFighter = (EntityAirFighter) EntityAirplane; + if (EntityAirFighter.Racket()) { + g2d.setColor(Color.GRAY); + g2d.fillRect(_startPosX + 70, _startPosY - 15, 10, 10); + g2d.setColor(Color.BLACK); + g2d.drawRect(_startPosX + 70, _startPosY - 15, 10, 10); + int[] xPointsArrNoseRacket = {_startPosX + 70, _startPosX + 70, _startPosX + 60}; + int[] yPointsArrNoseRacket = {_startPosY - 5, _startPosY - 15, _startPosY - 10}; + + g2d.setColor(Color.RED); + g2d.fillPolygon(xPointsArrNoseRacket, yPointsArrNoseRacket, xPointsArrNoseRacket.length); + g2d.setColor(Color.BLACK); + g2d.drawPolygon(xPointsArrNoseRacket, yPointsArrNoseRacket, xPointsArrNoseRacket.length); + g2d.setColor(Color.GRAY); + g2d.fillRect(_startPosX + 70, _startPosY - 40, 10, 10); + g2d.setColor(Color.BLACK); + g2d.drawRect(_startPosX + 70, _startPosY - 40, 10, 10); + int[] xPoints2ArrNoseRacket = {_startPosX + 70, _startPosX + 70, _startPosX + 60}; + int[] yPoints2ArrNoseRacket = {_startPosY - 30, _startPosY - 40, _startPosY - 35}; + g2d.setColor(Color.RED); + g2d.fillPolygon(xPoints2ArrNoseRacket, yPoints2ArrNoseRacket, xPoints2ArrNoseRacket.length); + g2d.setColor(Color.BLACK); + g2d.drawPolygon(xPoints2ArrNoseRacket, yPoints2ArrNoseRacket, xPoints2ArrNoseRacket.length); + + g2d.setColor(Color.GRAY); + g2d.fillRect(_startPosX + 70, _startPosY + 59, 10, 10); + g2d.setColor(Color.BLACK); + g2d.drawRect(_startPosX + 70, _startPosY + 59, 10, 10); + int[] xPoints3ArrNoseRacket = {_startPosX + 70, _startPosX + 70, _startPosX + 60}; + int[] yPoints3ArrNoseRacket = {_startPosY + 59, _startPosY + 69, _startPosY + 64}; + g2d.setColor(Color.RED); + g2d.fillPolygon(xPoints3ArrNoseRacket, yPoints3ArrNoseRacket, xPoints3ArrNoseRacket.length); + g2d.setColor(Color.BLACK); + g2d.drawPolygon(xPoints3ArrNoseRacket, yPoints3ArrNoseRacket, xPoints3ArrNoseRacket.length); + + g2d.setColor(Color.GRAY); + g2d.fillRect(_startPosX + 70, _startPosY + 34, 10, 10); + g2d.setColor(Color.BLACK); + g2d.drawRect(_startPosX + 70, _startPosY + 34, 10, 10); + int[] xPoints4ArrNoseRacket = {_startPosX + 70, _startPosX + 70, _startPosX + 60}; + int[] yPoints4ArrNoseRacket = {_startPosY + 34, _startPosY + 44, _startPosY + 39}; + g2d.setColor(Color.RED); + g2d.fillPolygon(xPoints4ArrNoseRacket, yPoints4ArrNoseRacket, xPoints4ArrNoseRacket.length); + g2d.setColor(Color.BLACK); + g2d.drawPolygon(xPoints4ArrNoseRacket, yPoints4ArrNoseRacket, xPoints4ArrNoseRacket.length); + + } + } +} diff --git a/src/DrawningObjects/DrawningAirplane.java b/src/DrawningObjects/DrawningAirplane.java new file mode 100644 index 0000000..0d726ea --- /dev/null +++ b/src/DrawningObjects/DrawningAirplane.java @@ -0,0 +1,161 @@ +package src.DrawningObjects; + +import java.awt.*; +import java.util.Random; +import src.DirectionType; +import src.Entities.EntityAirplane; +public class DrawningAirplane { + + protected EntityAirplane EntityAirplane; + private int _pictureWidth; + private int _pictureHeight; + private int _startPosX = 0; + private int _startPosY = 0; + private int _airplaneWidth = 160; + private int _airplaneHeight = 68; + private int _airplanekorpusHeight = 90; + protected IDraw DrawningEngines; + + public EntityAirplane EntityAirplane(){ + return EntityAirplane; + } + public DrawningAirplane(int speed, double weight, Color bodyColor, int width, int height){ + if(width <= _airplaneWidth || height <= _airplaneHeight) + return; + _startPosY=70; + _startPosX = 0; + + _pictureWidth = width; + _pictureHeight = height; + EntityAirplane = new EntityAirplane(speed, weight, bodyColor); + + DrawningEngines = new DrawningEngines (_startPosX,_startPosY); + Random rand = new Random(); + int variant = rand.nextInt(0,3); + } + + public void SetPosition(int x, int y){ + if(EntityAirFighter == null) + return; + _startPosX = x; + _startPosY = y; + if (x + _airplaneWidth >= _pictureWidth || y + _airplaneHeight >= _pictureHeight) { + _startPosX = 0; + _startPosY = 70; + } + } + public int GetPosX(){return _startPosX;} + public int GetPosY(){return _startPosY;} + public int GetWidth(){return _airplaneWidth;} + public int GetHeight(){return _airplaneHeight;} + public boolean CanMove(DirectionType direction) + { + if (EntityAirplane == null) + return false; + boolean can = false; + switch (direction) + { + case Left: + can = _startPosX - EntityAirplane.Step() >= 0; + break; + case Right: + can = _startPosX + EntityAirplane.Step() + _airplaneWidth< _pictureWidth; + break; + case Down: + can = _startPosY + EntityAirFighter.Step() + _airplanekorpusHeight < _pictureHeight; + break; + case Up: + can = _startPosY - EntityAirplane.Step() >= 0; + break; + }; + return can; + } + + public void MoveTransport(DirectionType direction){ + if (!CanMove(direction) || EntityAirplane == null) + return; + switch (direction) + { + case Left: + if (_startPosX - EntityAirplane.Step() >= 0) + _startPosX -= (int)EntityAirplane.Step(); + else + _startPosX = 0; + break; + case Up: + if (_startPosY - EntityAirplane.Step() >= 0) + _startPosY -= (int)EntityAirplane.Step(); + else + _startPosY = 0; + break; + case Right: + if (_startPosX + EntityAirplane.Step() + _airplaneWidth < _pictureWidth) + _startPosX += (int)EntityAirplane.Step(); + else + _startPosX = _pictureWidth - _airplaneWidth; + break; + case Down: + if (_startPosY + EntityAirplane.Step() + _airplaneHeight < _pictureHeight) + _startPosY += (int)EntityAirplane.Step(); + else + _startPosY = _pictureHeight - _airplaneHeight; + break; + } + DrawningEngines.ChangeX(_startPosX); + DrawningEngines.ChangeY(_startPosY); + } + public void DrawAirplane(Graphics2D g2d){ + + if (EntityAirFighter == null) + return; + DrawningEngines.DrawEngines(); +//тело самолёта + g2d.setColor(EntityAirFighter.BodyColor()); + g2d.fillRect(_startPosX + 20,_startPosY +4,140,20); + g2d.setColor(Color.BLACK); + g2d.drawRect(_startPosX + 20,_startPosY +4,140,20); +//Нос самолёта + int[] xPointsArrNose = {_startPosX + 20,_startPosX + 20,_startPosX-3}; + int[] yPointsArrNose = {_startPosY + 4,_startPosY + 24,_startPosY + 12}; + g2d.setColor(Color.BLACK); + g2d.fillPolygon(xPointsArrNose, yPointsArrNose, xPointsArrNose.length); + g2d.setColor(Color.BLACK); + g2d.drawPolygon(xPointsArrNose, yPointsArrNose, xPointsArrNose.length); + +// Правое крыло + int[] xPointsArrRightWing = {_startPosX + 80,_startPosX+80,_startPosX+85,_startPosX + 100}; + int[] yPointsArrRightWing = { _startPosY + 4,_startPosY - 66,_startPosY - 66, _startPosY + 4 }; + g2d.setColor(EntityAirFighter.BodyColor()); + g2d.fillPolygon(xPointsArrRightWing, yPointsArrRightWing, xPointsArrRightWing.length); + g2d.setColor(Color.BLACK); + g2d.drawPolygon(xPointsArrRightWing, yPointsArrRightWing, xPointsArrRightWing.length); + +// Левое крыло + int[] xPointsArrLeftWing = {_startPosX + 80,_startPosX + 100,_startPosX+85,_startPosX+80}; + int[] yPointsArrLeftWing = {_startPosY + 24,_startPosY + 24,_startPosY + 94,_startPosY + 94}; + g2d.setColor(EntityAirFighter.BodyColor()); + g2d.fillPolygon(xPointsArrLeftWing, yPointsArrLeftWing, xPointsArrLeftWing.length); + g2d.setColor(Color.BLACK); + g2d.drawPolygon(xPointsArrLeftWing, yPointsArrLeftWing, xPointsArrLeftWing.length); + +// Правое задние крыло + int[] xPointsArrRightBackWing={_startPosX + 140,_startPosX + 160,_startPosX+160,_startPosX+140}; + int[] yPointsArrRightBackWing={ _startPosY + 4,_startPosY + 4,_startPosY - 22,_startPosY -4}; + g2d.setColor(EntityAirFighter.BodyColor()); + g2d.fillPolygon(xPointsArrRightBackWing, yPointsArrRightBackWing, xPointsArrRightBackWing.length); + g2d.setColor(Color.BLACK); + g2d.drawPolygon(xPointsArrRightBackWing, yPointsArrRightBackWing, xPointsArrRightBackWing.length); +// Заднее левое крыло + int[] xPointsArrLeftBackWing= {_startPosX + 140,_startPosX + 160,_startPosX+160,_startPosX+140}; + int[] yPointsArrLeftBackWing= {_startPosY + 24,_startPosY + 24,_startPosY + 50,_startPosY + 32}; + g2d.setColor(EntityAirFighter.BodyColor()); + g2d.fillPolygon(xPointsArrLeftBackWing, yPointsArrLeftBackWing, xPointsArrLeftBackWing.length); + g2d.setColor(Color.BLACK); + g2d.drawPolygon(xPointsArrLeftBackWing, yPointsArrLeftBackWing, xPointsArrLeftBackWing.length); + + + + } + + +} diff --git a/src/AirFighterHard/DrawningEngines.java b/src/DrawningObjects/DrawningEngines.java similarity index 81% rename from src/AirFighterHard/DrawningEngines.java rename to src/DrawningObjects/DrawningEngines.java index 5e9adcf..8bc0121 100644 --- a/src/AirFighterHard/DrawningEngines.java +++ b/src/DrawningObjects/DrawningEngines.java @@ -1,21 +1,24 @@ -package AirFighterHard; - +package src.DrawningObjects; import javax.swing.*; import java.awt.*; +import src.NumberType; + +public class DrawningEngines implements IDraw { -public class DrawningEngines { - JPanel AirFighterPanel; private NumberType EnginesNumb; private Color EngineColor; public int CurX, CurY; - boolean Init( int curX, int curY, JPanel airfighterPanel){ + boolean DrawningEngines( int curX, int curY){ CurX = curX; CurY = curY; EngineColor = Color.BLACK; - AirFighterPanel = airfighterPanel; - - return true; + } + public void ChangeX(int x){ + CurX = x; + } + public void ChangeY(int y){ + CurY = y; } public void ChangeEnginesNumb(int x){ if(x <= 1) diff --git a/src/DrawningObjects/IDraw.java b/src/DrawningObjects/IDraw.java new file mode 100644 index 0000000..2d0c05e --- /dev/null +++ b/src/DrawningObjects/IDraw.java @@ -0,0 +1,10 @@ +package src.DrawningObjects; +import src.NumberType; +import java.awt.*; +public interface IDraw { + public void ChangeEngineNumb(int x); + //public NumberType EngineNumb(); + public void DrawEngines(Graphics2D g2d); + public void ChangeX(int x); + public void ChangeY(int y); +} diff --git a/src/Entities/EntityAirFighter.java b/src/Entities/EntityAirFighter.java new file mode 100644 index 0000000..b6de805 --- /dev/null +++ b/src/Entities/EntityAirFighter.java @@ -0,0 +1,22 @@ +package src.Entities; +import java.awt.*; + +public class EntityAirFighter extends EntityAirplane { + private Color BodyColor; + private boolean Wing; + private boolean Racket; + public Color BodyColor(){ + return BodyColor; + } + public boolean Racket(){return Racket;} + public boolean DopWing(){return Wing;} + public void Init(int speed, double weight, Color bodyColor, + boolean racket, boolean dopwing){ + super(speed, weight, bodyColor); + + BodyColor = bodyColor; + + Racket = racket; + Wing = wing; + } +} diff --git a/src/Entities/EntityAirplane.java b/src/Entities/EntityAirplane.java new file mode 100644 index 0000000..599af01 --- /dev/null +++ b/src/Entities/EntityAirplane.java @@ -0,0 +1,26 @@ +package src.Entities; +import java.awt.*; + +public class EntityAirplane { + private int Speed; + private double Weight, Step; + private Color BodyColor; + public int Speed(){ + return Speed; + } + public double Weight(){ + return Weight; + } + public double Step(){ + return Step; + } + public Color BodyColor(){ + return BodyColor; + } + public EntityAirplane(int speed, double weight, Color bodyColor){ + Speed = speed; + Weight = weight; + Step = (double)Speed * 100 / Weight; + BodyColor = bodyColor; + } +} \ No newline at end of file diff --git a/src/FormAirFighter.java b/src/FormAirFighter.java new file mode 100644 index 0000000..ac2b095 --- /dev/null +++ b/src/FormAirFighter.java @@ -0,0 +1,193 @@ +package src; + +import src.DrawningObjects.DrawningAirplane; + +import src.MovementStrategy.*; +import src.DrawningObjects.DrawningAirFighter; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.Random; + +public class FormAirFighter { + private DrawningAirplane DrawningAirplane; + private AbstractStrategy _abstractStrategy; + Canvas canv; + static int pictureBoxWidth = 882; + static int pictureBoxHeight = 453; + + public void Draw(){ + canv.repaint(); + } + + public FormAirFighter(){ + JFrame MonorailFrame =new JFrame (); + JButton buttonCreate = new JButton("Создать"); + JButton buttonCreateLocomotive = new JButton("Создать самолет с радаром"); + JButton buttonStep = new JButton("Шаг"); + JComboBox comboBoxStrategy = new JComboBox( + new String[]{ + "Довести до центра", + "Довести до края", + }); + JButton UpButton = new JButton(); + UpButton.setIcon(new ImageIcon("UpButton.jpg")); + JButton DownButton = new JButton(); + DownButton.setIcon(new ImageIcon("DownButton.jpg")); + JButton LeftButton = new JButton(); + LeftButton.setIcon(new ImageIcon("LeftButton.jpg")); + JButton RightButton = new JButton(); + RightButton.setIcon(new ImageIcon("RightButton.jpg")); + buttonStep.addActionListener( + new ActionListener() { + public void actionPerformed(ActionEvent e){ + if (DrawningAirplane == null) + { + return; + } + if (comboBoxStrategy.isEnabled()) + { + switch (comboBoxStrategy.getSelectedIndex()) + { + case 0: + _abstractStrategy = new MoveToCenter(); + break; + case 1: + _abstractStrategy = new MoveToBorder(); + break; + default: + _abstractStrategy = null; + break; + }; + if (_abstractStrategy == null) + { + return; + } + _abstractStrategy.SetData(new + DrawningObjectAirplane(DrawningAirplane), pictureBoxWidth, + pictureBoxHeight); + comboBoxStrategy.setEnabled(false); + } + if (_abstractStrategy == null) + { + return; + } + _abstractStrategy.MakeStep(); + Draw(); + if (_abstractStrategy.GetStatus() == Status.Finish) + { + comboBoxStrategy.setEnabled(true); + _abstractStrategy = null; + } + } + } + ); + buttonCreate.addActionListener( + new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + Random random = new Random(); + DrawningAirplane = new DrawningAirplane(random.nextInt(100, 300), random.nextDouble(1000, 3000), + Color.getHSBColor(random.nextInt(0, 301), random.nextInt(0, 301), random.nextInt(0, 301)), + pictureBoxWidth, pictureBoxHeight); + canv.DrawningAirplane = DrawningAirplane; + comboBoxStrategy.enable(true); + Draw(); + } + } + ); + buttonCreateLocomotive.addActionListener( + new ActionListener() { + public void actionPerformed(ActionEvent e){ + Random random = new Random(); + DrawningAirplane = new DrawningAirFighter(random.nextInt(100, 300), random.nextDouble(1000, 3000), + Color.getHSBColor(random.nextInt(0, 301), random.nextInt(0, 301), random.nextInt(0, 301)), + Color.getHSBColor(random.nextInt(0, 301), random.nextInt(0, 301), random.nextInt(0, 301)), + random.nextBoolean(), random.nextBoolean(), + pictureBoxWidth, pictureBoxHeight); + canv.DrawningAirplane = DrawningAirplane; + comboBoxStrategy.enable(true); + Draw(); + } + } + ); + RightButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + if(DrawningAirplane.EntityAirplane() == null) { + return; + } + DrawningAirplane.MoveTransport(DirectionType.Right); + Draw(); + } + }); + LeftButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + if(DrawningAirplane.EntityAirplane() == null) + return; + DrawningAirplane.MoveTransport(DirectionType.Left); + Draw(); + } + }); + UpButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + if(DrawningAirplane.EntityAirplane() == null) + return; + DrawningAirplane.MoveTransport(DirectionType.Up); + Draw(); + } + }); + DownButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + if(DrawningAirplane.EntityAirplane() == null) + return; + DrawningAirplane.MoveTransport(DirectionType.Down); + Draw(); + } + }); + + MonorailFrame.setSize (900, 500); + MonorailFrame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); + MonorailFrame.setLayout(null); + canv = new Canvas(); + canv.setSize(pictureBoxWidth, pictureBoxHeight); + buttonCreate.setBounds(198, 401, 180, 40); + buttonCreateLocomotive.setBounds(12, 401, 180, 40); + RightButton.setBounds(840,411,30,30); + LeftButton.setBounds(768,411,30,30); + UpButton.setBounds(804,375,30,30); + DownButton.setBounds(804,411,30,30); + comboBoxStrategy.setBounds(719,12,151,28); + buttonStep.setBounds(768, 46, 94, 29); + MonorailFrame.add(canv); + MonorailFrame.add(buttonCreate); + MonorailFrame.add(buttonCreateLocomotive); + MonorailFrame.add(UpButton); + MonorailFrame.add(DownButton); + MonorailFrame.add(LeftButton); + MonorailFrame.add(RightButton); + MonorailFrame.add(comboBoxStrategy); + MonorailFrame.add(buttonStep); + MonorailFrame.setVisible(true); + } +} +class Canvas extends JComponent{ + public DrawningAirplane DrawningAirplane; + public Canvas(){ + } + public void paintComponent (Graphics g){ + if (DrawningAirplane == null){ + return; + } + super.paintComponents (g) ; + Graphics2D g2d = (Graphics2D)g; + DrawningAirplane.DrawAirplane(g2d); + super.repaint(); + } +} + diff --git a/src/Main.java b/src/Main.java new file mode 100644 index 0000000..7928ef2 --- /dev/null +++ b/src/Main.java @@ -0,0 +1,19 @@ +package src; +import src.DrawningObjects.DrawningAirplaneWithRadar; +import src.DrawningObjects.DrawningAirplane; +import src.MovementStrategy.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; +import java.util.Random; +import javax.imageio.ImageIO; +import javax.swing.*; + +public class Main { + public static void main(String[] args) throws IOException { + FormAirFighter form = new FormAirFighter(); + } +} \ No newline at end of file diff --git a/src/MovementStrategy/AbstractStrategy.java b/src/MovementStrategy/AbstractStrategy.java new file mode 100644 index 0000000..9634f7a --- /dev/null +++ b/src/MovementStrategy/AbstractStrategy.java @@ -0,0 +1,69 @@ +package MovementStrategy; +import src.DirectionType; + +public abstract class AbstractStrategy { + private IMoveableObject _moveableObject; + private Status _state = Status.NotInit; + private int FieldWidth; + protected int FieldWidth(){return FieldWidth;} + private int FieldHeight; + protected int FieldHeight(){return FieldHeight;} + public Status GetStatus() { return _state; } + public void SetData(IMoveableObject moveableObject, int width, int + height) + { + if (moveableObject == null) + { + _state = Status.NotInit; + return; + } + _state = Status.InProgress; + _moveableObject = moveableObject; + FieldWidth = width; + FieldHeight = height; + } + public void MakeStep() + { + if (_state != Status.InProgress) + { + return; + } + if (IsTargetDestination()) + { + _state = Status.Finish; + return; + } + MoveToTarget(); + } + protected boolean MoveLeft() {return MoveTo(DirectionType.Left);} + protected boolean MoveRight() {return MoveTo(DirectionType.Right);} + protected boolean MoveUp() {return MoveTo(DirectionType.Up);} + protected boolean MoveDown() {return MoveTo(DirectionType.Down);} + protected ObjectParameters GetObjectParameters(){ + if(_moveableObject != null) + return _moveableObject.GetObjectParameters(); + else return null; + } + protected Integer GetStep() + { + if (_state != Status.InProgress) + { + return null; + } + return _moveableObject.GetStep(); + } + protected abstract void MoveToTarget(); + protected abstract boolean IsTargetDestination(); + private boolean MoveTo(DirectionType directionType) { + if (_state != Status.InProgress) + { + return false; + } + if (_moveableObject.CheckCanMove(directionType)) + { + _moveableObject.MoveObject(directionType); + return true; + } + return false; + } +} diff --git a/src/MovementStrategy/DrawningObjectAirplane.java b/src/MovementStrategy/DrawningObjectAirplane.java new file mode 100644 index 0000000..8182d40 --- /dev/null +++ b/src/MovementStrategy/DrawningObjectAirplane.java @@ -0,0 +1,31 @@ +package MovementStrategy; +import src.DirectionType; +import src.DrawningObjects.DrawningAirplane; + +public class DrawningObjectAirplane implements IMoveableObject{ + private final DrawningAirplane _drawningAirplane; + public DrawningObjectAirplane(DrawningAirplane drawningAirplane){ + _drawningAirplane = drawningAirplane; + } + public ObjectParameters GetObjectParameters(){ + if(_drawningAirplane == null || _drawningAirplane.EntityAirplane() == null) + return null; + return new ObjectParameters(_drawningAirplane.GetPosX(), _drawningAirplane.GetPosY(), + _drawningAirplane.GetWidth(), _drawningAirplane.GetHeight()); + } + public int GetStep(){ + if(_drawningAirplane.EntityAirplane() == null) + return 0; + return (int)_drawningAirplane.EntityAirplane().Step(); + } + public boolean CheckCanMove(DirectionType direction){ + if(_drawningAirplane == null) + return false; + return _drawningAirplane.CanMove(direction); + } + public void MoveObject(DirectionType direction){ + if(_drawningAirplane == null) + return; + _drawningAirplane.MoveTransport(direction); + } +} diff --git a/src/MovementStrategy/IMoveableObject.java b/src/MovementStrategy/IMoveableObject.java new file mode 100644 index 0000000..32d772d --- /dev/null +++ b/src/MovementStrategy/IMoveableObject.java @@ -0,0 +1,10 @@ +package MovementStrategy; + +import src.DirectionType; + +public interface IMoveableObject { + public ObjectParameters GetObjectParameters(); + public int GetStep(); + boolean CheckCanMove(DirectionType direction); + void MoveObject(DirectionType direction); +} diff --git a/src/MovementStrategy/MoveToBorder.java b/src/MovementStrategy/MoveToBorder.java new file mode 100644 index 0000000..2e9bb29 --- /dev/null +++ b/src/MovementStrategy/MoveToBorder.java @@ -0,0 +1,36 @@ +package MovementStrategy; + +public class MoveToBorder extends AbstractStrategy { + @Override + protected boolean IsTargetDestination() { + var objParams = GetObjectParameters(); + if (objParams == null) { + return false; + } + int a = FieldWidth(); + int b = FieldHeight(); + int q = GetStep(); + return objParams.RightBorder <= FieldWidth() && objParams.RightBorder + GetStep() >= FieldWidth() && + objParams.DownBorder <= FieldHeight() && objParams.DownBorder + GetStep() >= FieldHeight(); + } + @Override + protected void MoveToTarget() { + var objParams = GetObjectParameters(); + if (objParams == null) { + return; + } + var diffX = objParams.RightBorder - FieldWidth(); + if (Math.abs(diffX) >= GetStep()) { + if (diffX < 0) { + MoveRight(); + } + } + var diffY = objParams.DownBorder - FieldHeight(); + if (Math.abs(diffY) >= GetStep()) { + if (diffY < 0) { + MoveDown(); + } + } + } +} + diff --git a/src/MovementStrategy/MoveToCenter.java b/src/MovementStrategy/MoveToCenter.java new file mode 100644 index 0000000..18cc240 --- /dev/null +++ b/src/MovementStrategy/MoveToCenter.java @@ -0,0 +1,52 @@ +package MovementStrategy; + +public class MoveToCenter extends AbstractStrategy{ + @Override + protected boolean IsTargetDestination(){ + var objParams = GetObjectParameters(); + if(objParams == null) + return false; + return ((objParams.ObjectMiddleHorizontal <= FieldWidth() / 2 && + objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth() / 2) + ||(objParams.ObjectMiddleHorizontal >= FieldWidth() / 2 && + objParams.ObjectMiddleHorizontal - GetStep() <= FieldWidth() / 2)) && + + ((objParams.ObjectMiddleVertical <= FieldHeight() / 2 && + objParams.ObjectMiddleVertical + GetStep() >= FieldHeight() / 2) || + (objParams.ObjectMiddleVertical >= FieldHeight() / 2 && + objParams.ObjectMiddleVertical - GetStep() <= FieldHeight() / 2)); + } + @Override + protected void MoveToTarget() + { + var objParams = GetObjectParameters(); + if (objParams == null) + { + return; + } + var diffX = objParams.ObjectMiddleHorizontal - FieldWidth() / 2; + if (Math.abs(diffX) > GetStep()) + { + if (diffX > 0) + { + MoveLeft(); + } + else + { + MoveRight(); + } + } + var diffY = objParams.ObjectMiddleVertical - FieldHeight() / 2; + if (Math.abs(diffY) > GetStep()) + { + if (diffY > 0) + { + MoveUp(); + } + else + { + MoveDown(); + } + } + } +} diff --git a/src/MovementStrategy/ObjectParameters.java b/src/MovementStrategy/ObjectParameters.java new file mode 100644 index 0000000..d7e6958 --- /dev/null +++ b/src/MovementStrategy/ObjectParameters.java @@ -0,0 +1,27 @@ +package MovementStrategy; + +public class ObjectParameters { + private final int _x; + private final int _y; + private final int _width; + private final int _height; + public int LeftBorder; + public int TopBorder; + public int RightBorder; + public int DownBorder; + public int ObjectMiddleHorizontal; + public int ObjectMiddleVertical; + public ObjectParameters(int x, int y, int width, int height) + { + _x = x; + _y = y; + _width = width; + _height = height; + LeftBorder = _x; + TopBorder = _y; + RightBorder = _x + width; + DownBorder = _y + _height * 125 / 1000 + (_height-_height * 125 / 1000)/2 ; + ObjectMiddleHorizontal = _x + _width / 2; + ObjectMiddleVertical = _y +(_height - _height * 125 / 1000) / 2 / 2; + } +} diff --git a/src/MovementStrategy/Status.java b/src/MovementStrategy/Status.java new file mode 100644 index 0000000..586b538 --- /dev/null +++ b/src/MovementStrategy/Status.java @@ -0,0 +1,7 @@ +package MovementStrategy; + +public enum Status { + NotInit, + InProgress, + Finish +} diff --git a/src/AirFighterHard/NumberType.java b/src/NumberType.java similarity index 65% rename from src/AirFighterHard/NumberType.java rename to src/NumberType.java index ebba054..1753235 100644 --- a/src/AirFighterHard/NumberType.java +++ b/src/NumberType.java @@ -1,7 +1,6 @@ -package AirFighterHard; - +package src; public enum NumberType { Two, Four, Six -} +} \ No newline at end of file diff --git a/src/README.md b/src/README.md new file mode 100644 index 0000000..29cea80 --- /dev/null +++ b/src/README.md @@ -0,0 +1,2 @@ +# PIbd-23-Kislitsa E.D.-AirFighter-Hard + -- 2.25.1 From 81e02f1e3cf372a1a6f5897a1e9e55405dd4c8cb Mon Sep 17 00:00:00 2001 From: goblinrf Date: Tue, 7 Nov 2023 21:44:02 +0300 Subject: [PATCH 2/3] Done --- .../PIbd_23_Kislitsa_E.D_AirFighter_Hard.iml | 1 - .idea/misc.xml | 1 - src/DrawningObjects/DrawningAirFighter.java | 23 ++++++-- src/DrawningObjects/DrawningAirplane.java | 41 +++++++++----- src/DrawningObjects/DrawningEngines.java | 25 +++++---- src/DrawningObjects/DrawningEnginesOval.java | 52 ++++++++++++++++++ src/DrawningObjects/DrawningEnginesQuad.java | 55 +++++++++++++++++++ src/DrawningObjects/IDraw.java | 3 +- src/Entities/EntityAirFighter.java | 12 ++-- src/Main.java | 2 +- src/MovementStrategy/AbstractStrategy.java | 2 +- .../DrawningObjectAirplane.java | 2 +- src/MovementStrategy/IMoveableObject.java | 2 +- src/MovementStrategy/MoveToBorder.java | 2 +- src/MovementStrategy/MoveToCenter.java | 2 +- src/MovementStrategy/ObjectParameters.java | 2 +- src/MovementStrategy/Status.java | 2 +- 17 files changed, 180 insertions(+), 49 deletions(-) create mode 100644 src/DrawningObjects/DrawningEnginesOval.java create mode 100644 src/DrawningObjects/DrawningEnginesQuad.java diff --git a/.idea/PIbd_23_Kislitsa_E.D_AirFighter_Hard.iml b/.idea/PIbd_23_Kislitsa_E.D_AirFighter_Hard.iml index 852166e..c90834f 100644 --- a/.idea/PIbd_23_Kislitsa_E.D_AirFighter_Hard.iml +++ b/.idea/PIbd_23_Kislitsa_E.D_AirFighter_Hard.iml @@ -4,7 +4,6 @@ - diff --git a/.idea/misc.xml b/.idea/misc.xml index 432b646..1e7df8d 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,4 +1,3 @@ - diff --git a/src/DrawningObjects/DrawningAirFighter.java b/src/DrawningObjects/DrawningAirFighter.java index 0908cea..7ab316b 100644 --- a/src/DrawningObjects/DrawningAirFighter.java +++ b/src/DrawningObjects/DrawningAirFighter.java @@ -6,12 +6,13 @@ import java.awt.*; public class DrawningAirFighter extends DrawningAirplane { public DrawningAirFighter(int speed, double weight, Color bodyColor, Color additionalColor, - boolean dopwings, boolean rackets, int width, int height ){ - super(speed,weight,bodyColor,width,height); - if(EntityAirplane!=null){ - EntityAirplane = new EntityAirFighter(speed, weight, bodyColor, additionalColor, dopwings,rackets); + boolean dopwings, boolean rackets, int width, int height) { + super(speed, weight, bodyColor, width, height); + if (EntityAirplane != null) { + EntityAirplane = new EntityAirFighter(speed, weight, bodyColor, additionalColor, dopwings, rackets); } } + @Override public void DrawAirplane(Graphics2D g2d) { if (!(EntityAirplane instanceof EntityAirFighter)) { @@ -19,7 +20,7 @@ public class DrawningAirFighter extends DrawningAirplane { } super.DrawAirplane(g2d); EntityAirFighter _airplaneAirFighter = (EntityAirFighter) EntityAirplane; - if (EntityAirFighter.Racket()) { + if (_airplaneAirFighter.Racket()) { g2d.setColor(Color.GRAY); g2d.fillRect(_startPosX + 70, _startPosY - 15, 10, 10); g2d.setColor(Color.BLACK); @@ -65,5 +66,17 @@ public class DrawningAirFighter extends DrawningAirplane { g2d.drawPolygon(xPoints4ArrNoseRacket, yPoints4ArrNoseRacket, xPoints4ArrNoseRacket.length); } + if (_airplaneAirFighter.DopWing()) { + g2d.setColor(_airplaneAirFighter.AdditionalColor()); + int[] xPointsrightdopwing = {_startPosX + 30, _startPosX + 30, _startPosX + 35, _startPosX + 45}; + int[] yPointsrightdopwing = {_startPosY + 4, _startPosY - 34, _startPosY - 34, _startPosY + 4}; + g2d.fillPolygon(xPointsrightdopwing, yPointsrightdopwing, xPointsrightdopwing.length); + + int[] xPointsleftdopwing = {_startPosX + 30,_startPosX + 30,_startPosX+35,_startPosX+45}; + int[] yPointsleftdopwing = {_startPosY + 24,_startPosY + 59,_startPosY + 59,_startPosY + 24}; + g2d.fillPolygon(xPointsleftdopwing,yPointsleftdopwing,xPointsleftdopwing.length); + } } } + + diff --git a/src/DrawningObjects/DrawningAirplane.java b/src/DrawningObjects/DrawningAirplane.java index 0d726ea..f490ce2 100644 --- a/src/DrawningObjects/DrawningAirplane.java +++ b/src/DrawningObjects/DrawningAirplane.java @@ -9,8 +9,8 @@ public class DrawningAirplane { protected EntityAirplane EntityAirplane; private int _pictureWidth; private int _pictureHeight; - private int _startPosX = 0; - private int _startPosY = 0; + protected int _startPosX = 0; + protected int _startPosY = 0; private int _airplaneWidth = 160; private int _airplaneHeight = 68; private int _airplanekorpusHeight = 90; @@ -28,14 +28,25 @@ public class DrawningAirplane { _pictureWidth = width; _pictureHeight = height; EntityAirplane = new EntityAirplane(speed, weight, bodyColor); - - DrawningEngines = new DrawningEngines (_startPosX,_startPosY); + DrawningEngines = new DrawningEngines(_airplaneWidth, _airplaneHeight,_startPosX,_startPosY); Random rand = new Random(); int variant = rand.nextInt(0,3); + if(variant ==0){ + DrawningEngines = new DrawningEngines(_airplaneWidth, _airplaneHeight,_startPosX,_startPosY); + } else{ + if(variant ==1){ + DrawningEngines = new DrawningEnginesQuad(_airplaneWidth, _airplaneHeight,_startPosX,_startPosY); + + } + else if(variant==2) { + DrawningEngines = new DrawningEnginesOval(_airplaneWidth, _airplaneHeight, _startPosX, _startPosY); + } + } + DrawningEngines.ChangeEnginesNumb(rand.nextInt(1, 5)); } public void SetPosition(int x, int y){ - if(EntityAirFighter == null) + if(EntityAirplane == null) return; _startPosX = x; _startPosY = y; @@ -62,10 +73,10 @@ public class DrawningAirplane { can = _startPosX + EntityAirplane.Step() + _airplaneWidth< _pictureWidth; break; case Down: - can = _startPosY + EntityAirFighter.Step() + _airplanekorpusHeight < _pictureHeight; + can = _startPosY + EntityAirplane.Step() + _airplanekorpusHeight < _pictureHeight; break; case Up: - can = _startPosY - EntityAirplane.Step() >= 0; + can = _startPosY - EntityAirplane.Step() - _airplaneHeight >= 0; break; }; return can; @@ -83,7 +94,7 @@ public class DrawningAirplane { _startPosX = 0; break; case Up: - if (_startPosY - EntityAirplane.Step() >= 0) + if (_startPosY - EntityAirplane.Step() - _airplaneHeight >= 0) _startPosY -= (int)EntityAirplane.Step(); else _startPosY = 0; @@ -106,11 +117,11 @@ public class DrawningAirplane { } public void DrawAirplane(Graphics2D g2d){ - if (EntityAirFighter == null) + if (EntityAirplane == null) return; - DrawningEngines.DrawEngines(); + DrawningEngines.DrawEngines(g2d); //тело самолёта - g2d.setColor(EntityAirFighter.BodyColor()); + g2d.setColor(EntityAirplane.BodyColor()); g2d.fillRect(_startPosX + 20,_startPosY +4,140,20); g2d.setColor(Color.BLACK); g2d.drawRect(_startPosX + 20,_startPosY +4,140,20); @@ -125,7 +136,7 @@ public class DrawningAirplane { // Правое крыло int[] xPointsArrRightWing = {_startPosX + 80,_startPosX+80,_startPosX+85,_startPosX + 100}; int[] yPointsArrRightWing = { _startPosY + 4,_startPosY - 66,_startPosY - 66, _startPosY + 4 }; - g2d.setColor(EntityAirFighter.BodyColor()); + g2d.setColor(EntityAirplane.BodyColor()); g2d.fillPolygon(xPointsArrRightWing, yPointsArrRightWing, xPointsArrRightWing.length); g2d.setColor(Color.BLACK); g2d.drawPolygon(xPointsArrRightWing, yPointsArrRightWing, xPointsArrRightWing.length); @@ -133,7 +144,7 @@ public class DrawningAirplane { // Левое крыло int[] xPointsArrLeftWing = {_startPosX + 80,_startPosX + 100,_startPosX+85,_startPosX+80}; int[] yPointsArrLeftWing = {_startPosY + 24,_startPosY + 24,_startPosY + 94,_startPosY + 94}; - g2d.setColor(EntityAirFighter.BodyColor()); + g2d.setColor(EntityAirplane.BodyColor()); g2d.fillPolygon(xPointsArrLeftWing, yPointsArrLeftWing, xPointsArrLeftWing.length); g2d.setColor(Color.BLACK); g2d.drawPolygon(xPointsArrLeftWing, yPointsArrLeftWing, xPointsArrLeftWing.length); @@ -141,14 +152,14 @@ public class DrawningAirplane { // Правое задние крыло int[] xPointsArrRightBackWing={_startPosX + 140,_startPosX + 160,_startPosX+160,_startPosX+140}; int[] yPointsArrRightBackWing={ _startPosY + 4,_startPosY + 4,_startPosY - 22,_startPosY -4}; - g2d.setColor(EntityAirFighter.BodyColor()); + g2d.setColor(EntityAirplane.BodyColor()); g2d.fillPolygon(xPointsArrRightBackWing, yPointsArrRightBackWing, xPointsArrRightBackWing.length); g2d.setColor(Color.BLACK); g2d.drawPolygon(xPointsArrRightBackWing, yPointsArrRightBackWing, xPointsArrRightBackWing.length); // Заднее левое крыло int[] xPointsArrLeftBackWing= {_startPosX + 140,_startPosX + 160,_startPosX+160,_startPosX+140}; int[] yPointsArrLeftBackWing= {_startPosY + 24,_startPosY + 24,_startPosY + 50,_startPosY + 32}; - g2d.setColor(EntityAirFighter.BodyColor()); + g2d.setColor(EntityAirplane.BodyColor()); g2d.fillPolygon(xPointsArrLeftBackWing, yPointsArrLeftBackWing, xPointsArrLeftBackWing.length); g2d.setColor(Color.BLACK); g2d.drawPolygon(xPointsArrLeftBackWing, yPointsArrLeftBackWing, xPointsArrLeftBackWing.length); diff --git a/src/DrawningObjects/DrawningEngines.java b/src/DrawningObjects/DrawningEngines.java index 8bc0121..1135b60 100644 --- a/src/DrawningObjects/DrawningEngines.java +++ b/src/DrawningObjects/DrawningEngines.java @@ -5,11 +5,13 @@ import src.NumberType; public class DrawningEngines implements IDraw { - private NumberType EnginesNumb; + private NumberType EngineNumb; + private int Width, Height; private Color EngineColor; public int CurX, CurY; - boolean DrawningEngines( int curX, int curY){ - + public DrawningEngines(int width, int height,int curX, int curY){ + Width = width; + Height = height; CurX = curX; CurY = curY; EngineColor = Color.BLACK; @@ -22,29 +24,28 @@ public class DrawningEngines implements IDraw { } public void ChangeEnginesNumb(int x){ if(x <= 1) - EnginesNumb = NumberType.Two; + EngineNumb = NumberType.Two; if(x == 2) - EnginesNumb = NumberType.Four; + EngineNumb = NumberType.Four; if(x >= 3) - EnginesNumb = NumberType.Six; + EngineNumb = NumberType.Six; } - public NumberType WheelsNumb(){ - return EnginesNumb; + public NumberType EngineNumb(){ + return EngineNumb; } - public void DrawEngines(){ - Graphics2D g2d = (Graphics2D) AirFighterPanel.getGraphics(); + public void DrawEngines(Graphics2D g2d){ g2d.setColor(EngineColor); g2d.fillOval(CurX + 92,CurY - 15,25,10 ); g2d.fillOval(CurX + 92,CurY + 34,25,10 ); - if (EnginesNumb == NumberType.Four || EnginesNumb == NumberType.Six) + if (EngineNumb == NumberType.Four || EngineNumb == NumberType.Six) { g2d.fillOval(CurX + 86,CurY - 40,25,10 ); g2d.fillOval(CurX + 86,CurY +59,25,10 ); } - if (EnginesNumb == NumberType.Six) + if (EngineNumb == NumberType.Six) { g2d.fillOval(CurX + 128,CurY -7,25,10 ); g2d.fillOval(CurX + 128,CurY +25,25,10 ); diff --git a/src/DrawningObjects/DrawningEnginesOval.java b/src/DrawningObjects/DrawningEnginesOval.java new file mode 100644 index 0000000..c9201db --- /dev/null +++ b/src/DrawningObjects/DrawningEnginesOval.java @@ -0,0 +1,52 @@ +package src.DrawningObjects; + +import java.awt.*; + +public class DrawningEnginesOval implements IDraw{ + private src.NumberType EngineNumb; + private int Width, Height; + private Color EngineColor; + public int CurX, CurY; + public DrawningEnginesOval(int width, int height,int curX, int curY){ + Width = width; + Height = height; + CurX = curX; + CurY = curY; + EngineColor = Color.BLACK; + } + public void ChangeX(int x){ + CurX = x; + } + public void ChangeY(int y){ + CurY = y; + } + public void ChangeEnginesNumb(int x){ + if(x <= 1) + EngineNumb = src.NumberType.Two; + if(x == 2) + EngineNumb = src.NumberType.Four; + if(x >= 3) + EngineNumb = src.NumberType.Six; + } + public src.NumberType EngineNumb(){ + return EngineNumb; + } + public void DrawEngines(Graphics2D g2d){ + g2d.setColor(EngineColor); + g2d.drawOval(CurX + 92,CurY - 15,25,10 ); + g2d.drawOval(CurX + 92,CurY + 34,25,10 ); + + if (EngineNumb == src.NumberType.Four || EngineNumb == src.NumberType.Six) + { + g2d.drawOval(CurX + 86,CurY - 40,25,10 ); + + g2d.drawOval(CurX + 86,CurY +59,25,10 ); + } + + if (EngineNumb == src.NumberType.Six) + { + g2d.drawOval(CurX + 128,CurY -7,25,10 ); + g2d.drawOval(CurX + 128,CurY +25,25,10 ); + } + } +} diff --git a/src/DrawningObjects/DrawningEnginesQuad.java b/src/DrawningObjects/DrawningEnginesQuad.java new file mode 100644 index 0000000..6dcaee5 --- /dev/null +++ b/src/DrawningObjects/DrawningEnginesQuad.java @@ -0,0 +1,55 @@ +package src.DrawningObjects; + +import src.NumberType; + +import javax.swing.*; +import java.awt.*; + +public class DrawningEnginesQuad implements IDraw { + private src.NumberType EngineNumb; + private int Width, Height; + private Color EngineColor; + public int CurX, CurY; + public DrawningEnginesQuad(int width, int height, int curX, int curY){ + Width = width; + Height = height; + CurX = curX; + CurY = curY; + EngineColor = Color.BLACK; + } + public void ChangeX(int x){ + CurX = x; + } + public void ChangeY(int y){ + CurY = y; + } + public void ChangeEnginesNumb(int x){ + if(x <= 1) + EngineNumb = src.NumberType.Two; + if(x == 2) + EngineNumb = src.NumberType.Four; + if(x >= 3) + EngineNumb = src.NumberType.Six; + } + public src.NumberType EngineNumb(){ + return EngineNumb; + } + public void DrawEngines(Graphics2D g2d){ + g2d.setColor(EngineColor); + g2d.fillRect(CurX + 92,CurY - 15,25,10 ); + g2d.fillRect(CurX + 92,CurY + 34,25,10 ); + + if (EngineNumb == src.NumberType.Four || EngineNumb == src.NumberType.Six) + { + g2d.fillRect(CurX + 86,CurY - 40,25,10 ); + + g2d.fillRect(CurX + 86,CurY +59,25,10 ); + } + + if (EngineNumb == src.NumberType.Six) + { + g2d.fillRect(CurX + 128,CurY -7,25,10 ); + g2d.fillRect(CurX + 128,CurY +25,25,10 ); + } + } +} diff --git a/src/DrawningObjects/IDraw.java b/src/DrawningObjects/IDraw.java index 2d0c05e..192b4c8 100644 --- a/src/DrawningObjects/IDraw.java +++ b/src/DrawningObjects/IDraw.java @@ -2,8 +2,7 @@ package src.DrawningObjects; import src.NumberType; import java.awt.*; public interface IDraw { - public void ChangeEngineNumb(int x); - //public NumberType EngineNumb(); + public void ChangeEnginesNumb(int x); public void DrawEngines(Graphics2D g2d); public void ChangeX(int x); public void ChangeY(int y); diff --git a/src/Entities/EntityAirFighter.java b/src/Entities/EntityAirFighter.java index b6de805..d098bca 100644 --- a/src/Entities/EntityAirFighter.java +++ b/src/Entities/EntityAirFighter.java @@ -3,20 +3,22 @@ import java.awt.*; public class EntityAirFighter extends EntityAirplane { private Color BodyColor; - private boolean Wing; + private Color AdditionalColor; + private boolean DopWing; private boolean Racket; + public Color AdditionalColor(){return AdditionalColor;} public Color BodyColor(){ return BodyColor; } public boolean Racket(){return Racket;} - public boolean DopWing(){return Wing;} - public void Init(int speed, double weight, Color bodyColor, + public boolean DopWing(){return DopWing;} + public EntityAirFighter(int speed, double weight, Color bodyColor, Color additionalColor, boolean racket, boolean dopwing){ super(speed, weight, bodyColor); BodyColor = bodyColor; - + AdditionalColor=additionalColor; Racket = racket; - Wing = wing; + DopWing= dopwing; } } diff --git a/src/Main.java b/src/Main.java index 7928ef2..f8a4ff2 100644 --- a/src/Main.java +++ b/src/Main.java @@ -1,5 +1,5 @@ package src; -import src.DrawningObjects.DrawningAirplaneWithRadar; +import src.DrawningObjects.DrawningAirFighter; import src.DrawningObjects.DrawningAirplane; import src.MovementStrategy.*; import java.awt.*; diff --git a/src/MovementStrategy/AbstractStrategy.java b/src/MovementStrategy/AbstractStrategy.java index 9634f7a..db7f984 100644 --- a/src/MovementStrategy/AbstractStrategy.java +++ b/src/MovementStrategy/AbstractStrategy.java @@ -1,4 +1,4 @@ -package MovementStrategy; +package src.MovementStrategy; import src.DirectionType; public abstract class AbstractStrategy { diff --git a/src/MovementStrategy/DrawningObjectAirplane.java b/src/MovementStrategy/DrawningObjectAirplane.java index 8182d40..589b3b5 100644 --- a/src/MovementStrategy/DrawningObjectAirplane.java +++ b/src/MovementStrategy/DrawningObjectAirplane.java @@ -1,4 +1,4 @@ -package MovementStrategy; +package src.MovementStrategy; import src.DirectionType; import src.DrawningObjects.DrawningAirplane; diff --git a/src/MovementStrategy/IMoveableObject.java b/src/MovementStrategy/IMoveableObject.java index 32d772d..deb24ff 100644 --- a/src/MovementStrategy/IMoveableObject.java +++ b/src/MovementStrategy/IMoveableObject.java @@ -1,4 +1,4 @@ -package MovementStrategy; +package src.MovementStrategy; import src.DirectionType; diff --git a/src/MovementStrategy/MoveToBorder.java b/src/MovementStrategy/MoveToBorder.java index 2e9bb29..2c14d1d 100644 --- a/src/MovementStrategy/MoveToBorder.java +++ b/src/MovementStrategy/MoveToBorder.java @@ -1,4 +1,4 @@ -package MovementStrategy; +package src.MovementStrategy; public class MoveToBorder extends AbstractStrategy { @Override diff --git a/src/MovementStrategy/MoveToCenter.java b/src/MovementStrategy/MoveToCenter.java index 18cc240..e54e8d8 100644 --- a/src/MovementStrategy/MoveToCenter.java +++ b/src/MovementStrategy/MoveToCenter.java @@ -1,4 +1,4 @@ -package MovementStrategy; +package src.MovementStrategy; public class MoveToCenter extends AbstractStrategy{ @Override diff --git a/src/MovementStrategy/ObjectParameters.java b/src/MovementStrategy/ObjectParameters.java index d7e6958..d4b198c 100644 --- a/src/MovementStrategy/ObjectParameters.java +++ b/src/MovementStrategy/ObjectParameters.java @@ -1,4 +1,4 @@ -package MovementStrategy; +package src.MovementStrategy; public class ObjectParameters { private final int _x; diff --git a/src/MovementStrategy/Status.java b/src/MovementStrategy/Status.java index 586b538..aeff748 100644 --- a/src/MovementStrategy/Status.java +++ b/src/MovementStrategy/Status.java @@ -1,4 +1,4 @@ -package MovementStrategy; +package src.MovementStrategy; public enum Status { NotInit, -- 2.25.1 From c76841f5e2b6ae28335ed8f87eb4ba49909bb84d Mon Sep 17 00:00:00 2001 From: goblinrf Date: Fri, 24 Nov 2023 23:24:01 +0300 Subject: [PATCH 3/3] Done --- .idea/misc.xml | 1 + src/FormAirFighter.java | 34 +++++++++++++++++----------------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index 1e7df8d..432b646 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,3 +1,4 @@ + diff --git a/src/FormAirFighter.java b/src/FormAirFighter.java index ac2b095..af2c1ff 100644 --- a/src/FormAirFighter.java +++ b/src/FormAirFighter.java @@ -23,9 +23,9 @@ public class FormAirFighter { } public FormAirFighter(){ - JFrame MonorailFrame =new JFrame (); + JFrame AirplaneFrame =new JFrame (); JButton buttonCreate = new JButton("Создать"); - JButton buttonCreateLocomotive = new JButton("Создать самолет с радаром"); + JButton buttonCreateAirFighter = new JButton("Создать боевой самолёт"); JButton buttonStep = new JButton("Шаг"); JComboBox comboBoxStrategy = new JComboBox( new String[]{ @@ -98,7 +98,7 @@ public class FormAirFighter { } } ); - buttonCreateLocomotive.addActionListener( + buttonCreateAirFighter.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e){ Random random = new Random(); @@ -151,29 +151,29 @@ public class FormAirFighter { } }); - MonorailFrame.setSize (900, 500); - MonorailFrame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); - MonorailFrame.setLayout(null); + AirplaneFrame.setSize (900, 500); + AirplaneFrame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); + AirplaneFrame.setLayout(null); canv = new Canvas(); canv.setSize(pictureBoxWidth, pictureBoxHeight); buttonCreate.setBounds(198, 401, 180, 40); - buttonCreateLocomotive.setBounds(12, 401, 180, 40); + buttonCreateAirFighter.setBounds(12, 401, 180, 40); RightButton.setBounds(840,411,30,30); LeftButton.setBounds(768,411,30,30); UpButton.setBounds(804,375,30,30); DownButton.setBounds(804,411,30,30); comboBoxStrategy.setBounds(719,12,151,28); buttonStep.setBounds(768, 46, 94, 29); - MonorailFrame.add(canv); - MonorailFrame.add(buttonCreate); - MonorailFrame.add(buttonCreateLocomotive); - MonorailFrame.add(UpButton); - MonorailFrame.add(DownButton); - MonorailFrame.add(LeftButton); - MonorailFrame.add(RightButton); - MonorailFrame.add(comboBoxStrategy); - MonorailFrame.add(buttonStep); - MonorailFrame.setVisible(true); + AirplaneFrame.add(canv); + AirplaneFrame.add(buttonCreate); + AirplaneFrame.add(buttonCreateAirFighter); + AirplaneFrame.add(UpButton); + AirplaneFrame.add(DownButton); + AirplaneFrame.add(LeftButton); + AirplaneFrame.add(RightButton); + AirplaneFrame.add(comboBoxStrategy); + AirplaneFrame.add(buttonStep); + AirplaneFrame.setVisible(true); } } class Canvas extends JComponent{ -- 2.25.1