From 268582bd6dd55619eaaf2804ddf5b6876fdd4f58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A0=D0=BE=D0=BC=D0=B0=20=D0=9F=D0=B5=D1=80=D0=BC=D1=8F?= =?UTF-8?q?=D0=BA=D0=BE=D0=B2?= Date: Mon, 22 Apr 2024 14:04:18 +0400 Subject: [PATCH 1/2] =?UTF-8?q?=D0=9B=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=20=E2=84=961?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AccordionBus/src/AccordionBus.form | 66 +++++++ AccordionBus/src/AccordionBus.java | 82 ++++++++ AccordionBus/src/DirectionType.java | 6 + AccordionBus/src/DrawningAccordionBus.java | 217 +++++++++++++++++++++ AccordionBus/src/EntityAccordionBus.java | 52 +++++ AccordionBus/src/EnumerateDoors.java | 16 ++ AccordionBus/src/Main.java | 2 +- AccordionBus/src/Resources/buttDown.png | Bin 0 -> 662 bytes AccordionBus/src/Resources/buttLeft.png | Bin 0 -> 684 bytes AccordionBus/src/Resources/buttRIght.png | Bin 0 -> 689 bytes AccordionBus/src/Resources/buttUp.png | Bin 0 -> 684 bytes 11 files changed, 440 insertions(+), 1 deletion(-) create mode 100644 AccordionBus/src/AccordionBus.form create mode 100644 AccordionBus/src/AccordionBus.java create mode 100644 AccordionBus/src/DirectionType.java create mode 100644 AccordionBus/src/DrawningAccordionBus.java create mode 100644 AccordionBus/src/EntityAccordionBus.java create mode 100644 AccordionBus/src/EnumerateDoors.java create mode 100644 AccordionBus/src/Resources/buttDown.png create mode 100644 AccordionBus/src/Resources/buttLeft.png create mode 100644 AccordionBus/src/Resources/buttRIght.png create mode 100644 AccordionBus/src/Resources/buttUp.png diff --git a/AccordionBus/src/AccordionBus.form b/AccordionBus/src/AccordionBus.form new file mode 100644 index 0000000..cdce57d --- /dev/null +++ b/AccordionBus/src/AccordionBus.form @@ -0,0 +1,66 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/AccordionBus/src/AccordionBus.java b/AccordionBus/src/AccordionBus.java new file mode 100644 index 0000000..275c886 --- /dev/null +++ b/AccordionBus/src/AccordionBus.java @@ -0,0 +1,82 @@ +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.Random; + +public class AccordionBus extends JFrame { + private JPanel panelAccordionBus; + private JButton buttonDown; + private JButton buttonLeft; + private JButton buttonRight; + private JButton buttonUp; + private JButton buttonCreate; + + private DrawningAccordionBus drawningAccordionBus; + + public void paint(Graphics g){ + super.paint(g); + if (drawningAccordionBus == null) return; + drawningAccordionBus.drawTransport(g); + } + + public AccordionBus(){ + add(panelAccordionBus); + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setVisible(true); + setBounds(300, 150, 1200, 800); + setResizable(false); + Graphics g = getGraphics().create(); + Icon iconDown = new ImageIcon("AccordionBus\\src\\Resources\\buttDown.png"); + Icon iconUp = new ImageIcon("AccordionBus\\src\\Resources\\buttUp.png"); + Icon iconLeft = new ImageIcon("AccordionBus\\src\\Resources\\buttLeft.png"); + Icon iconRight = new ImageIcon("AccordionBus\\src\\Resources\\buttRight.png"); + buttonDown.setIcon(iconDown); + buttonLeft.setIcon(iconLeft); + buttonUp.setIcon(iconUp); + buttonRight.setIcon(iconRight); + drawningAccordionBus = new DrawningAccordionBus(); + buttonCreate.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + Random rnd = new Random(); + + drawningAccordionBus.Init(rnd.nextInt(90) + 10, rnd.nextInt(990) + 10, + new Color(rnd.nextInt(255), rnd.nextInt(255), rnd.nextInt(255)), + new Color(rnd.nextInt(255), rnd.nextInt(255), rnd.nextInt(255)), + rnd.nextBoolean(), rnd.nextBoolean(), rnd.nextBoolean(), EnumerateDoors.getRandomValue()); + drawningAccordionBus.setPictureSize(panelAccordionBus.getWidth(), panelAccordionBus.getHeight()); + drawningAccordionBus.setPosition(rnd.nextInt(100) + 50, rnd.nextInt(100) + 50); + paint(g); + } + }); + + buttonRight.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + if (drawningAccordionBus.moveTransport(DirectionType.Right)) paint(g); + } + }); + + buttonLeft.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + if (drawningAccordionBus.moveTransport(DirectionType.Left)) paint(g); + } + }); + + buttonUp.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + if (drawningAccordionBus.moveTransport(DirectionType.Up)) paint(g); + } + }); + + buttonDown.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + if (drawningAccordionBus.moveTransport(DirectionType.Down)) paint(g); + } + }); + } +} diff --git a/AccordionBus/src/DirectionType.java b/AccordionBus/src/DirectionType.java new file mode 100644 index 0000000..1afad5c --- /dev/null +++ b/AccordionBus/src/DirectionType.java @@ -0,0 +1,6 @@ +public enum DirectionType { + Up, + Down, + Left, + Right; +} \ No newline at end of file diff --git a/AccordionBus/src/DrawningAccordionBus.java b/AccordionBus/src/DrawningAccordionBus.java new file mode 100644 index 0000000..9a4e7f8 --- /dev/null +++ b/AccordionBus/src/DrawningAccordionBus.java @@ -0,0 +1,217 @@ +import java.awt.*; + +public class DrawningAccordionBus { + private EntityAccordionBus entityAccordionBus; + + public EntityAccordionBus getEntityAccordionBus(){return entityAccordionBus;} + + private Integer pictureWidth; + + private Integer pictureHeight; + + private Integer startPosX; + + private Integer startPosY; + + private final int drawingBusWidth = 130; + + private final int drawingBusHeight = 35; + + public void Init(int speed, double weight, Color bodyColor, Color additionalColor, + boolean hatch, boolean fourWheels, boolean additionalLine, EnumerateDoors enumerateDoors){ + entityAccordionBus = new EntityAccordionBus(); + entityAccordionBus.Init(speed, weight, bodyColor, additionalColor, + hatch, fourWheels, additionalLine, enumerateDoors); + pictureHeight = null; + pictureWidth = null; + startPosX = null; + startPosY = null; + } + + public boolean setPictureSize(int width, int height){ + if (drawingBusHeight > height || drawingBusWidth > width) { + return false; + } + if (startPosY != null && startPosX != null) { + if (startPosX + drawingBusWidth > width) { + startPosX = width - drawingBusWidth; + } + if (startPosY + drawingBusHeight > height) { + startPosY = height - drawingBusHeight; + } + } + pictureWidth = width; + pictureHeight = height; + return true; + } + + public void setPosition(int x, int y) { + if (pictureHeight == null || pictureWidth == null) { + return; + } + if (x + drawingBusWidth > pictureWidth || x < 0) { + startPosX = pictureWidth - drawingBusWidth; + } else { + startPosX = x; + } + if (y + drawingBusHeight > pictureHeight || y < 0) { + startPosY = pictureHeight - drawingBusHeight; + } else { + startPosY = y; + } + } + + public boolean moveTransport(DirectionType direction){ + if (entityAccordionBus == null || startPosX == null || startPosY == null) return false; + + int heightCap = 30; + double step = entityAccordionBus.getStep(); + switch (direction){ + case Left: + if (startPosX - step > 0) startPosX -= (int)step; + else startPosX = 0; + return true; + case Right: + if (startPosX + drawingBusWidth + step < pictureWidth - heightCap) startPosX += (int)step; + else startPosX = pictureWidth - drawingBusWidth; + return true; + case Up: + if (startPosY - step > heightCap) startPosY -= (int)step; + else startPosY = heightCap; + return true; + case Down: + if (startPosY + drawingBusHeight < pictureHeight) startPosY += (int)step; + else startPosY = pictureHeight - drawingBusHeight; + return true; + default: + return false; + } + } + + public void drawTransport(Graphics g){ + if (entityAccordionBus == null || startPosY == null || startPosX == null) return; + + //корпус + g.setColor(entityAccordionBus.getBodyColor()); + g.fillRect(startPosX.intValue(), startPosY.intValue() + 10, 60, 15); + g.fillRect(startPosX.intValue() + 70, startPosY.intValue() + 10, 60, 15); + g.setColor(Color.black); + g.drawRect(startPosX.intValue() + 70, startPosY.intValue() + 10, 60, 15); + g.drawRect(startPosX.intValue(), startPosY.intValue() + 10, 60, 15); + + //доп. линия + if (entityAccordionBus.getAdditionalLine()){ + g.setColor(entityAccordionBus.getAdditionalColor()); + g.fillRect(startPosX, startPosY + 20, 60, 3); + g.fillRect(startPosX + 70, startPosY + 20, 60, 3); + g.setColor(Color.black); + g.drawRect(startPosX, startPosY + 20, 60, 3); + g.drawRect(startPosX + 70, startPosY + 20, 60, 3); + } + + //стёкла + g.setColor(Color.cyan); + g.fillRect(startPosX + 2, startPosY + 13, 5, 5); + g.fillRect(startPosX + 12, startPosY + 13, 5, 5); + g.fillRect(startPosX + 32, startPosY + 13, 5, 5); + g.fillRect(startPosX + 42, startPosY + 13, 5, 5); + + g.fillRect(startPosX + 72, startPosY + 13, 5, 5); + g.fillRect(startPosX + 82, startPosY + 13, 5, 5); + g.fillRect(startPosX + 92, startPosY + 13, 5, 5); + g.fillRect(startPosX + 102, startPosY + 13, 5, 5); + g.fillRect(startPosX + 112, startPosY + 13, 5, 5); + + g.setColor(Color.black); + g.drawRect(startPosX + 2, startPosY + 13, 5, 5); + g.drawRect(startPosX + 12, startPosY + 13, 5, 5); + g.drawRect(startPosX + 32, startPosY + 13, 5, 5); + g.drawRect(startPosX + 42, startPosY + 13, 5, 5); + + g.drawRect(startPosX + 72, startPosY + 13, 5, 5); + g.drawRect(startPosX + 82, startPosY + 13, 5, 5); + g.drawRect(startPosX + 92, startPosY + 13, 5, 5); + g.drawRect(startPosX + 102, startPosY + 13, 5, 5); + g.drawRect(startPosX + 112, startPosY + 13, 5, 5); + + //гормошка + g.drawLine(startPosX + 60, startPosY + 10, startPosX + 62, startPosY + 13); + g.drawLine(startPosX + 62, startPosY + 13, startPosX + 65, startPosY + 10); + g.drawLine(startPosX + 65, startPosY + 10, startPosX + 67, startPosY + 13); + g.drawLine(startPosX + 67, startPosY + 13, startPosX + 70, startPosY + 10); + g.drawLine(startPosX + 60, startPosY + 25, startPosX + 62, startPosY + 22); + g.drawLine(startPosX + 62, startPosY + 22, startPosX + 65, startPosY + 25); + g.drawLine(startPosX + 65, startPosY + 25, startPosX + 67, startPosY + 22); + g.drawLine(startPosX + 67, startPosY + 22, startPosX + 70, startPosY + 25); + g.drawLine(startPosX + 62, startPosY + 13, startPosX + 62, startPosY + 22); + g.drawLine(startPosX + 67, startPosY + 13, startPosX + 67, startPosY + 22); + g.drawLine(startPosX + 65, startPosY + 10, startPosX + 65, startPosY + 25); + + //колёса + g.setColor(Color.white); + g.fillOval(startPosX + 5, startPosY + 20, 10, 10); + g.fillOval(startPosX + 40, startPosY + 20, 10, 10); + + g.fillOval(startPosX + 110, startPosY + 20, 10, 10); + if (entityAccordionBus.getFourWheels()) + g.fillOval(startPosX + 75, startPosY + 20, 10, 10); + + g.setColor(Color.black); + g.drawOval(startPosX + 5, startPosY + 20, 10, 10); + g.drawOval(startPosX + 40, startPosY + 20, 10, 10); + + g.drawOval(startPosX + 110, startPosY + 20, 10, 10); + if (entityAccordionBus.getFourWheels()) + g.drawOval(startPosX + 75, startPosY + 20, 10, 10); + + //люки + if (entityAccordionBus.getHatch()){ + g.setColor(entityAccordionBus.getAdditionalColor()); + g.fillRect(startPosX + 10, startPosY + 7, 10, 3); + g.fillRect(startPosX + 90, startPosY + 7, 10, 3); + g.setColor(Color.black); + g.drawRect(startPosX + 10, startPosY + 7, 10, 3); + g.drawRect(startPosX + 90, startPosY + 7, 10, 3); + } + + //двери + switch(entityAccordionBus.getEnumerateDoors()){ + case threeDoors: + g.setColor(entityAccordionBus.getAdditionalColor()); + g.fillRect(startPosX + 20, startPosY + 15, 5, 10); + g.fillRect(startPosX + 123, startPosY + 15, 5, 10); + g.fillRect(startPosX + 87, startPosY + 15, 5, 10); + g.setColor(Color.black); + g.drawRect(startPosX + 20, startPosY + 15, 5, 10); + g.drawRect(startPosX + 123, startPosY + 15, 5, 10); + g.drawRect(startPosX + 87, startPosY + 15, 5, 10); + break; + case fourDoors: + g.setColor(entityAccordionBus.getAdditionalColor()); + g.fillRect(startPosX + 20, startPosY + 15, 5, 10); + g.fillRect(startPosX + 123, startPosY + 15, 5, 10); + g.fillRect(startPosX + 87, startPosY + 15, 5, 10); + g.fillRect(startPosX + 53, startPosY + 15, 5, 10); + g.setColor(Color.black); + g.drawRect(startPosX + 20, startPosY + 15, 5, 10); + g.drawRect(startPosX + 123, startPosY + 15, 5, 10); + g.drawRect(startPosX + 87, startPosY + 15, 5, 10); + g.drawRect(startPosX + 53, startPosY + 15, 5, 10); + break; + case fiveDoors: + g.setColor(entityAccordionBus.getAdditionalColor()); + g.fillRect(startPosX + 20, startPosY + 15, 5, 10); + g.fillRect(startPosX + 123, startPosY + 15, 5, 10); + g.fillRect(startPosX + 87, startPosY + 15, 5, 10); + g.fillRect(startPosX + 53, startPosY + 15, 5, 10); + g.fillRect(startPosX + 27, startPosY + 19, 11, 5); + g.setColor(Color.black); + g.drawRect(startPosX + 20, startPosY + 15, 5, 10); + g.drawRect(startPosX + 123, startPosY + 15, 5, 10); + g.drawRect(startPosX + 87, startPosY + 15, 5, 10); + g.drawRect(startPosX + 53, startPosY + 15, 5, 10); + g.drawRect(startPosX + 27, startPosY + 19, 11, 5); + break; + } + } +} \ No newline at end of file diff --git a/AccordionBus/src/EntityAccordionBus.java b/AccordionBus/src/EntityAccordionBus.java new file mode 100644 index 0000000..1630a08 --- /dev/null +++ b/AccordionBus/src/EntityAccordionBus.java @@ -0,0 +1,52 @@ +import java.awt.*; + +public class EntityAccordionBus { + private int speed; + + public int getSpeed(){return speed;} + + private double weight; + + public double getWeight(){return weight;} + + private double step; + + public double getStep(){return step;} + + private Color bodyColor; + + public Color getBodyColor(){return bodyColor;} + + private Color additionalColor; + + public Color getAdditionalColor(){return additionalColor;} + + private boolean hatch; + + public boolean getHatch(){return hatch;} + + private boolean fourWheels; + + public boolean getFourWheels(){return fourWheels;} + + private boolean additionalLine; + + public boolean getAdditionalLine(){return additionalLine;} + + private EnumerateDoors enumerateDoors; + + public EnumerateDoors getEnumerateDoors(){return enumerateDoors;} + + public void Init(int speed, double weight, Color bodyColor, Color additionalColor, + boolean hatch, boolean fourWheels, boolean additionalLine, EnumerateDoors enumerateDoors){ + this.speed = speed; + this.weight = weight; + this.bodyColor = bodyColor; + this.additionalColor = additionalColor; + this.hatch = hatch; + this.fourWheels = fourWheels; + this.additionalLine = additionalLine; + this.enumerateDoors = enumerateDoors; + step = speed * 100 / weight; + } +} \ No newline at end of file diff --git a/AccordionBus/src/EnumerateDoors.java b/AccordionBus/src/EnumerateDoors.java new file mode 100644 index 0000000..d0e2218 --- /dev/null +++ b/AccordionBus/src/EnumerateDoors.java @@ -0,0 +1,16 @@ +import java.util.Random; + +public enum EnumerateDoors { + threeDoors, + fourDoors, + fiveDoors; + + private static Random rnd = new Random(); + + public static EnumerateDoors getRandomValue(){ + int rez = rnd.nextInt(3); + if (rez == 0) return EnumerateDoors.threeDoors; + else if (rez == 1) return EnumerateDoors.fourDoors; + return EnumerateDoors.fiveDoors; + } +} \ No newline at end of file diff --git a/AccordionBus/src/Main.java b/AccordionBus/src/Main.java index 1d70cc0..64e9660 100644 --- a/AccordionBus/src/Main.java +++ b/AccordionBus/src/Main.java @@ -1,6 +1,6 @@ public class Main { public static void main(String[] args) { - + AccordionBus form = new AccordionBus(); } } \ No newline at end of file diff --git a/AccordionBus/src/Resources/buttDown.png b/AccordionBus/src/Resources/buttDown.png new file mode 100644 index 0000000000000000000000000000000000000000..5b5eb7cb654c15d86c69ec196e1f668d065f1a46 GIT binary patch literal 662 zcmV;H0%`q;P)pHNJ&INRA_3n2u{0X}}402SUsUJY*{uZGW1 zfjQ^O_E3u?S&y{aZN@o|A01?yYPCw0o-yGG#+de*&1SLPVzDsVdh@_K4u?Z;GD-hl zuZN{0_;)}jB!>!tUWTH&q>K(u-omdHrmNfF-fzG zLo!D&Wr&ZT3RWS@L_Ha1ZjchfN!6Zh%-`CpO+H19%H9mw3*@mdA zi&QaO>$gldL>*BbsicoDNH;{An2?7vqmW9aq9vt+P7GEAG&lG>;`#-tZW^KaQD=4t z?)Q7D?R-8v#UMSi%U@zToq_`w3WZc#v)KguZ?{_|2OU7yLEUbbolYlk&>smrhi0i% zV%O`{ZVwS62gZ-E~j-H6R*?7R literal 0 HcmV?d00001 diff --git a/AccordionBus/src/Resources/buttLeft.png b/AccordionBus/src/Resources/buttLeft.png new file mode 100644 index 0000000000000000000000000000000000000000..fe44c5c8f595de2063719f9c22c58418f2ea36ff GIT binary patch literal 684 zcmV;d0#p5oP)pHUP(kjRA_Gb2>WHJFn1Vn_~t^~up}=cLa*0L^g-t35)s(} zhX76=-AwGOq{F{S*=z^!?|4U{yUV2;c#eeqfK^Of`zC|6o0z+Z*yk1 z3fXKniT@{!41S#k(>zHSkH=Oa)~Tf<9b>=WL$z8ZweAxG4*<#)4UO+sRiJ_-*WA%vsEY*;CMW0+ZiL`O8^m}R4RG()xjhJfN=TnHU}%& zz&zZ2AbyI!zVzzk7)tJBp&{8xgOIXQf}IQt=-Y(lwp|pnT(ypY?iuZ?{}7 zjcwDyYicFICnA|l25z?-hkL&3Aay(*{V_DySKUyAb@)4H_TPe!kXOUo2>B1=a8L;J SI7hAk0000pHV@X6oRA_O!$&^ru9YR7PN!b_I3mJgu~2f5b=g!TOAu=I;c}2G z@(dGlZkx)GjI`TrB~d73Iie^c#gL3_w_5-J7!HRFSv<_=a{vIiTrQ;c#xe4&F6GKi z9wRO$(nYUUt69a_aB3@3tybZ5I$0x2opMtqXUkj=;+pLx(}GFD_f9+OCHku?*?u~y_}voYq&9V4cG8LDC? zzP#sevu8INNs>f)Ki&DcT&kQZtX3(~T@B=zIu@C|VgMm%B7NgO~sp^0C5IZI6cDoNkSO?EiT&vaMzZ74yi|R^}pHUP(kjRA_sjy?97~VvX5*w3K0?B0N#HKaD}gtXT#UXv*9PN z!b+*c>v=7b&WxCZ+u}UWgVX8cgg^7pQc4+3ESF0_L_kEC&*yjT=kwW`&(a}%AQp>7 zI2;Z)*SMv017R4#cDt3xkr~kiWF7Y|>amAboOCjoIGMbN2;=cMk%O#@(<5<$yjCA6 z2f0TcVM4FX=^2s{-}e)VD3Gj5agJ)WO3EP_+3)uN05F|SS%TsQxMsTDE&u?mRx27; z+8mJ%sm*2sQ54-=J06cvC=|#wINW3-S)UP9K~jF}(2_oJZF$m~K@iwEZ9O9C4ShJo zYelG4oRt0y8fpOnRraSUMKTdHK73jfB=At#ljSF z7h9=RjBPr6-#51D7!HT2vBt^Hndr7yX&X1z$r~a?h|9brq)ztPZ03wiihjSJ8k0J- z0J7aV>CS+w#n>Y*yWJIRn%?GI>obga-e0rp?F0uG?l27Pai+~=d=P83D3Uawuy%fDEq7Jk)_p*r#sY{F-3<6jA1BhQAnG4cyud=9`a SWO9)J0000 Date: Mon, 22 Apr 2024 15:19:27 +0400 Subject: [PATCH 2/2] =?UTF-8?q?=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AccordionBus/src/AccordionBus.form | 2 +- AccordionBus/src/DrawningAccordionBus.java | 63 ++++++---------------- AccordionBus/src/DrawningDoors.java | 54 +++++++++++++++++++ 3 files changed, 71 insertions(+), 48 deletions(-) create mode 100644 AccordionBus/src/DrawningDoors.java diff --git a/AccordionBus/src/AccordionBus.form b/AccordionBus/src/AccordionBus.form index cdce57d..5505ed7 100644 --- a/AccordionBus/src/AccordionBus.form +++ b/AccordionBus/src/AccordionBus.form @@ -3,7 +3,7 @@ - + diff --git a/AccordionBus/src/DrawningAccordionBus.java b/AccordionBus/src/DrawningAccordionBus.java index 9a4e7f8..1f267ac 100644 --- a/AccordionBus/src/DrawningAccordionBus.java +++ b/AccordionBus/src/DrawningAccordionBus.java @@ -1,8 +1,13 @@ import java.awt.*; +import java.util.Random; public class DrawningAccordionBus { private EntityAccordionBus entityAccordionBus; + DrawningDoors drawningDoors = new DrawningDoors(); + + Random rnd = new Random(); + public EntityAccordionBus getEntityAccordionBus(){return entityAccordionBus;} private Integer pictureWidth; @@ -69,19 +74,19 @@ public class DrawningAccordionBus { switch (direction){ case Left: if (startPosX - step > 0) startPosX -= (int)step; - else startPosX = 0; + else startPosX = 10; return true; case Right: - if (startPosX + drawingBusWidth + step < pictureWidth - heightCap) startPosX += (int)step; - else startPosX = pictureWidth - drawingBusWidth; + if (startPosX + drawingBusWidth + step < pictureWidth) startPosX += (int)step; + else startPosX = pictureWidth - drawingBusWidth + 8; return true; case Up: if (startPosY - step > heightCap) startPosY -= (int)step; else startPosY = heightCap; return true; case Down: - if (startPosY + drawingBusHeight < pictureHeight) startPosY += (int)step; - else startPosY = pictureHeight - drawingBusHeight; + if (startPosY + drawingBusHeight + step < pictureHeight + heightCap) startPosY += (int)step; + else startPosY = pictureHeight - drawingBusHeight + heightCap + 10; return true; default: return false; @@ -93,11 +98,11 @@ public class DrawningAccordionBus { //корпус g.setColor(entityAccordionBus.getBodyColor()); - g.fillRect(startPosX.intValue(), startPosY.intValue() + 10, 60, 15); - g.fillRect(startPosX.intValue() + 70, startPosY.intValue() + 10, 60, 15); + g.fillRect(startPosX, startPosY + 10, 60, 15); + g.fillRect(startPosX + 70, startPosY + 10, 60, 15); g.setColor(Color.black); - g.drawRect(startPosX.intValue() + 70, startPosY.intValue() + 10, 60, 15); - g.drawRect(startPosX.intValue(), startPosY.intValue() + 10, 60, 15); + g.drawRect(startPosX + 70, startPosY + 10, 60, 15); + g.drawRect(startPosX, startPosY + 10, 60, 15); //доп. линия if (entityAccordionBus.getAdditionalLine()){ @@ -175,43 +180,7 @@ public class DrawningAccordionBus { } //двери - switch(entityAccordionBus.getEnumerateDoors()){ - case threeDoors: - g.setColor(entityAccordionBus.getAdditionalColor()); - g.fillRect(startPosX + 20, startPosY + 15, 5, 10); - g.fillRect(startPosX + 123, startPosY + 15, 5, 10); - g.fillRect(startPosX + 87, startPosY + 15, 5, 10); - g.setColor(Color.black); - g.drawRect(startPosX + 20, startPosY + 15, 5, 10); - g.drawRect(startPosX + 123, startPosY + 15, 5, 10); - g.drawRect(startPosX + 87, startPosY + 15, 5, 10); - break; - case fourDoors: - g.setColor(entityAccordionBus.getAdditionalColor()); - g.fillRect(startPosX + 20, startPosY + 15, 5, 10); - g.fillRect(startPosX + 123, startPosY + 15, 5, 10); - g.fillRect(startPosX + 87, startPosY + 15, 5, 10); - g.fillRect(startPosX + 53, startPosY + 15, 5, 10); - g.setColor(Color.black); - g.drawRect(startPosX + 20, startPosY + 15, 5, 10); - g.drawRect(startPosX + 123, startPosY + 15, 5, 10); - g.drawRect(startPosX + 87, startPosY + 15, 5, 10); - g.drawRect(startPosX + 53, startPosY + 15, 5, 10); - break; - case fiveDoors: - g.setColor(entityAccordionBus.getAdditionalColor()); - g.fillRect(startPosX + 20, startPosY + 15, 5, 10); - g.fillRect(startPosX + 123, startPosY + 15, 5, 10); - g.fillRect(startPosX + 87, startPosY + 15, 5, 10); - g.fillRect(startPosX + 53, startPosY + 15, 5, 10); - g.fillRect(startPosX + 27, startPosY + 19, 11, 5); - g.setColor(Color.black); - g.drawRect(startPosX + 20, startPosY + 15, 5, 10); - g.drawRect(startPosX + 123, startPosY + 15, 5, 10); - g.drawRect(startPosX + 87, startPosY + 15, 5, 10); - g.drawRect(startPosX + 53, startPosY + 15, 5, 10); - g.drawRect(startPosX + 27, startPosY + 19, 11, 5); - break; - } + drawningDoors.setEnumer((int)rnd.nextInt(3) + 3); + drawningDoors.paintDoors(startPosX, startPosY, g, entityAccordionBus.getAdditionalColor()); } } \ No newline at end of file diff --git a/AccordionBus/src/DrawningDoors.java b/AccordionBus/src/DrawningDoors.java new file mode 100644 index 0000000..87bc485 --- /dev/null +++ b/AccordionBus/src/DrawningDoors.java @@ -0,0 +1,54 @@ +import java.awt.*; + +public class DrawningDoors { + private EnumerateDoors enumer; + + public void setEnumer(int value){ + if (value == 3) enumer = EnumerateDoors.threeDoors; + if (value == 4) enumer = EnumerateDoors.fourDoors; + if (value == 5) enumer = EnumerateDoors.fiveDoors; + } + + public boolean paintDoors(int startPosX, int startPosY, Graphics g, Color color){ + if (enumer == null) return false; + switch(enumer){ + case threeDoors: + g.setColor(color); + g.fillRect(startPosX + 20, startPosY + 15, 5, 10); + g.fillRect(startPosX + 123, startPosY + 15, 5, 10); + g.fillRect(startPosX + 87, startPosY + 15, 5, 10); + g.setColor(Color.black); + g.drawRect(startPosX + 20, startPosY + 15, 5, 10); + g.drawRect(startPosX + 123, startPosY + 15, 5, 10); + g.drawRect(startPosX + 87, startPosY + 15, 5, 10); + break; + case fourDoors: + g.setColor(color); + g.fillRect(startPosX + 20, startPosY + 15, 5, 10); + g.fillRect(startPosX + 123, startPosY + 15, 5, 10); + g.fillRect(startPosX + 87, startPosY + 15, 5, 10); + g.fillRect(startPosX + 53, startPosY + 15, 5, 10); + g.setColor(Color.black); + g.drawRect(startPosX + 20, startPosY + 15, 5, 10); + g.drawRect(startPosX + 123, startPosY + 15, 5, 10); + g.drawRect(startPosX + 87, startPosY + 15, 5, 10); + g.drawRect(startPosX + 53, startPosY + 15, 5, 10); + break; + case fiveDoors: + g.setColor(color); + g.fillRect(startPosX + 20, startPosY + 15, 5, 10); + g.fillRect(startPosX + 123, startPosY + 15, 5, 10); + g.fillRect(startPosX + 87, startPosY + 15, 5, 10); + g.fillRect(startPosX + 53, startPosY + 15, 5, 10); + g.fillRect(startPosX + 27, startPosY + 19, 11, 5); + g.setColor(Color.black); + g.drawRect(startPosX + 20, startPosY + 15, 5, 10); + g.drawRect(startPosX + 123, startPosY + 15, 5, 10); + g.drawRect(startPosX + 87, startPosY + 15, 5, 10); + g.drawRect(startPosX + 53, startPosY + 15, 5, 10); + g.drawRect(startPosX + 27, startPosY + 19, 11, 5); + break; + } + return true; + } +} -- 2.25.1