From 2894298cd557ce8ea36f361436524e5d0ca731f9 Mon Sep 17 00:00:00 2001 From: ENDORFIT Date: Sat, 6 Apr 2024 21:31:39 +0400 Subject: [PATCH] =?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 --- ProjectMonorail/.gitignore | 29 +++ ProjectMonorail/.idea/.gitignore | 8 + ProjectMonorail/.idea/misc.xml | 6 + ProjectMonorail/.idea/modules.xml | 8 + ProjectMonorail/.idea/uiDesigner.xml | 124 +++++++++ ProjectMonorail/ProjectMonorail.iml | 11 + ProjectMonorail/Resource/Arrows/ArrowDown.png | Bin 0 -> 2001 bytes ProjectMonorail/Resource/Arrows/ArrowLeft.png | Bin 0 -> 1981 bytes .../Resource/Arrows/ArrowRight.png | Bin 0 -> 1970 bytes ProjectMonorail/Resource/Arrows/ArrowUp.png | Bin 0 -> 1986 bytes ProjectMonorail/src/CountWheels.java | 12 + ProjectMonorail/src/DirectionType.java | 6 + ProjectMonorail/src/DrawingField.java | 58 +++++ .../src/DrawingModernMonorail.java | 236 ++++++++++++++++++ ProjectMonorail/src/DrawingWheels.java | 26 ++ ProjectMonorail/src/EntityModernMonorail.java | 38 +++ ProjectMonorail/src/FormModernMonorail.java | 127 ++++++++++ ProjectMonorail/src/Program.java | 5 + 18 files changed, 694 insertions(+) create mode 100644 ProjectMonorail/.gitignore create mode 100644 ProjectMonorail/.idea/.gitignore create mode 100644 ProjectMonorail/.idea/misc.xml create mode 100644 ProjectMonorail/.idea/modules.xml create mode 100644 ProjectMonorail/.idea/uiDesigner.xml create mode 100644 ProjectMonorail/ProjectMonorail.iml create mode 100644 ProjectMonorail/Resource/Arrows/ArrowDown.png create mode 100644 ProjectMonorail/Resource/Arrows/ArrowLeft.png create mode 100644 ProjectMonorail/Resource/Arrows/ArrowRight.png create mode 100644 ProjectMonorail/Resource/Arrows/ArrowUp.png create mode 100644 ProjectMonorail/src/CountWheels.java create mode 100644 ProjectMonorail/src/DirectionType.java create mode 100644 ProjectMonorail/src/DrawingField.java create mode 100644 ProjectMonorail/src/DrawingModernMonorail.java create mode 100644 ProjectMonorail/src/DrawingWheels.java create mode 100644 ProjectMonorail/src/EntityModernMonorail.java create mode 100644 ProjectMonorail/src/FormModernMonorail.java create mode 100644 ProjectMonorail/src/Program.java diff --git a/ProjectMonorail/.gitignore b/ProjectMonorail/.gitignore new file mode 100644 index 0000000..f68d109 --- /dev/null +++ b/ProjectMonorail/.gitignore @@ -0,0 +1,29 @@ +### IntelliJ IDEA ### +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/ProjectMonorail/.idea/.gitignore b/ProjectMonorail/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/ProjectMonorail/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/ProjectMonorail/.idea/misc.xml b/ProjectMonorail/.idea/misc.xml new file mode 100644 index 0000000..69ace3f --- /dev/null +++ b/ProjectMonorail/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/ProjectMonorail/.idea/modules.xml b/ProjectMonorail/.idea/modules.xml new file mode 100644 index 0000000..8a2f0e7 --- /dev/null +++ b/ProjectMonorail/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/ProjectMonorail/.idea/uiDesigner.xml b/ProjectMonorail/.idea/uiDesigner.xml new file mode 100644 index 0000000..2b63946 --- /dev/null +++ b/ProjectMonorail/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ProjectMonorail/ProjectMonorail.iml b/ProjectMonorail/ProjectMonorail.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/ProjectMonorail/ProjectMonorail.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/ProjectMonorail/Resource/Arrows/ArrowDown.png b/ProjectMonorail/Resource/Arrows/ArrowDown.png new file mode 100644 index 0000000000000000000000000000000000000000..271d5b42c28358202fdcb547ec49379358890a7e GIT binary patch literal 2001 zcmbVNdr;GM98awxAh#}jF$okn9pDq3 zkE!Qln;z(1G92FKZ5+oq>iK|Ek8Mt6>NeQ?W8SGCb9y_ObHDQFsi)g*xup5!_xpTb zpYNl!*;yHp;V*_m5EN<6H0OYKeBcQU0l%}6rb7@UNu^DuY$M6KC^#o$K0HIC*Qd>d zpcy-MZ*RAq$ey&RJiPXZkA6y*Lr)J@Y7;)PNvAnmi1d#=9j4cT*5 z4Ov%`WsBxD>>Z5D4(A_2wljBE%T`uh77Phn^!^BbrDWmM6~$FccTT)e(C;|=2~}{u z?-k?p?c?9s)}?Dn*i>tazWD9p*v@{bQE?wx{T0yNru=0 zW7$DfmuyGuoQW!;Gb?y1w<60yR1_0>QZaW9oL+_j1zt+T;WDp>5wJ3YVn{Cr)`4xc z0v>{h#RkQ2Li6p}u!-d}=MtwxQYY7MGH5KO1XP!t}y z6u=x$y0IMdf)Qij%b+L{MGjM|eLkPcr&F}cWrPu)0AuPhoKtI5NFb&mAV~yqTnX@!pcj~_DtxV77ZHlFH>*Bdk;h?Y_i#t0!#MGKB{j#B4P z0$aipl%*87IV}(khnaW^7g^rHvYydQWskZHYqcsAo{>j0Bj^Yw zpmeZIS^!BcAL*Q2YSqZfL&HPWg5gA<3k(V(kbVk8FuYCwZw7|teMJ;d`VVC>3=>$l z=)-x+SP0k}&Brs#P7Rz_2l{n54)v2E4xK&H+oNzWFapcqr~)6sVMj4w!tr2~^>`RC z2qp1Wv(b@Rd#l@ElNu-a2OgRygnho|Hneu@+cw#xw(1SdHO^a+N$Z!xmTgh8lX3D+ z$=Il?@YOS~eHMD6@4cfxTF>8Hr@S}t)1Uha_H@Xj@Pt)|U*4)&dOuP={?Z`Sbi?Wu zX5FlbuCF;P8XO0INjPcN)q*4u5X zlXg_!wK?gwSbu9xIy%ep!2lHN=-6|u#Su9^g4-);^D$jg={c-k=x+#dR(&0FJ@2-# z!2hwb_t+G~KV7osNUE<|5)*a3@zVD%%sF)b=!&ASh-Qg&d3kSKUhYJBZ-H^;>c|%7 zVJ70?^;wSn(eVY`?R)i;XXeRgzgd;o3;n?y^M_Ef!E2l9a&>`!467x}+%(_0_HXO6 Bx;y{? literal 0 HcmV?d00001 diff --git a/ProjectMonorail/Resource/Arrows/ArrowLeft.png b/ProjectMonorail/Resource/Arrows/ArrowLeft.png new file mode 100644 index 0000000000000000000000000000000000000000..313d764af6de2716a563bb27b561e46f20950674 GIT binary patch literal 1981 zcmbVNdrT8|96yR6A~L2MpiDWBO>x@Z^U!=5}YbW$h;LF23`mJIMeMSenp!S5Wb;Zq0-FfeAbBaz}3@*|eIaE%w&uIKvyVzOu}4w^<8qo~=&74RJ6byHg4Lrg9z3ur;*GL8 z`}NroX$$IhKZBv0gEQD$S+&EJ-jQs&w1e}o!xnN zTH?FgMt@RuNqaJOV`b`u?jO^m&i4i8sAD~b$tM?o{lzx}rGJ~=?CGc31IZx^W|^Y0 z6MeO+(vPC&?D)-fj-MFbN0d0JW&?jBVC;#c<4ZT(i<}!?3bme1d(xjd|2$xF44;xM zLeSU=@)H2<-4_i(L6M9zOUkk>!b#4nB4mD5J}(c@5Hxqbk0;1{T7q44F2kCTzUCGL zW+)S~WVQ{n@n$-YNhuNN%o4kkEXgO06f%DvJlBT<1zuVrV4v5+inz~&4C=+fTHZzx zcn~7xn~QD?`-mjJwhj{{wp+15~)hbMmX%I+}ejHyQcm|DABuaZ| zFU?9Kz^eUNK97?)F^_wNYX9+b1^~AiF1a8L3(eSugpb3c+oE+yF$&_QnWmuz8>EQS!3`=oE;*4hmXbU0HCIn;+*YD(RihFNr#o4J<&U@Bfv!2u(xSHyjgDjl5`or|t@%qZq7t8kEfu{9#$H1+P zGgc|m-hRLJ^KlP?u38)cSCZP>M@1iRJaz0)U3Ym*9d|^4D8i&gUt{abZOaXuFr|D+Lg%;g*TI@(w=^uwS@#bqBeMtq literal 0 HcmV?d00001 diff --git a/ProjectMonorail/Resource/Arrows/ArrowRight.png b/ProjectMonorail/Resource/Arrows/ArrowRight.png new file mode 100644 index 0000000000000000000000000000000000000000..bbee88ea051de06fd4013049b63b7a785542aa84 GIT binary patch literal 1970 zcmbVN3s4kg9N!Z`1Rv*PL`7s>oP?3P-8;@ZZuL~SBRKN#fKxfG(Y@X8j*YwBb$5Y- zG#D};X)?k%Y2}!e6p?5(zJ?4%MMv}f%5oB|sVPQL(Pj$MzU6VFj@IPPKEB8A`#*mF z$F6ebWDbrR8-*aqV0)G=4}QlhPhL)s56^WlMp0v z-TLb0?1RpcE1F|74sV$odA&`Tl56qmi4T$NWA~P*7gk=DEb(j1`v-{&RkPw=DXN@bGvvIx!*%>K;68iv zg|vy)12(QbnX)&2#j5NP7tZ9y9PJ2Oq>J~P;`Ywn`T4$k6%Q=KE_DKKb7thsWJ`=Y zEx1KnF=zDD+IG(oVa$*Ys@%minS|Y{=-nB+=D&Go)U+WL$o|&Ze|P53I0~5@C}g=M z1c@G@JSybf_eUd0_$by@AQw1hku)FBQVPG?U_gLq1erD?C{T0}kWmltv780#Xllk# zma$;-rZ@rGr!$}E!5^O-C zMOKhmo}a_ew}bUf9TKp><-k~2!68@+@)6)m~S1c2uOi7ysu zkWm87Oi;WLNUI1anHOC=@9&G0v(IEyuh$yT#Ca^o@TF4HBL{$ul7R(-QG@YFp`A+F(}L#hLWlO1T!@0<;4I69cBZR58wjl!_W|o zq?PycB2)~mOL=tN4m*p;ds#o+c(TKETkCL;c21Hhjs|v{1%upZS(YL7CL{2s7=gxU zG*KE8ZO~~blh>;uQuQ=Vq#C_O!qj)(#?!@02K1e0{^$AGA`459@;|p6r7)G$A+uNs z2DPlWa`M6A-jSb0yR(I)Xr&4)7_EdKFj((0``irlh%GGyQ0Tv;MGs8ky>clff;1mw zt1lkUOgkJJk1O@s;|Knvi`{#V)OH^nHVkDLYE^I&YIcBw9ZrO;Y)nbmI@ksu+HGmB ztW`HI>aq_x)e&v@_3)7+SBFnNwPkMAO3&W)RomVUhQ-EGnq>dJ%2DO&GcP43emX$# ze>vRX{>pAlx)L9eKK|g5gldx=OOM(3n{89ewz^-g{r=O(HSQ79XSPL1ftDYV#syov z3vSJi7=O_{CTLuGb3#3`{pYWzwvvC`PR%ZQK4iF}K3Y11;OXJJHozYvaF2tWCbJn{YQP2TLD5tY)Iy_+aHAf1BQS zL-pDoysG`j3k|P#+_}HKuI`g_(Iv+WQ_R&JJDj`f2kxmpxA?tphR%!mv!Y^S{+^vn YRQ(NsXx3VLUil^1GjeQ=>5HoV0bbUw(f|Me literal 0 HcmV?d00001 diff --git a/ProjectMonorail/Resource/Arrows/ArrowUp.png b/ProjectMonorail/Resource/Arrows/ArrowUp.png new file mode 100644 index 0000000000000000000000000000000000000000..0812cc2ad4f4625737d7e50b175a242268d5c87d GIT binary patch literal 1986 zcmbVN3s4kg9AA8a_@XR99hj-lS#p90Pkb@IW1*L(#-91>i+g)}S?qF0v z3!@kxl%rBUs4*iGr!ik)0hMCXm}$o7FoV%F(lm;Oj+G{T%i~5Jt;wBzeEWUB@BjGy zA78C4J$XuCXdnbZQ!FXwOz@p0KLHcKdlA|6+n z*|K$0YwB0F=Qgy4C7oiVJj*s${uQ*5jmYg@ zGbTE@J>llW)niXKtv9_odHkC_w|4dz!q57>@95fDv$SR)dwk@W-FuuDox2rfYy^cP9tLFE9q@ zBzPN@mCHgFz4e=;gP%FIpQx}?EqeZ_-=w2SM^?V}`;5g?E1|Yi8GjFC#hnIBPUKT^ zL?MK6jP&WwE`d%VmT`jUIi;gjY=@n zA}KJu#BeMuOC%gzsboZeslz_Fd7oHT9N`HthI$DeRVgvqry(Fk`fz-y;2Kg+ktpq= z-83tS0ITw0`9e?%F3!Ekl#d`ydD*f7+}QH-DhKZb0@(==@ zPypB(jmHzy4h6=ea=i}wfj;Wu(AopFJqia6Lmv8C75MQrJDLR@P5`Z}+FrO8oIKMk z<^+36?X|8?ioT2w@3`5&14(R@ib{fWbC>wH>-&1U{rSFbeN1mu>>nZPGT^d48{aoa z>dT!c6&tqQn>}anLgz2NZ%5v%2_NjfnphJ=9(W;=Oe3t{Xf{I^veq|LA3kE+)D7v} zUH;0D>Km&jtc?r4SD&!=&}Tn2u1ifWZFgU}8*suOFKz3L`cQg4Y?pV>`F+{^!Ey7h zbyRu$ZWJu@&ZW=*a0)9~oQtRHg^?Q`B=+Dg literal 0 HcmV?d00001 diff --git a/ProjectMonorail/src/CountWheels.java b/ProjectMonorail/src/CountWheels.java new file mode 100644 index 0000000..1e14a19 --- /dev/null +++ b/ProjectMonorail/src/CountWheels.java @@ -0,0 +1,12 @@ +public enum CountWheels { + Two(2), + Three(3), + Four(4); + private final int Value; + CountWheels(int Count){ + Value=Count; + } + public int getCountWheels(){ + return Value; + } +} diff --git a/ProjectMonorail/src/DirectionType.java b/ProjectMonorail/src/DirectionType.java new file mode 100644 index 0000000..b6f4136 --- /dev/null +++ b/ProjectMonorail/src/DirectionType.java @@ -0,0 +1,6 @@ +public enum DirectionType { + Up, + Down, + Left, + Right; +} diff --git a/ProjectMonorail/src/DrawingField.java b/ProjectMonorail/src/DrawingField.java new file mode 100644 index 0000000..1ff7a05 --- /dev/null +++ b/ProjectMonorail/src/DrawingField.java @@ -0,0 +1,58 @@ +import javax.swing.*; +import java.awt.*; +import java.util.Random; + +public class DrawingField extends JPanel { + private final FormModernMonorail field; + DrawingModernMonorail _monorail; + public DrawingField(FormModernMonorail field) { + this.field = field; + } + + @Override + protected void paintComponent(Graphics g) { + super.paintComponent(g); + Graphics2D g2 =(Graphics2D)g; + if (_monorail !=null) + _monorail.DrawTransport(g2); + else return; + } + + public void UpButtonAction(){ + if (_monorail !=null) + _monorail.MoveTransport(DirectionType.Up); + return; + } + + public void DownButtonAction(){ + if (_monorail !=null) + _monorail.MoveTransport(DirectionType.Down); + return; + } + + public void RightButtonAction(){ + if (_monorail !=null) + _monorail.MoveTransport(DirectionType.Right); + return; + } + + public void LeftButtonAction(){ + if (_monorail !=null) + _monorail.MoveTransport(DirectionType.Left); + return; + } + + public void CreateButtonAction(){ + Random rnd=new Random(); + _monorail =new DrawingModernMonorail(); + _monorail.SetPictureSize(getWidth(),getHeight()); + _monorail.Initialization(rnd.nextInt(50)+10,rnd.nextInt(100)+500,new Color(rnd.nextInt(256),rnd.nextInt(256),rnd.nextInt(256)), new Color(rnd.nextInt(256),rnd.nextInt(256),rnd.nextInt(256)), rnd.nextBoolean(), rnd.nextBoolean()); + _monorail.SetPosition(rnd.nextInt(100)+10,rnd.nextInt(100)+10,getWidth(),getHeight()); + } + + public void ResizeField(){ + if (_monorail !=null) + _monorail.SetPictureSize(getWidth(),getHeight()); + else return; + } +} diff --git a/ProjectMonorail/src/DrawingModernMonorail.java b/ProjectMonorail/src/DrawingModernMonorail.java new file mode 100644 index 0000000..c564e94 --- /dev/null +++ b/ProjectMonorail/src/DrawingModernMonorail.java @@ -0,0 +1,236 @@ +import java.awt.*; +import java.util.Random; + +public class DrawingModernMonorail { + private EntityModernMonorail _entityMonorail; + private DrawingWheels _wheels; + + private Integer _pictureWidth = null; + private Integer _pictureHeight = null; + + private int _startPositionX; + private int _startPositionY; + + private int _drawningMonorailWidth = 160; + private final int _drawningMonorailHeight = 55; + + public EntityModernMonorail getMonorail() {return _entityMonorail;} + public DrawingWheels getWheels() {return _wheels;} + + public void Initialization(int speed, float weight, Color bodyColor, Color additionalColor, boolean monorailTrack, boolean cabin) + { + _entityMonorail = new EntityModernMonorail(); + _entityMonorail.Initialization(speed, weight, bodyColor, additionalColor, monorailTrack, cabin); + _wheels = new DrawingWheels(); + Random rnd = new Random(); + _wheels.SetCountWheels(2 + rnd.nextInt(0, 3)); + } + + public boolean SetPictureSize(int width, int height) + { + if (_drawningMonorailWidth > width || _drawningMonorailHeight > height) return false; + + if (_startPositionX >= 0 && _startPositionY >= 0) + { + if (_startPositionX + _drawningMonorailWidth > width) + { + _startPositionX = width - _drawningMonorailWidth; + } + if (_startPositionY + _drawningMonorailHeight > height) + { + _startPositionY = height - _drawningMonorailHeight; + } + } + + _pictureWidth = width; + _pictureHeight = height; + return true; + } + + public void SetPosition(int x, int y, int width, int height) + { + if (_pictureHeight == null || _pictureWidth == null) return; + + if (x + _drawningMonorailWidth > _pictureWidth || x < 0) + { + _startPositionX = (int)Math.random() * (_pictureWidth - _drawningMonorailWidth); + } + else + { + _startPositionX = x; + } + + if (y + _drawningMonorailHeight > _pictureHeight || y < 0) + { + _startPositionY = (int)Math.random() * (_pictureHeight - _drawningMonorailHeight); + } + else + { + _startPositionY = y; + } + } + + public boolean MoveTransport(DirectionType direction) + { + if (_pictureWidth == null || _pictureHeight == null) return false; + + switch (direction) + { + case Right: + if (_startPositionX + _drawningMonorailWidth + _entityMonorail.Step < _pictureWidth) + { + _startPositionX += _entityMonorail.Step; + } + return true; + case Left: + if (_startPositionX - _entityMonorail.Step >= 0) + { + _startPositionX -= _entityMonorail.Step; + } + return true; + case Up: + if (_startPositionY - _entityMonorail.Step >= 0) + { + _startPositionY -= _entityMonorail.Step; + } + return true; + case Down: + if (_startPositionY + _drawningMonorailHeight + _entityMonorail.Step < _pictureHeight) + { + _startPositionY += _entityMonorail.Step; + } + return true; + default: + return false; + } + } + + public void DrawTransport(Graphics g) + { + if (_startPositionX < 0 || _startPositionY < 0 || _pictureHeight== null || _pictureWidth== null) return; + + Graphics2D g2 = (Graphics2D) g; + g.setColor(_entityMonorail.getBodyColor()); + + //Кузов монорельса + g.drawLine(_startPositionX + 8, _startPositionY + 10, _startPositionX + 13, _startPositionY); + g.drawLine(_startPositionX + 13, _startPositionY, _startPositionX + 80, _startPositionY); + g.drawLine(_startPositionX + 80, _startPositionY, _startPositionX + 80, _startPositionY + 25); + g.drawLine(_startPositionX + 80, _startPositionY + 25, _startPositionX + 8, _startPositionY + 25); + g.drawLine(_startPositionX + 8, _startPositionY + 25, _startPositionX + 8, _startPositionY + 10); + g.drawLine(_startPositionX + 8, _startPositionY + 10, _startPositionX + 30, _startPositionY + 10); + g.drawLine(_startPositionX + 39, _startPositionY + 10, _startPositionX + 80, _startPositionY + 10); + + //Дверь + g.drawRect(_startPositionX + 30, _startPositionY + 5, 9, 15); + + //Окна + g.setColor(_entityMonorail.getAdditionalColor()); + g.drawRect(_startPositionX + 14, _startPositionY + 2, 5, 6); + g.drawRect(_startPositionX + 21, _startPositionY + 2, 5, 6); + g.drawRect(_startPositionX + 70, _startPositionY + 2, 5, 6); + + //Связка монорельса + g.setColor(_entityMonorail.getBodyColor()); + g.fillRect(_startPositionX + 80, _startPositionY + 2, 7, 22); + + //Нижняя часть монорельса + int xPoly_LeftSide[] = {_startPositionX, _startPositionX + 8, _startPositionX + 72, _startPositionX + 36, _startPositionX + 36, _startPositionX + 15, _startPositionX + 15, _startPositionX}; + int yPoly_LeftSide[] = {_startPositionY + 30, _startPositionY + 25, _startPositionY + 25, _startPositionY + 25, _startPositionY + 32, _startPositionY + 32, _startPositionY + 35, _startPositionY + 32}; + g.fillPolygon(xPoly_LeftSide, yPoly_LeftSide, xPoly_LeftSide.length); + + int xPoly_RightSide[] = {_startPositionX + 86, _startPositionX + 80, _startPositionX + 50, _startPositionX + 50, _startPositionX + 69, _startPositionX + 79, _startPositionX + 86}; + int yPoly_RightSide[] = {_startPositionY + 30, _startPositionY + 25, _startPositionY + 25, _startPositionY + 32, _startPositionY + 32, _startPositionY + 35, _startPositionY + 32}; + g.fillPolygon(xPoly_RightSide, yPoly_RightSide, xPoly_RightSide.length); + + g.fillRect(_startPositionX + 8, _startPositionY + 25, 70, 3); + + if (_entityMonorail.getMonorailTrack()) { + if (_entityMonorail.getCabin()) { + g.fillRect(_startPositionX, _startPositionY + 35, 170, 5); + } + else { + g.fillRect(_startPositionX, _startPositionY + 35, 86, 5); + } + } + + //Колеса + int[] coordinatesX = new int[_wheels.getCountWheels()]; + coordinatesX[0] = _startPositionX + 10; + coordinatesX[1] = _startPositionX + 65; + + if (coordinatesX.length == 4) { + coordinatesX[2] = _startPositionX + 25; + coordinatesX[3] = _startPositionX + 50; + } + else if (coordinatesX.length == 3) { + Random rnd = new Random(); + if (rnd.nextInt(0, 2) == 1) { + coordinatesX[2] = _startPositionX + 25; + } + else { + coordinatesX[2] = _startPositionX + 50; + } + } + + _wheels.DrawWheels(g2, coordinatesX, _startPositionY + 30, _entityMonorail.getAdditionalColor()); + + if (_entityMonorail.getCabin()) { + int offset = 170; + + //Кузов монорельса + g.drawLine(_startPositionX - 8 + offset, _startPositionY + 10, _startPositionX - 13 + offset, _startPositionY); + g.drawLine(_startPositionX - 13 + offset, _startPositionY, _startPositionX - 80 + offset, _startPositionY); + g.drawLine(_startPositionX - 80 + offset, _startPositionY, _startPositionX - 80 + offset, _startPositionY + 25); + g.drawLine(_startPositionX - 80 + offset, _startPositionY + 25, _startPositionX - 8 + offset, _startPositionY + 25); + g.drawLine(_startPositionX - 8 + offset, _startPositionY + 25, _startPositionX - 8 + offset, _startPositionY + 10); + g.drawLine(_startPositionX - 8 + offset, _startPositionY + 10, _startPositionX - 30 + offset, _startPositionY + 10); + g.drawLine(_startPositionX - 39 + offset, _startPositionY + 10, _startPositionX - 80 + offset, _startPositionY + 10); + + //Дверь + g.drawRect(_startPositionX - 39 + offset, _startPositionY + 5, 9, 15); + + //Окна + g.setColor(_entityMonorail.getAdditionalColor()); + g.drawRect(_startPositionX - 20 + offset, _startPositionY + 2, 5, 6); + g.drawRect(_startPositionX - 27 + offset, _startPositionY + 2, 5, 6); + g.drawRect(_startPositionX - 76 + offset, _startPositionY + 2, 5, 6); + + //Связка монорельса + g.setColor(_entityMonorail.getBodyColor()); + g.fillRect(_startPositionX - 87 + offset, _startPositionY + 2, 7, 22); + + //Нижняя часть монорельса + xPoly_LeftSide = new int[]{_startPositionX + offset, _startPositionX - 8 + offset, _startPositionX - 72 + offset, _startPositionX - 36 + offset, _startPositionX - 36 + offset, _startPositionX - 15 + offset, _startPositionX - 15 + offset, _startPositionX + offset}; + yPoly_LeftSide = new int[] {_startPositionY + 30, _startPositionY + 25, _startPositionY + 25, _startPositionY + 25, _startPositionY + 32, _startPositionY + 32, _startPositionY + 35, _startPositionY + 32}; + g.fillPolygon(xPoly_LeftSide, yPoly_LeftSide, xPoly_LeftSide.length); + + xPoly_RightSide = new int[]{_startPositionX - 86 + offset, _startPositionX - 80 + offset, _startPositionX - 50 + offset, _startPositionX - 50 + offset, _startPositionX - 69 + offset, _startPositionX - 79 + offset, _startPositionX - 86 + offset}; + yPoly_RightSide = new int[] {_startPositionY + 30, _startPositionY + 25, _startPositionY+ 25, _startPositionY + 32, _startPositionY + 32 , _startPositionY + 35, _startPositionY + 32}; + g.fillPolygon(xPoly_RightSide, yPoly_RightSide, xPoly_RightSide.length); + g.fillRect(_startPositionX - 80 + offset, _startPositionY + 25, 70, 3); + + //Колеса + coordinatesX = new int[_wheels.getCountWheels()]; + coordinatesX[0] = _startPositionX - 20 + offset; + coordinatesX[1] = _startPositionX - 75 + offset; + + if (coordinatesX.length == 4) { + coordinatesX[2] = _startPositionX - 35 + offset; + coordinatesX[3] = _startPositionX - 60 + offset; + } + else if (coordinatesX.length == 3) { + Random rnd = new Random(); + if (rnd.nextInt(0, 2) == 1) { + coordinatesX[2] = _startPositionX - 35 + offset; + } + else { + coordinatesX[2] = _startPositionX - 60 + offset; + } + } + + _wheels.DrawWheels(g2, coordinatesX, _startPositionY + 30, _entityMonorail.getAdditionalColor()); + } + + } +} diff --git a/ProjectMonorail/src/DrawingWheels.java b/ProjectMonorail/src/DrawingWheels.java new file mode 100644 index 0000000..6693c95 --- /dev/null +++ b/ProjectMonorail/src/DrawingWheels.java @@ -0,0 +1,26 @@ +import java.awt.*; + +public class DrawingWheels { + + private CountWheels _wheels; + + public void SetCountWheels(int Count){ + for (CountWheels temp: CountWheels.values()) + if (temp.getCountWheels() == Count){ + _wheels=temp; + return; + } + } + + public int getCountWheels() { + return _wheels.getCountWheels(); + } + + public void DrawWheels(Graphics2D g,int startPosX[], int startPosY, Color color) { + g.setColor(color); + for (int i = 0; i < startPosX.length; i++) { + g.drawOval(startPosX[i], startPosY, 10, 10); + g.fillOval(startPosX[i], startPosY, 10, 10); + } + } +} diff --git a/ProjectMonorail/src/EntityModernMonorail.java b/ProjectMonorail/src/EntityModernMonorail.java new file mode 100644 index 0000000..84be183 --- /dev/null +++ b/ProjectMonorail/src/EntityModernMonorail.java @@ -0,0 +1,38 @@ +import java.awt.*; +import java.util.Random; + +public class EntityModernMonorail { + public float Step; + private int _speed; + private float _weight; + private Color _bodyColor; + private Color _additionalColor; + private boolean _monorailTrack; + private boolean _cabin; + + public int getSpeed() { + return _speed; + } + public float getWeight() { + return _weight; + } + public Color getBodyColor() { + return _bodyColor; + } + public Color getAdditionalColor() {return _additionalColor;} + public boolean getMonorailTrack() {return _monorailTrack;} + public boolean getCabin() {return _cabin;} + + public void Initialization(int speed, float weight, Color bodyColor, Color additionalColor, boolean monorailTrack, boolean cabin){ + Random rnd = new Random(); + _speed = speed <= 0 ? rnd.nextInt(50)+10 : speed; + _weight = weight <= 0 ? rnd.nextInt(100)+500 : weight; + _bodyColor = bodyColor; + _additionalColor = additionalColor; + _monorailTrack = monorailTrack; + _cabin = cabin; + + Step = _speed * 100/ (int)_weight; + } +} + diff --git a/ProjectMonorail/src/FormModernMonorail.java b/ProjectMonorail/src/FormModernMonorail.java new file mode 100644 index 0000000..29c88e0 --- /dev/null +++ b/ProjectMonorail/src/FormModernMonorail.java @@ -0,0 +1,127 @@ +import javax.swing.*; +import java.awt.*; +import java.awt.event.ComponentAdapter; +import java.awt.event.ComponentEvent; +public class FormModernMonorail extends JFrame{ + private int Width; + private int Height; + + private JPanel BottomPanel = new JPanel(); + private JPanel CreatePanel = new JPanel(); + private JPanel BottomAndCreatePanel = new JPanel(); + private JPanel DimentionPanel = new JPanel(); + private JPanel UPanel = new JPanel(); + private JPanel DPanel = new JPanel(); + private JPanel LRPanel = new JPanel(); + + private DrawingField field = new DrawingField(this); + + private JButton ButtonCreate=new JButton("Create Monorail"); + + private Icon _iconUp = new ImageIcon("Resource\\Arrows\\ArrowUp.png"); + private Icon _iconDown = new ImageIcon("Resource\\Arrows\\ArrowDown.png"); + private Icon _iconRight = new ImageIcon("Resource\\Arrows\\ArrowRight.png"); + private Icon _iconLeft = new ImageIcon("Resource\\Arrows\\ArrowLeft.png"); + + private JButton ButtonUp=new JButton(_iconUp); + private JButton ButtonDown=new JButton(_iconDown); + private JButton ButtonRight=new JButton(_iconRight); + private JButton ButtonLeft=new JButton(_iconLeft); + + public FormModernMonorail(){ + super("Modern Monorail"); + setSize(600,480); + Width=getWidth(); + Height=getHeight(); + ShowWindow(); + RefreshWindow(); + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setVisible(true); + } + + public void ShowWindow(){ + + Dimension dimen=new Dimension(30,30); + + ButtonUp.setPreferredSize(dimen); + ButtonUp.addActionListener(e->{ + field.UpButtonAction(); + repaint(); + }); + + ButtonDown.setPreferredSize(dimen); + ButtonDown.addActionListener(e->{ + field.DownButtonAction(); + repaint(); + }); + + ButtonRight.setPreferredSize(dimen); + ButtonRight.addActionListener(e->{ + field.RightButtonAction(); + repaint(); + }); + + ButtonLeft.setPreferredSize(dimen); + ButtonLeft.addActionListener(e->{ + field.LeftButtonAction(); + repaint(); + }); + + LRPanel.setLayout(new FlowLayout(FlowLayout.CENTER,50,0)); + LRPanel.setBackground(new Color(0,0,0,0)); + LRPanel.add(ButtonLeft); + LRPanel.add(ButtonRight); + + UPanel.setLayout(new FlowLayout()); + UPanel.setBackground(new Color(0,0,0,0)); + UPanel.add(ButtonUp); + + DPanel.setLayout(new FlowLayout()); + DPanel.setBackground(new Color(0,0,0,0)); + DPanel.add(ButtonDown); + + DimentionPanel.setLayout(new BoxLayout(DimentionPanel,BoxLayout.Y_AXIS)); + DimentionPanel.setBackground(new Color(0,0,0,0)); + DimentionPanel.add(UPanel); + DimentionPanel.add(LRPanel); + DimentionPanel.add(DPanel); + add(DimentionPanel); + + CreatePanel.setLayout(new FlowLayout()); + CreatePanel.setBackground(new Color(0,0,0,0)); + CreatePanel.add(ButtonCreate); + ButtonCreate.addActionListener(e->{ + field.CreateButtonAction(); + repaint(); + }); + + BottomPanel.setLayout(new FlowLayout()); + BottomPanel.setBackground(new Color(0,0,0,0)); + + BottomAndCreatePanel.setLayout(new BoxLayout(BottomAndCreatePanel,BoxLayout.Y_AXIS)); + BottomAndCreatePanel.setBackground(new Color(0,0,0,0)); + BottomAndCreatePanel.add(CreatePanel); + BottomAndCreatePanel.add(BottomPanel); + + add(BottomAndCreatePanel); + add(field); + + addComponentListener(new ComponentAdapter() { + @Override + public void componentResized(ComponentEvent e) { + super.componentResized(e); + Width=getWidth(); + Height=getHeight(); + + field.ResizeField(); + repaint(); + RefreshWindow(); + } + }); + } + public void RefreshWindow(){ + field.setBounds(0,0,Width,Height); + BottomAndCreatePanel.setBounds(-220,Height-110,Width,80); + DimentionPanel.setBounds(Width-170,Height-170,190,140); + } +} diff --git a/ProjectMonorail/src/Program.java b/ProjectMonorail/src/Program.java new file mode 100644 index 0000000..b6da7d7 --- /dev/null +++ b/ProjectMonorail/src/Program.java @@ -0,0 +1,5 @@ +public class Program { + public static void main(String[] args){ + new FormModernMonorail(); + } +}