From 14f32cb3f708866be17876c2aebbd62725777de5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B0=D1=88=D0=B8=D0=BD=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC?= Date: Sat, 22 Oct 2022 16:07:28 +0400 Subject: [PATCH] Full restart --- src/AbstractMap.java | 32 +++-- src/DrawingField.java | 69 +++++----- src/DrawingGasolineTanker.java | 59 +++++++-- src/DrawingImprovedGasolineTanker.java | 50 ++++++++ src/DrawingMap.java | 71 ++++++++++ src/DrawingObjectGasolineTanker.java | 39 ++++++ src/DrawingOrnamentWheelsFirst.java | 54 ++++++++ src/DrawingOrnamentWheelsSecond.java | 55 ++++++++ src/DrawingWheels.java | 51 ++++---- src/EntityGasolineTanker.java | 4 +- src/EntityImprovedGasolineTanker.java | 10 +- src/FormGasolineTanker.form | 160 +++++++++++++++++++++++ src/FormGasolineTanker.java | 166 +++++++++--------------- src/FormMap.form | 171 +++++++++++++++++++++++++ src/FormMap.java | 87 +++++++++++++ src/IDrawingObject.java | 1 + src/IDrawningObjectWheels.java | 6 + src/LongMap.java | 42 +++--- src/Main.java | 6 +- src/OrnamentForm.java | 9 ++ src/SimpleMap.java | 16 +-- 21 files changed, 935 insertions(+), 223 deletions(-) create mode 100644 src/DrawingImprovedGasolineTanker.java create mode 100644 src/DrawingMap.java create mode 100644 src/DrawingObjectGasolineTanker.java create mode 100644 src/DrawingOrnamentWheelsFirst.java create mode 100644 src/DrawingOrnamentWheelsSecond.java create mode 100644 src/FormGasolineTanker.form create mode 100644 src/FormMap.form create mode 100644 src/FormMap.java create mode 100644 src/IDrawningObjectWheels.java create mode 100644 src/OrnamentForm.java diff --git a/src/AbstractMap.java b/src/AbstractMap.java index a895bdd..ea02c9f 100644 --- a/src/AbstractMap.java +++ b/src/AbstractMap.java @@ -10,8 +10,8 @@ public abstract class AbstractMap { protected float _size_x; protected float _size_y; protected final Random _random = new Random(); - protected final int _freeWaterArea = 0; - protected final int _land = 1; + protected final int _freeRoad = 0; + protected final int _barrier = 1; public BufferedImage CreateMap(int width, int height, IDrawingObject drawingObject) { @@ -28,18 +28,16 @@ public abstract class AbstractMap { public BufferedImage MoveObject(Direction direction) { - float[] dim = _drawingObject.GetCurrentPosition(); - - if (CheckLand(dim[0], dim[1], dim[2], dim[3]) != 0) - { - _drawingObject.MoveObject(SetOppositDirection(direction)); - } - if (true) { _drawingObject.MoveObject(direction); } - return DrawMapWithObject(); + float[] cortege = _drawingObject.GetCurrentPosition(); + if (CheckLand(cortege[0],cortege[1],cortege[2],cortege[3])!= 0) + { + _drawingObject.MoveObject(SetOppositDirection(direction)); + } + return DrawMapWithObject(); } private boolean SetObjectOnMap() @@ -88,13 +86,13 @@ public abstract class AbstractMap { { for (int j = 0; j < _map[i].length; ++j) { - if (_map[i][j] == _freeWaterArea) + if (_map[i][j] == _freeRoad) { - DrawWaterPart(gr, i, j); + DrawBarrierPart(gr, i, j); } - else if (_map[i][j] == _land) + else if (_map[i][j] == _barrier) { - DrawLandPart(gr, i, j); + DrawRoadPart(gr, i, j); } } } @@ -116,7 +114,7 @@ public abstract class AbstractMap { { for (int y = RUj; y <= LDj; y++) { - if (_map[x][y] == _land) + if (_map[x][y] == _barrier) { return 1; } @@ -143,6 +141,6 @@ public abstract class AbstractMap { } protected abstract void GenerateMap(); - protected abstract void DrawWaterPart(Graphics gr, int i, int j); - protected abstract void DrawLandPart(Graphics gr, int i, int j); + protected abstract void DrawBarrierPart(Graphics gr, int i, int j); + protected abstract void DrawRoadPart(Graphics gr, int i, int j); } diff --git a/src/DrawingField.java b/src/DrawingField.java index 94df9a6..f92125f 100644 --- a/src/DrawingField.java +++ b/src/DrawingField.java @@ -2,12 +2,13 @@ import javax.swing.*; import java.awt.*; import java.util.Random; -public class DrawingField extends JPanel { - private final FormGasolineTanker field; - DrawingGasolineTanker _gasolineTanker; +public class DrawingField extends JPanel{ + private final FormGasolineTanker Field; + DrawingGasolineTanker _gasolineTanker=null; public DrawingField(FormGasolineTanker field) { - this.field = field; + Field = field; } + @Override protected void paintComponent(Graphics g) { super.paintComponent(g); @@ -16,41 +17,47 @@ public class DrawingField extends JPanel { _gasolineTanker.DrawTransport(g2); else return; } - public void UpButtonAction(){ - if (_gasolineTanker!=null) - _gasolineTanker.MoveTransport(Direction.Up); - else + public void DirectionButtonAction(Direction side){ + if(_gasolineTanker == null) return; + _gasolineTanker.MoveTransport(side); } - public void DownButtonAction(){ - if (_gasolineTanker!=null) - _gasolineTanker.MoveTransport(Direction.Down); - else - return; - } - public void RightButtonAction(){ - if (_gasolineTanker!=null) - _gasolineTanker.MoveTransport(Direction.Right); - else - return; - } - public void LeftButtonAction(){ - if (_gasolineTanker!=null) - _gasolineTanker.MoveTransport(Direction.Left); - else - return; + private void SetData() { + Random rand=new Random(); + _gasolineTanker.SetPosition(rand.nextInt(100)+10,rand.nextInt(100)+10,getWidth(),getHeight()); + Field.SpeedLabel.setText("Скорость: "+_gasolineTanker.getGasolineTanker().getSpeed()); + Field.WeightLabel.setText("Вес: "+_gasolineTanker.getGasolineTanker().getWeight()); + Field.BodyColorLabel.setText("Цвет: "+Integer.toHexString(_gasolineTanker.getGasolineTanker().getBodyColor().getRGB()).substring(2)); } public void CreateButtonAction(){ - Random rnd=new Random(); - _gasolineTanker=new DrawingGasolineTanker(rnd.nextInt(50)+10,rnd.nextInt(100)+500,new Color(rnd.nextInt(256),rnd.nextInt(256),rnd.nextInt(256))); - _gasolineTanker.SetPosition(rnd.nextInt(100)+10,rnd.nextInt(100)+10,getWidth(),getHeight()); - field.SpeedLabel.setText("Speed: "+_gasolineTanker.getGasolineTanker().getSpeed()); - field.WeightLabel.setText("Weight: "+_gasolineTanker.getGasolineTanker().getWeight()); - field.BodyColorLabel.setText("Color: "+Integer.toHexString(_gasolineTanker.getGasolineTanker().getBodyColor().getRGB()).substring(2)); + Random rand=new Random(); + Color color1 = JColorChooser.showDialog(Field, "Выберите цвет тела корабля", null); + if(color1==null) + color1=new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256)); + _gasolineTanker=new DrawingGasolineTanker(rand.nextInt(50)+10,rand.nextInt(3000)+20000,color1,rand.nextInt(3)); + SetData(); + } + public void CreateModifButtonAction(){ + Random rand=new Random(); + Color color1=JColorChooser.showDialog(Field, "Выберите цвет тела корабля",null); + Color color2=JColorChooser.showDialog(Field, "Выборите цвет модификаций корабля",null); + if(color1==null) + color1=new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256)); + if (color2==null) + color2=new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256)); + _gasolineTanker = new DrawingImprovedGasolineTanker(rand.nextInt(50) + 10, rand.nextInt(3000) + 20000, color1, + color2, rand.nextBoolean(), rand.nextBoolean(), rand.nextInt(3)); + SetData(); } public void ResizeField(){ if (_gasolineTanker!=null) _gasolineTanker.ChangeBorders(getWidth(),getHeight()); else return; } + + public void Draw(Graphics2D graphics) { + if (_gasolineTanker!=null) + _gasolineTanker.DrawTransport(graphics); + else return; + } } diff --git a/src/DrawingGasolineTanker.java b/src/DrawingGasolineTanker.java index f7f3bb9..9d414e0 100644 --- a/src/DrawingGasolineTanker.java +++ b/src/DrawingGasolineTanker.java @@ -1,25 +1,56 @@ import java.awt.*; public class DrawingGasolineTanker { - public EntityGasolineTanker GasolineTanker; - public EntityGasolineTanker getGasolineTanker() { + protected EntityGasolineTanker GasolineTanker; + public EntityGasolineTanker getGasolineTanker(){ return GasolineTanker; } - public DrawingWheels Wheels; - private int _startPosX; - private int _startPosY; + protected IDrawningObjectWheels Wheels; + private CountWheels _wheels; + protected int _startPosX; + protected int _startPosY; private Integer _pictureWidth = null; private Integer _pictureHeight = null; - private final int _gasolineTankerWidth = 160; - private final int _gasolineTankerHeight = 55; + private int _gasolineTankerWidth = 160; + private int _gasolineTankerHeight = 70; - public DrawingGasolineTanker(int speed, float weight, Color bodyColor) + public DrawingGasolineTanker(int speed, float weight, Color bodyColor, int wheelsForm) { GasolineTanker = new EntityGasolineTanker(speed, weight, bodyColor); - Wheels = new DrawingWheels(); + Wheels= GetFormOfBlock(wheelsForm); Wheels.SetCountWheels((int)(2 + Math.random() + Math.random()*2)); } + public IDrawningObjectWheels GetFormOfBlock(int FormOfBlock){ + OrnamentForm temp = null; + for (OrnamentForm form:OrnamentForm.values()) { + if(form.Value==FormOfBlock){ + temp = form; + break; + } + } + if(temp==null) + return null; + switch (temp){ + case NoneOrnament: + return new DrawingWheels(_wheels); + case GrayOrnament: + return new DrawingOrnamentWheelsFirst(_wheels); + case RedOrnament: + return new DrawingOrnamentWheelsSecond(_wheels); + } + return null; + } + + protected DrawingGasolineTanker(int speed, float weight, Color bodyColor,int warshipWidth, int warshipHeight) + { + GasolineTanker = new EntityGasolineTanker(speed, weight, bodyColor); + Wheels= new DrawingWheels(_wheels); + Wheels.SetCountWheels((int)(2 + Math.random() + Math.random()*2)); + _gasolineTankerWidth=warshipWidth; + _pictureHeight=warshipHeight; + } + public void SetPosition(int x, int y, int width, int height) { if (x >= 0 && x+_gasolineTankerWidth <= width && y >= 0 && y+_gasolineTankerHeight <= height) @@ -69,6 +100,7 @@ public class DrawingGasolineTanker { break; } } + public void DrawTransport(Graphics g) { if (_startPosX < 0 || _startPosY < 0 || _pictureHeight== null || _pictureWidth== null) @@ -102,6 +134,7 @@ public class DrawingGasolineTanker { g2.drawRect(_startPosX + 120, _startPosY + 10, 25, 25); g2.fillRect(_startPosX + 120, _startPosY + 10, 25, 25); } + public void ChangeBorders(int width,int height) { _pictureWidth = width; @@ -121,4 +154,12 @@ public class DrawingGasolineTanker { _startPosY = _pictureHeight - _gasolineTankerHeight; } } + public float[] GetCurrentPosition() { + float[] dim = new float[4]; + dim[0] = _startPosX; + dim[1] =_startPosY; + dim[2] = _startPosX + _gasolineTankerWidth; + dim[3] = _startPosY + _gasolineTankerHeight; + return dim; + } } diff --git a/src/DrawingImprovedGasolineTanker.java b/src/DrawingImprovedGasolineTanker.java new file mode 100644 index 0000000..ac2b6dc --- /dev/null +++ b/src/DrawingImprovedGasolineTanker.java @@ -0,0 +1,50 @@ +import java.awt.*; + +public class DrawingImprovedGasolineTanker extends DrawingGasolineTanker { + + public DrawingImprovedGasolineTanker(int speed, float weight, Color bodyColor, Color dopColor, boolean bodyKit, boolean antena,int blockForm) { + super(speed, weight, bodyColor, 160, 70); + GasolineTanker=new EntityImprovedGasolineTanker(speed,weight,bodyColor,dopColor,bodyKit,antena); + Wheels= GetFormOfBlock(blockForm); + Wheels.SetCountWheels((int)(2 + Math.random() + Math.random()*2)); + } + + @Override + public void DrawTransport(Graphics g) { + + if (! (GasolineTanker instanceof EntityImprovedGasolineTanker)) + { + return; + } + + EntityImprovedGasolineTanker improvedGasolineTanker = (EntityImprovedGasolineTanker)GasolineTanker; + Graphics2D g2 = (Graphics2D) g; + + int [] x1 ={_startPosX+25,_startPosX+65,_startPosX+75,_startPosX+25,_startPosX+25}; + int [] y1 ={_startPosY,_startPosY,_startPosY+5,_startPosY+5,_startPosY}; + int [] x2 ={_startPosX+25,_startPosX+75,_startPosX+65,_startPosX+25,_startPosX+25}; + int [] y2 ={_startPosY+45,_startPosY+45,_startPosY+50,_startPosY+50,_startPosY+45}; + + if (improvedGasolineTanker.BodyKit) + { + g2.setColor(improvedGasolineTanker.GetDopColor()); + g2.drawRect(_startPosX + 25, _startPosY + 5, 100, 35); + g2.fillRect(_startPosX + 25, _startPosY + 5, 100, 35); + + } + + _startPosX += 10; + _startPosY += 5; + super.DrawTransport(g); + _startPosX -= 10; + _startPosY -= 5; + + if (improvedGasolineTanker.Antena) + { + g2.setColor(Color.RED); + g2.drawRect(_startPosX + 130, _startPosY + 5, 10, 5); + g2.fillRect(_startPosX + 130, _startPosY + 5, 10, 5); + + } + } +} diff --git a/src/DrawingMap.java b/src/DrawingMap.java new file mode 100644 index 0000000..01e4b0a --- /dev/null +++ b/src/DrawingMap.java @@ -0,0 +1,71 @@ +import javax.swing.*; +import java.awt.*; +import java.awt.image.BufferedImage; +import java.util.Random; + +public class DrawingMap extends JPanel { + private final FormMap Map; + private AbstractMap _abstractMap; + BufferedImage bufferedImage; + + public DrawingMap(FormMap map){ + Map=map; + _abstractMap = new SimpleMap(); + } + + @Override + protected void paintComponent(Graphics g) { + super.paintComponent(g); + g.drawImage(bufferedImage,0,0,null); + } + + private void SetData(DrawingGasolineTanker gasolineTanker) { + Random rand=new Random(); + gasolineTanker.SetPosition(rand.nextInt(100)+10,rand.nextInt(100)+10,getWidth(),getHeight()); + Map.SpeedLabel.setText("Speed: "+gasolineTanker.getGasolineTanker().getSpeed()); + Map.WeightLabel.setText("Weight: "+gasolineTanker.getGasolineTanker().getWeight()); + Map.BodyColorLabel.setText("Color: "+Integer.toHexString(gasolineTanker.getGasolineTanker().getBodyColor().getRGB()).substring(2)); + bufferedImage = _abstractMap.CreateMap(700,550,new DrawingObjectGasolineTanker(gasolineTanker)); + } + public void CreateButtonAction(){ + Random rand=new Random(); + Color color1=new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256)); + if(color1==null) + color1=new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256)); + DrawingGasolineTanker warship=new DrawingGasolineTanker(rand.nextInt(50)+10,rand.nextInt(3000)+20000,color1,rand.nextInt(3)); + SetData(warship); + } + public void CreateModifButtonAction(){ + Random rand=new Random(); + Color color1=new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256)); + Color color2=new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256)); + if(color1==null) + color1=new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256)); + if (color2==null) + color2=new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256)); + DrawingGasolineTanker gasolineTanker = new DrawingImprovedGasolineTanker(rand.nextInt(50) + 10, rand.nextInt(3000) + 20000, color1, + color2, rand.nextBoolean(), rand.nextBoolean(),rand.nextInt(3)); + SetData(gasolineTanker); + } + public void DirectionButtonAction(Direction side){ + if(_abstractMap != null){ + bufferedImage = _abstractMap.MoveObject(side); + } + } + + public void ComboBoxSelectorMapAction(String name){ + switch (name){ + case "Simple map": + _abstractMap = new SimpleMap(); + break; + case "Long map": + _abstractMap = new LongMap(); + break; + } + } + + public void DrawMap(Graphics g){ + g.drawImage(bufferedImage,0,0,null); + } + +} diff --git a/src/DrawingObjectGasolineTanker.java b/src/DrawingObjectGasolineTanker.java new file mode 100644 index 0000000..7a1c0d7 --- /dev/null +++ b/src/DrawingObjectGasolineTanker.java @@ -0,0 +1,39 @@ +import java.awt.*; + +public class DrawingObjectGasolineTanker implements IDrawingObject { + + private DrawingGasolineTanker _gasolineTanker=null; + + public DrawingObjectGasolineTanker(DrawingGasolineTanker gasolineTanker) + { + _gasolineTanker= gasolineTanker; + } + + public float Step() { + if(_gasolineTanker != null && _gasolineTanker.GasolineTanker != null) + return _gasolineTanker.GasolineTanker.Step; + return 0; + } + + @Override + public void SetObject(int x, int y, int width, int height) { + _gasolineTanker.SetPosition(x,y,width,height); + } + + @Override + public void MoveObject(Direction direction) { + _gasolineTanker.MoveTransport(direction); + } + + @Override + public void DrawingObject(Graphics g) { + _gasolineTanker.DrawTransport(g); + } + + @Override + public float[] GetCurrentPosition() { + if(_gasolineTanker!=null) + return _gasolineTanker.GetCurrentPosition(); + return null; + } +} diff --git a/src/DrawingOrnamentWheelsFirst.java b/src/DrawingOrnamentWheelsFirst.java new file mode 100644 index 0000000..e818a5e --- /dev/null +++ b/src/DrawingOrnamentWheelsFirst.java @@ -0,0 +1,54 @@ +import java.awt.*; + +public class DrawingOrnamentWheelsFirst implements IDrawningObjectWheels{ + private CountWheels _wheels; + + public DrawingOrnamentWheelsFirst(CountWheels wheels){ + _wheels=wheels; + } + @Override + public void SetCountWheels(int count) { + for (CountWheels temp: CountWheels.values()) + if (temp.getCountWheels() == count){ + _wheels=temp; + return; + } + } + + @Override + public void DrawWheels(Graphics2D g, int _startPosX, int _startPosY) { + if (_wheels.getCountWheels() == 2) { + g.setColor(Color.BLACK); + g.drawOval(_startPosX + 10, _startPosY + 35, 20, 20); + g.fillOval(_startPosX + 10, _startPosY + 35, 20, 20); + g.setColor(Color.GRAY); + g.drawOval(_startPosX + 130, _startPosY + 45, 20, 5); + g.drawOval(_startPosX + 10, _startPosY + 45, 20, 5); + } + if (_wheels.getCountWheels() == 3) { + g.setColor(Color.BLACK); + g.drawOval(_startPosX + 10, _startPosY + 35, 20, 20); + g.fillOval(_startPosX + 10, _startPosY + 35, 20, 20); + g.drawOval(_startPosX + 30, _startPosY + 35, 20, 20); + g.fillOval(_startPosX + 30, _startPosY + 35, 20, 20); + g.setColor(Color.GRAY); + g.drawOval(_startPosX + 130, _startPosY + 45, 20, 5); + g.drawOval(_startPosX + 30, _startPosY + 45, 20, 5); + g.drawOval(_startPosX + 10, _startPosY + 45, 20, 5); + } + if (_wheels.getCountWheels() == 4) { + g.setColor(Color.BLACK); + g.drawOval(_startPosX + 10, _startPosY + 35, 20, 20); + g.fillOval(_startPosX + 10, _startPosY + 35, 20, 20); + g.drawOval(_startPosX + 30, _startPosY + 35, 20, 20); + g.fillOval(_startPosX + 30, _startPosY + 35, 20, 20); + g.drawOval(_startPosX + 50, _startPosY + 35, 20, 20); + g.fillOval(_startPosX + 50, _startPosY + 35, 20, 20); + g.setColor(Color.GRAY); + g.drawOval(_startPosX + 130, _startPosY + 45, 20, 5); + g.drawOval(_startPosX + 50, _startPosY + 45, 20, 5); + g.drawOval(_startPosX + 30, _startPosY + 45, 20, 5); + g.drawOval(_startPosX + 10, _startPosY + 45, 20, 5); + } + } +} diff --git a/src/DrawingOrnamentWheelsSecond.java b/src/DrawingOrnamentWheelsSecond.java new file mode 100644 index 0000000..cf2ff8d --- /dev/null +++ b/src/DrawingOrnamentWheelsSecond.java @@ -0,0 +1,55 @@ +import java.awt.*; + +public class DrawingOrnamentWheelsSecond implements IDrawningObjectWheels{ + private CountWheels _wheels; + + public DrawingOrnamentWheelsSecond(CountWheels wheels){ + _wheels=wheels; + } + @Override + public void SetCountWheels(int count) { + for (CountWheels temp: CountWheels.values()) + if (temp.getCountWheels() == count){ + _wheels=temp; + return; + } + } + + @Override + public void DrawWheels(Graphics2D g, int _startPosX, int _startPosY) { + + if (_wheels.getCountWheels() == 2) { + g.setColor(Color.BLACK); + g.drawOval(_startPosX + 10, _startPosY + 35, 20, 20); + g.fillOval(_startPosX + 10, _startPosY + 35, 20, 20); + g.setColor(Color.RED); + g.drawOval(_startPosX + 130, _startPosY + 45, 20, 5); + g.drawOval(_startPosX + 10, _startPosY + 45, 20, 5); + } + if (_wheels.getCountWheels() == 3) { + g.setColor(Color.BLACK); + g.drawOval(_startPosX + 10, _startPosY + 35, 20, 20); + g.fillOval(_startPosX + 10, _startPosY + 35, 20, 20); + g.drawOval(_startPosX + 30, _startPosY + 35, 20, 20); + g.fillOval(_startPosX + 30, _startPosY + 35, 20, 20); + g.setColor(Color.RED); + g.drawOval(_startPosX + 130, _startPosY + 45, 20, 5); + g.drawOval(_startPosX + 30, _startPosY + 45, 20, 5); + g.drawOval(_startPosX + 10, _startPosY + 45, 20, 5); + } + if (_wheels.getCountWheels() == 4) { + g.setColor(Color.BLACK); + g.drawOval(_startPosX + 10, _startPosY + 35, 20, 20); + g.fillOval(_startPosX + 10, _startPosY + 35, 20, 20); + g.drawOval(_startPosX + 30, _startPosY + 35, 20, 20); + g.fillOval(_startPosX + 30, _startPosY + 35, 20, 20); + g.drawOval(_startPosX + 50, _startPosY + 35, 20, 20); + g.fillOval(_startPosX + 50, _startPosY + 35, 20, 20); + g.setColor(Color.RED); + g.drawOval(_startPosX + 130, _startPosY + 45, 20, 5); + g.drawOval(_startPosX + 50, _startPosY + 45, 20, 5); + g.drawOval(_startPosX + 30, _startPosY + 45, 20, 5); + g.drawOval(_startPosX + 10, _startPosY + 45, 20, 5); + } + } +} diff --git a/src/DrawingWheels.java b/src/DrawingWheels.java index 53f93b4..e50d1ca 100644 --- a/src/DrawingWheels.java +++ b/src/DrawingWheels.java @@ -1,8 +1,12 @@ import java.awt.*; -public class DrawingWheels { +public class DrawingWheels implements IDrawningObjectWheels{ - private CountWheels _wheels; + private CountWheels _wheels = null; + + public DrawingWheels(CountWheels wheels) { + _wheels=wheels; + } public void SetCountWheels(int Count){ for (CountWheels temp: CountWheels.values()) @@ -13,29 +17,26 @@ public class DrawingWheels { } public void DrawWheels(Graphics2D g,int _startPosX, int _startPosY) { - switch (_wheels.getCountWheels()) - { - case 2: - g.setColor(Color.BLACK); - g.drawOval(_startPosX + 10, _startPosY + 35, 20, 20); - g.fillOval(_startPosX + 10, _startPosY + 35, 20, 20); - break; - case 3: - g.setColor(Color.BLACK); - g.drawOval(_startPosX + 10, _startPosY + 35, 20, 20); - g.fillOval(_startPosX + 10, _startPosY + 35, 20, 20); - g.drawOval(_startPosX + 30, _startPosY + 35, 20, 20); - g.fillOval(_startPosX + 30, _startPosY + 35, 20, 20); - break; - case 4: - g.setColor(Color.BLACK); - g.drawOval(_startPosX + 10, _startPosY + 35, 20, 20); - g.fillOval(_startPosX + 10, _startPosY + 35, 20, 20); - g.drawOval(_startPosX + 30, _startPosY + 35, 20, 20); - g.fillOval(_startPosX + 30, _startPosY + 35, 20, 20); - g.drawOval(_startPosX + 50, _startPosY + 35, 20, 20); - g.fillOval(_startPosX + 50, _startPosY + 35, 20, 20); - break; + if (_wheels.getCountWheels() == 2) { + g.setColor(Color.BLACK); + g.drawOval(_startPosX + 10, _startPosY + 35, 20, 20); + g.fillOval(_startPosX + 10, _startPosY + 35, 20, 20); + } + if (_wheels.getCountWheels() == 3) { + g.setColor(Color.BLACK); + g.drawOval(_startPosX + 10, _startPosY + 35, 20, 20); + g.fillOval(_startPosX + 10, _startPosY + 35, 20, 20); + g.drawOval(_startPosX + 30, _startPosY + 35, 20, 20); + g.fillOval(_startPosX + 30, _startPosY + 35, 20, 20); + } + if (_wheels.getCountWheels() == 4){ + g.setColor(Color.BLACK); + g.drawOval(_startPosX + 10, _startPosY + 35, 20, 20); + g.fillOval(_startPosX + 10, _startPosY + 35, 20, 20); + g.drawOval(_startPosX + 30, _startPosY + 35, 20, 20); + g.fillOval(_startPosX + 30, _startPosY + 35, 20, 20); + g.drawOval(_startPosX + 50, _startPosY + 35, 20, 20); + g.fillOval(_startPosX + 50, _startPosY + 35, 20, 20); } } } diff --git a/src/EntityGasolineTanker.java b/src/EntityGasolineTanker.java index b881fb0..5199730 100644 --- a/src/EntityGasolineTanker.java +++ b/src/EntityGasolineTanker.java @@ -14,7 +14,7 @@ public class EntityGasolineTanker { public Color getBodyColor() { return BodyColor; } - public float Step; + public int Step; public EntityGasolineTanker(int speed, float weight, Color bodyColor){ @@ -22,7 +22,7 @@ public class EntityGasolineTanker { Speed = speed <= 0 ? rnd.nextInt(50)+10 : speed; Weight = weight <= 0 ? rnd.nextInt(100)+500 : weight; BodyColor = bodyColor; - Step = Speed * 100/ (int)Weight; + Step = Speed * 5000/ (int)Weight; } } diff --git a/src/EntityImprovedGasolineTanker.java b/src/EntityImprovedGasolineTanker.java index c97681e..8786016 100644 --- a/src/EntityImprovedGasolineTanker.java +++ b/src/EntityImprovedGasolineTanker.java @@ -11,16 +11,16 @@ public class EntityImprovedGasolineTanker extends EntityGasolineTanker{ return BodyKit ; } - public boolean OrnamentWheels ; - public boolean GetOrnamentWheels () { - return OrnamentWheels ; + public boolean Antena ; + public boolean GetAntena () { + return Antena ; } - public EntityImprovedGasolineTanker(int speed, float weight, Color bodyColor, Color dopColor, boolean bodyKit, boolean ornamentWheels){ + public EntityImprovedGasolineTanker(int speed, float weight, Color bodyColor, Color dopColor, boolean bodyKit, boolean antena){ super(speed,weight,bodyColor); DopColor = dopColor; BodyKit = bodyKit; - OrnamentWheels = ornamentWheels; + Antena = antena; } } diff --git a/src/FormGasolineTanker.form b/src/FormGasolineTanker.form new file mode 100644 index 0000000..2c51dc1 --- /dev/null +++ b/src/FormGasolineTanker.form @@ -0,0 +1,160 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/FormGasolineTanker.java b/src/FormGasolineTanker.java index e01c86b..22aa3a9 100644 --- a/src/FormGasolineTanker.java +++ b/src/FormGasolineTanker.java @@ -2,134 +2,90 @@ import javax.swing.*; import java.awt.*; import java.awt.event.ComponentAdapter; import java.awt.event.ComponentEvent; + public class FormGasolineTanker extends JFrame{ private int Width; private int Height; - - JPanel BottomPanel = new JPanel(); - JPanel CreatePanel = new JPanel(); - JPanel BottomAndCreatePanel = new JPanel(); - JPanel DimentionPanel = new JPanel(); - JPanel UPanel = new JPanel(); - JPanel DPanel = new JPanel(); - JPanel LRPanel = new JPanel(); - - JLabel SpeedLabel = new JLabel("Speed: "); - JLabel WeightLabel = new JLabel("Weight: "); - JLabel BodyColorLabel = new JLabel("Color: "); - DrawingField field = new DrawingField(this); + private JButton ButtonDown; + private JButton ButtonRight; + private JButton ButtonLeft; + private JButton ButtonUp; + private JButton ButtonCreate; + private JButton ButtonCreateModif; + public JLabel SpeedLabel; + public JLabel WeightLabel; + public JLabel BodyColorLabel; + private JPanel PictureBox; - JButton ButtonCreate=new JButton("Create"); - - Icon iconUp = new ImageIcon("C:\\Users\\kashi\\OneDrive\\Материал\\KeyUp.png"); - JButton ButtonUp=new JButton(iconUp); - - Icon iconDown = new ImageIcon("C:\\Users\\kashi\\OneDrive\\Материал\\KeyDown.png"); - JButton ButtonDown=new JButton(iconDown); - - Icon iconRight = new ImageIcon("C:\\Users\\kashi\\OneDrive\\Материал\\KeyRight.png"); - JButton ButtonRight=new JButton(iconRight); - - Icon iconLeft = new ImageIcon("C:\\Users\\kashi\\OneDrive\\Материал\\KeyLeft.png"); - JButton ButtonLeft=new JButton(iconLeft); public FormGasolineTanker(){ - super("Gasoline Tanker"); - setSize(800,600); - Width=getWidth(); - Height=getHeight(); + super("Военный корабль"); + setContentPane(PictureBox); + setSize(1000,700); + Width = getWidth(); + Height = getHeight(); ShowWindow(); - RefreshWindow(); + field.setBounds(0,0,Width,Height); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); } + ImageIcon spriteUp =new ImageIcon((new ImageIcon("Material\\KeyUp.png")). + getImage().getScaledInstance(10,10,Image.SCALE_SMOOTH)); + ImageIcon spriteDown =new ImageIcon((new ImageIcon("Material\\KeyDown.png")). + getImage().getScaledInstance(10,10,Image.SCALE_SMOOTH)); + ImageIcon spriteLeft =new ImageIcon((new ImageIcon("Material\\KeyLeft.png")). + getImage().getScaledInstance(10,10,Image.SCALE_SMOOTH)); + ImageIcon spriteRight =new ImageIcon((new ImageIcon("Material\\KeyRight.png")). + getImage().getScaledInstance(10,10,Image.SCALE_SMOOTH)); + private void ShowWindow(){ - 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->{ + ButtonCreate.addActionListener(e -> { field.CreateButtonAction(); - repaint(); + ReDraw(); + }); + ButtonCreateModif.addActionListener(e -> { + field.CreateModifButtonAction(); + ReDraw(); + }); + ButtonUp.setIcon(spriteUp); + ButtonUp.addActionListener(e -> { + field.DirectionButtonAction(Direction.Up); + ReDraw(); + }); + ButtonLeft.setIcon(spriteLeft); + ButtonLeft.addActionListener(e -> { + field.DirectionButtonAction(Direction.Left); + ReDraw(); + }); + ButtonRight.setIcon(spriteRight); + ButtonRight.addActionListener(e -> { + field.DirectionButtonAction(Direction.Right); + ReDraw(); + }); + ButtonDown.setIcon(spriteDown); + ButtonDown.addActionListener(e -> { + field.DirectionButtonAction(Direction.Down); + ReDraw(); }); - - BottomPanel.setLayout(new FlowLayout()); - BottomPanel.setBackground(new Color(0,0,0,0)); - BottomPanel.add(SpeedLabel); - BottomPanel.add(WeightLabel); - BottomPanel.add(BodyColorLabel); - - 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) { + public void componentResized(ComponentEvent e){ super.componentResized(e); Width=getWidth(); Height=getHeight(); field.ResizeField(); - repaint(); - RefreshWindow(); + ReDraw(); + field.setBounds(0,0,Width,Height); } }); } - public void RefreshWindow(){ - field.setBounds(0,0,Width,Height); - BottomAndCreatePanel.setBounds(-220,Height-110,Width,80); - DimentionPanel.setBounds(Width-170,Height-170,190,140); + private void ReDraw() + { + Graphics2D graphics = (Graphics2D) PictureBox.getGraphics(); + graphics.clearRect(0, 0, PictureBox.getWidth(), PictureBox.getHeight()); + PictureBox.paintComponents(graphics); + field.Draw(graphics); } } diff --git a/src/FormMap.form b/src/FormMap.form new file mode 100644 index 0000000..8826466 --- /dev/null +++ b/src/FormMap.form @@ -0,0 +1,171 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/FormMap.java b/src/FormMap.java new file mode 100644 index 0000000..e58f7c9 --- /dev/null +++ b/src/FormMap.java @@ -0,0 +1,87 @@ +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.ComponentAdapter; +import java.awt.event.ComponentEvent; +import java.util.Objects; + +public class FormMap extends JFrame { + private int Width; + private int Height; + DrawingMap map = new DrawingMap(this); + private JButton ButtonDown; + private JButton ButtonRight; + private JButton ButtonLeft; + private JButton ButtonUp; + private JButton ButtonCreate; + private JButton ButtonCreateModif; + public JLabel SpeedLabel; + public JLabel WeightLabel; + public JLabel BodyColorLabel; + private JComboBox ComboBoxSelectorMap; + private JPanel PictureBox; + ImageIcon spriteUp =new ImageIcon((new ImageIcon("Material\\KeyUp.png")). + getImage().getScaledInstance(10,10,Image.SCALE_SMOOTH)); + ImageIcon spriteDown =new ImageIcon((new ImageIcon("Material\\KeyDown.png")). + getImage().getScaledInstance(10,10,Image.SCALE_SMOOTH)); + ImageIcon spriteLeft =new ImageIcon((new ImageIcon("Material\\KeyLeft.png")). + getImage().getScaledInstance(10,10,Image.SCALE_SMOOTH)); + ImageIcon spriteRight =new ImageIcon((new ImageIcon("Material\\KeyRight.png")). + getImage().getScaledInstance(10,10,Image.SCALE_SMOOTH)); + public FormMap(){ + super("Военный корабль"); + setContentPane(PictureBox); + setSize(1000,700); + Width = getWidth(); + Height = getHeight(); + ShowWindow(); + map.setBounds(0,0,Width,Height); + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setVisible(true); + } + + private void ShowWindow(){ + ButtonCreate.addActionListener(e -> { + map.CreateButtonAction(); + ReDraw(); + }); + ButtonCreateModif.addActionListener(e -> { + map.CreateModifButtonAction(); + ReDraw(); + }); + ButtonUp.setIcon(spriteUp); + ButtonUp.addActionListener(e -> { + map.DirectionButtonAction(Direction.Up); + ReDraw(); + }); + ButtonLeft.setIcon(spriteLeft); + ButtonLeft.addActionListener(e -> { + map.DirectionButtonAction(Direction.Left); + ReDraw(); + }); + ButtonRight.setIcon(spriteRight); + ButtonRight.addActionListener(e -> { + map.DirectionButtonAction(Direction.Right); + ReDraw(); + }); + ButtonDown.setIcon(spriteDown); + ButtonDown.addActionListener(e -> { + map.DirectionButtonAction(Direction.Down); + ReDraw(); + }); + + ComboBoxSelectorMap.addActionListener(e -> { + map.ComboBoxSelectorMapAction(Objects.requireNonNull(ComboBoxSelectorMap.getSelectedItem()).toString()); + ReDraw(); + }); + } + private void ReDraw() + { + Graphics2D graphics = (Graphics2D) PictureBox.getGraphics(); + graphics.clearRect(0, 0, PictureBox.getWidth(), PictureBox.getHeight()); + PictureBox.paintComponents(graphics); + map.DrawMap(graphics); + } + +} diff --git a/src/IDrawingObject.java b/src/IDrawingObject.java index e4f54ff..3df3eb3 100644 --- a/src/IDrawingObject.java +++ b/src/IDrawingObject.java @@ -1,4 +1,5 @@ import java.awt.*; + public interface IDrawingObject { public float Step=0; void SetObject(int x, int y, int width, int height); diff --git a/src/IDrawningObjectWheels.java b/src/IDrawningObjectWheels.java new file mode 100644 index 0000000..b293250 --- /dev/null +++ b/src/IDrawningObjectWheels.java @@ -0,0 +1,6 @@ +import java.awt.*; + +public interface IDrawningObjectWheels { + void SetCountWheels(int count); + void DrawWheels(Graphics2D g, int _startPosX, int _startPosY); +} diff --git a/src/LongMap.java b/src/LongMap.java index 51e7cca..61671b6 100644 --- a/src/LongMap.java +++ b/src/LongMap.java @@ -1,37 +1,43 @@ import java.awt.*; public class LongMap extends AbstractMap{ - @Override - protected void GenerateMap() { - _map = new int[60][60]; - _size_x = (float) (_width / _map.length); - _size_y = (float) (_height / _map[0].length); + protected void GenerateMap() + { + _map = new int[100][100]; + _size_x = (float)_width / _map[0].length; + _size_y = (float)_height / _map[1].length; int counter = 0; - for (int i = 0; i < _map.length; ++i) { - for (int j = 0; j < _map[i].length; ++j) { - _map[i][j] = _freeWaterArea; + for (int i = 0; i < _map[0].length; ++i) + { + for (int j = 0; j < _map[1].length; ++j) + { + _map[i][j] = _freeRoad; } } - while (counter < 20) { - int x = _random.nextInt(59); - int y = _random.nextInt(59); - if (_map[x][y] == _freeWaterArea) { - _map[x][y] = _land; - counter++; + while (counter < 5) + { + int xStart = _random.nextInt(0, 100); + int xEnd = _random.nextInt(80, 100); + + for (int i = xStart; i <= xEnd; ++i) + { + _map[i] [xStart] = _barrier; } + + counter++; } } @Override - protected void DrawWaterPart(Graphics gr, int i, int j) { - gr.setColor(new Color(0xFFFFFF)); + protected void DrawBarrierPart(Graphics gr, int i, int j) { + gr.setColor(Color.GRAY); gr.fillRect((int) (i * _size_x), (int) (j * _size_y), (int) (i * (_size_x + 1)), (int) (j * (_size_y + 1))); } @Override - protected void DrawLandPart(Graphics gr, int i, int j) { - gr.setColor(new Color(0x050303)); + protected void DrawRoadPart(Graphics gr, int i, int j) { + gr.setColor(Color.BLACK); gr.fillRect((int) (i * _size_x), (int) (j * _size_y), (int) (i * (_size_x + 1)), (int) (j * (_size_y + 1))); } } diff --git a/src/Main.java b/src/Main.java index 1528646..7b927cf 100644 --- a/src/Main.java +++ b/src/Main.java @@ -1,5 +1,5 @@ public class Main { - public static void main(String[] args){ - new FormGasolineTanker(); + public static void main(String[] args) { + new FormMap(); } -} +} \ No newline at end of file diff --git a/src/OrnamentForm.java b/src/OrnamentForm.java new file mode 100644 index 0000000..413c777 --- /dev/null +++ b/src/OrnamentForm.java @@ -0,0 +1,9 @@ +public enum OrnamentForm { + NoneOrnament(0), + GrayOrnament(1), + RedOrnament(2); + public final int Value; + OrnamentForm(int i) { + Value=i; + } +} diff --git a/src/SimpleMap.java b/src/SimpleMap.java index 5278e90..9b81ab1 100644 --- a/src/SimpleMap.java +++ b/src/SimpleMap.java @@ -2,14 +2,14 @@ import java.awt.*; public class SimpleMap extends AbstractMap { @Override - protected void DrawWaterPart(Graphics gr, int i, int j) { - gr.setColor(new Color(0x5285B6)); + protected void DrawBarrierPart(Graphics gr, int i, int j) { + gr.setColor(Color.GRAY); gr.fillRect((int) (i * _size_x), (int) (j * _size_y), (int) (i * (_size_x + 1)), (int) (j * (_size_y + 1))); } @Override - protected void DrawLandPart(Graphics gr, int i, int j) { - gr.setColor(new Color(0x422A1D)); + protected void DrawRoadPart(Graphics gr, int i, int j) { + gr.setColor(Color.BLACK); gr.fillRect((int) (i * _size_x), (int) (j * _size_y), (int) (i * (_size_x + 1)), (int) (j * (_size_y + 1))); } @@ -21,16 +21,16 @@ public class SimpleMap extends AbstractMap { int counter = 0; for (int i = 0; i < _map.length; ++i) { for (int j = 0; j < _map[i].length; ++j) { - _map[i][j] = _freeWaterArea; + _map[i][j] = _freeRoad; } } while (counter < 50) { int x = _random.nextInt(99); int y = _random.nextInt(99); - if (_map[x][y] == _freeWaterArea) { - _map[x][y] = _land; + if (_map[x][y] == _freeRoad) { + _map[x][y] = _barrier; counter++; } } } -} \ No newline at end of file +}