Продвинутый объект
This commit is contained in:
parent
489964eb09
commit
e65faf2146
82
src/DrawingAircraftCarrier.java
Normal file
82
src/DrawingAircraftCarrier.java
Normal file
@ -0,0 +1,82 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawingAircraftCarrier extends DrawingWarship{
|
||||
|
||||
public DrawingAircraftCarrier(int speed, float weight, Color bodyColor, Color dopColor, boolean bodyKit, boolean cabin, boolean superEngine)
|
||||
{
|
||||
super(speed, weight, bodyColor, 114, 40);
|
||||
Warship = new EntityAircraftCarrier(speed, weight, bodyColor, dopColor, bodyKit, cabin, superEngine);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void DrawTransport(Graphics2D g2){
|
||||
if(!(Warship instanceof EntityAircraftCarrier))
|
||||
{
|
||||
return;
|
||||
}
|
||||
EntityAircraftCarrier aircraftCarrier = (EntityAircraftCarrier) Warship;
|
||||
|
||||
if (aircraftCarrier.GetBodyKit())
|
||||
{
|
||||
//боковая площадка
|
||||
int[] pointXArea = {_startPosX + 94, _startPosX + 74, _startPosX + 24, _startPosX + 4};
|
||||
int[] pointYArea = {_startPosY + 40, _startPosY + 60, _startPosY + 60, _startPosY + 40};
|
||||
g2.setColor(Warship.GetBodyColor());
|
||||
g2.fillPolygon(pointXArea, pointYArea, 4);
|
||||
g2.setColor(Color.BLACK);
|
||||
g2.drawPolygon(pointXArea, pointYArea, 4);
|
||||
|
||||
//полоса
|
||||
int[] pointXLine = {_startPosX + 4, _startPosX + 15, _startPosX + 74, _startPosX + 59};
|
||||
int[] pointYLine = {_startPosY, _startPosY, _startPosY + 60, _startPosY + 60};
|
||||
g2.setColor(Color.GRAY);
|
||||
g2.fillPolygon(pointXLine, pointYLine, 4);
|
||||
g2.setColor(Color.BLACK);
|
||||
g2.drawPolygon(pointXLine, pointYLine, 4);
|
||||
|
||||
}
|
||||
|
||||
if (aircraftCarrier.GetSuperEngine())
|
||||
{
|
||||
g2.setColor(Color.RED);
|
||||
g2.fillOval(_startPosX, _startPosY, 10, 10);
|
||||
g2.setColor(Color.BLACK);
|
||||
g2.drawOval(_startPosX, _startPosY, 10, 10);
|
||||
|
||||
g2.setColor(Color.RED);
|
||||
g2.fillOval(_startPosX, _startPosY + 10, 10, 10);
|
||||
g2.setColor(Color.BLACK);
|
||||
g2.drawOval(_startPosX, _startPosY + 10, 10, 10);
|
||||
|
||||
g2.setColor(Color.RED);
|
||||
g2.fillOval(_startPosX, _startPosY + 18, 10, 10);
|
||||
g2.setColor(Color.BLACK);
|
||||
g2.drawOval(_startPosX, _startPosY + 18, 10, 10);
|
||||
|
||||
g2.setColor(Color.RED);
|
||||
g2.fillOval(_startPosX, _startPosY + 30, 10, 10);
|
||||
g2.setColor(Color.BLACK);
|
||||
g2.drawOval(_startPosX, _startPosY + 30, 10, 10);
|
||||
}
|
||||
|
||||
super.DrawTransport(g2);
|
||||
|
||||
if (aircraftCarrier.GetCabin())
|
||||
{
|
||||
g2.setColor(Color.GRAY);
|
||||
g2.fillOval(_startPosX + 80, _startPosY + 13, 10, 14);
|
||||
g2.setColor(Color.BLACK);
|
||||
g2.drawOval(_startPosX + 80, _startPosY + 13, 10, 14);
|
||||
|
||||
g2.setColor(Color.GRAY);
|
||||
g2.fillOval(_startPosX + 90, _startPosY + 13, 10, 14);
|
||||
g2.setColor(Color.BLACK);
|
||||
g2.drawOval(_startPosX + 90, _startPosY + 13, 10, 14);
|
||||
|
||||
g2.setColor(Color.GRAY);
|
||||
g2.fillRect(_startPosX + 85, _startPosY + 13, 10, 14);
|
||||
g2.setColor(Color.BLACK);
|
||||
g2.drawRect(_startPosX + 85, _startPosY + 13, 10, 14);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,18 +1,18 @@
|
||||
import java.awt.*;
|
||||
import java.util.Random;
|
||||
public class DrawingWarship {
|
||||
private EntityWarship Warship;
|
||||
protected EntityWarship Warship;
|
||||
public EntityWarship GetWarship(){return Warship;}
|
||||
public DrawingBlocks Blocks;
|
||||
|
||||
private int _startPosX;
|
||||
private int _startPosY;
|
||||
protected int _startPosX;
|
||||
protected int _startPosY;
|
||||
|
||||
private Integer _pictureWidth = null;
|
||||
private Integer _pictureHeight = null;
|
||||
|
||||
private final int _warshipWidth = 114;
|
||||
private final int _warshipHeight = 40;
|
||||
private int _warshipWidth = 114;
|
||||
private int _warshipHeight = 40;
|
||||
|
||||
public DrawingWarship(int speed, float weight, Color bodyColor)
|
||||
{
|
||||
@ -20,6 +20,12 @@ public class DrawingWarship {
|
||||
Blocks = new DrawingBlocks();
|
||||
Blocks.blockDirection = BlockRandom();
|
||||
}
|
||||
protected DrawingWarship(int speed, float weight, Color bodyColor, int warshipWidth, int warshipHeight)
|
||||
{
|
||||
this(speed, weight, bodyColor);
|
||||
_warshipWidth = warshipWidth;
|
||||
_warshipHeight = warshipHeight;
|
||||
}
|
||||
|
||||
public void SetPosition(int x, int y, int width, int height)
|
||||
{
|
||||
@ -31,6 +37,7 @@ public class DrawingWarship {
|
||||
_pictureHeight = height;
|
||||
}
|
||||
}
|
||||
|
||||
public void MoveTransport(Direction direction)
|
||||
{
|
||||
if (_pictureWidth == null || _pictureHeight == null)
|
||||
@ -69,7 +76,8 @@ public class DrawingWarship {
|
||||
break;
|
||||
}
|
||||
}
|
||||
public void DrawTransport(Graphics2D g2){
|
||||
|
||||
public void DrawTransport(Graphics2D g2){
|
||||
if (_startPosX < 0 || _startPosY < 0 || _pictureHeight == null || _pictureWidth == null)
|
||||
{
|
||||
return;
|
||||
|
24
src/EntityAircraftCarrier.java
Normal file
24
src/EntityAircraftCarrier.java
Normal file
@ -0,0 +1,24 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class EntityAircraftCarrier extends EntityWarship {
|
||||
private Color DopColor;
|
||||
public Color GetDopColor(){return DopColor;}
|
||||
|
||||
private boolean BodyKit;
|
||||
public boolean GetBodyKit(){return BodyKit;}
|
||||
|
||||
private boolean Cabin;
|
||||
public boolean GetCabin(){return Cabin;}
|
||||
|
||||
private boolean SuperEngine;
|
||||
public boolean GetSuperEngine(){return SuperEngine;}
|
||||
|
||||
public EntityAircraftCarrier(int speed, float weight, Color bodyColor, Color dopColor, boolean bodyKit, boolean cabin, boolean superEngine)
|
||||
{
|
||||
super(speed, weight, bodyColor);
|
||||
DopColor = dopColor;
|
||||
BodyKit = bodyKit;
|
||||
Cabin = cabin;
|
||||
SuperEngine = superEngine;
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormWarship">
|
||||
<grid id="27dc6" binding="mainPanel" layout-manager="GridLayoutManager" row-count="4" column-count="5" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<grid id="27dc6" binding="mainPanel" layout-manager="GridLayoutManager" row-count="4" column-count="6" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<xy x="23" y="20" width="961" height="517"/>
|
||||
@ -18,12 +18,12 @@
|
||||
</component>
|
||||
<hspacer id="3f3da">
|
||||
<constraints>
|
||||
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
<grid row="2" column="2" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
<component id="32714" class="javax.swing.JButton" binding="buttonLeft">
|
||||
<constraints>
|
||||
<grid row="2" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<grid row="2" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
@ -35,7 +35,7 @@
|
||||
</component>
|
||||
<toolbar id="3697c" binding="toolBar">
|
||||
<constraints>
|
||||
<grid row="3" column="0" row-span="1" col-span="5" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<grid row="3" column="0" row-span="1" col-span="6" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="-1" height="20"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
@ -64,7 +64,7 @@
|
||||
</toolbar>
|
||||
<component id="55933" class="javax.swing.JButton" binding="buttonRight">
|
||||
<constraints>
|
||||
<grid row="2" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<grid row="2" column="5" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
@ -76,7 +76,7 @@
|
||||
</component>
|
||||
<component id="82cc1" class="javax.swing.JButton" binding="buttonUp">
|
||||
<constraints>
|
||||
<grid row="1" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<grid row="1" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
@ -88,7 +88,7 @@
|
||||
</component>
|
||||
<component id="bb79e" class="javax.swing.JButton" binding="buttonDown">
|
||||
<constraints>
|
||||
<grid row="2" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<grid row="2" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
@ -101,12 +101,20 @@
|
||||
</component>
|
||||
<grid id="dfecd" binding="drawPanel" layout-manager="BorderLayout" hgap="0" vgap="0">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="5" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
<grid row="0" column="0" row-span="1" col-span="6" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<component id="34645" class="javax.swing.JButton" binding="buttonCreateModif">
|
||||
<constraints>
|
||||
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Modification"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
||||
|
@ -20,6 +20,7 @@ public class FormWarship extends JFrame {
|
||||
private JLabel toolBarLabelWieght;
|
||||
private JLabel toolBarLabelColor;
|
||||
private JPanel drawPanel;
|
||||
private JButton buttonCreateModif;
|
||||
|
||||
public FormWarship(){
|
||||
InitializeComponent();
|
||||
@ -28,6 +29,16 @@ public class FormWarship extends JFrame {
|
||||
drawingComponents.repaint();
|
||||
}
|
||||
|
||||
private void SetData(){
|
||||
Random rnd = new Random();
|
||||
_warship.SetPosition(rnd.nextInt(10, 100), rnd.nextInt(10, 100), drawPanel.getWidth(), drawPanel.getHeight());
|
||||
toolBarLabelSpeed.setText("Color: " + _warship.GetWarship().GetSpeed() + " ");
|
||||
toolBarLabelWieght.setText("Weight: " + _warship.GetWarship().GetWeight() + " ");
|
||||
toolBarLabelColor.setText("Color: " + _warship.GetWarship().GetBodyColor().getRed() + " " +
|
||||
_warship.GetWarship().GetBodyColor().getGreen() + " " + _warship.GetWarship().GetBodyColor().getBlue());
|
||||
}
|
||||
|
||||
|
||||
private void InitializeComponent(){
|
||||
setContentPane(mainPanel);
|
||||
setTitle("Warship");
|
||||
@ -46,17 +57,30 @@ public class FormWarship extends JFrame {
|
||||
|
||||
drawingComponents = new DrawingComponents();
|
||||
drawPanel.add(drawingComponents);
|
||||
|
||||
//кнопка добавления объекта
|
||||
buttonCreate.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Random rnd = new Random();
|
||||
_warship = new DrawingWarship(rnd.nextInt(200) + 100, rnd.nextInt(1000) + 1000,
|
||||
_warship = new DrawingWarship(rnd.nextInt(100,300), rnd.nextInt(1000, 2000),
|
||||
new Color(rnd.nextInt(256),rnd.nextInt(256),rnd.nextInt(256)));
|
||||
_warship.SetPosition(rnd.nextInt(90) + 10, rnd.nextInt(90) + 10, drawPanel.getWidth(), drawPanel.getHeight());
|
||||
toolBarLabelSpeed.setText("Color: " + _warship.GetWarship().GetSpeed() + " ");
|
||||
toolBarLabelWieght.setText("Weight: " + _warship.GetWarship().GetWeight() + " ");
|
||||
toolBarLabelColor.setText("Color: " + _warship.GetWarship().GetBodyColor().getRed() + " " +
|
||||
_warship.GetWarship().GetBodyColor().getGreen() + " " + _warship.GetWarship().GetBodyColor().getBlue());
|
||||
SetData();
|
||||
drawingComponents.SetDrawingWarship(_warship);
|
||||
Draw();
|
||||
}
|
||||
});
|
||||
|
||||
//добавление модифицированного объекта
|
||||
buttonCreateModif.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Random rnd = new Random();
|
||||
_warship = new DrawingAircraftCarrier(rnd.nextInt(100, 300) , rnd.nextInt(1000, 2000),
|
||||
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(), rnd.nextBoolean());
|
||||
SetData();
|
||||
drawingComponents.SetDrawingWarship(_warship);
|
||||
Draw();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user