модификация добавленна

This commit is contained in:
Макс Бондаренко 2022-11-29 00:17:16 +04:00
parent 1c30871417
commit e5a1bec005
3 changed files with 60 additions and 24 deletions

View File

@ -3,14 +3,14 @@ import java.awt.*;
import java.util.*;
public class DrawingShip extends JPanel {
private EntityWarmlyShip warmlyShip; //Класс-сущность
public EntityWarmlyShip warmlyShip; //Класс-сущность
public EntityWarmlyShip GetWarmlyShip(){return warmlyShip;}
public float _startPosX; //Координаты отрисовки по оси x
public float _startPosY; //Координаты отрисовки по оси y
private Integer _pictureWidth = null; //Ширина окна
private Integer _pictureHeight = null; //Высота окна
private final int _warmlyShipWidth = 125; //Ширина отрисовки корабля
private final int _warmlyShipHeight = 50; //Высота отрисовки корабля
protected int _warmlyShipWidth = 125; //Ширина отрисовки корабля
protected int _warmlyShipHeight = 50; //Высота отрисовки корабля
private int deckCount = 1;
private DrawDeck dd = new DrawDeck();
@ -23,6 +23,13 @@ public class DrawingShip extends JPanel {
dd.SetDeckCount(random.nextInt(1, 4));
}
protected DrawingShip(int speed, float weight, Color bodyColor, int warmlyWidth, int warmlyHeight)
{
this(speed, weight, bodyColor);
_warmlyShipWidth = warmlyWidth;
_warmlyShipHeight = warmlyHeight;
}
//Начальные коордитанты
public void SetPosition(int x, int y, int width, int height)
{

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormShip">
<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="20" y="20" width="500" height="400"/>
@ -13,7 +13,7 @@
<children>
<component id="2ea16" 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"/>
@ -25,7 +25,7 @@
</component>
<component id="4eb88" 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"/>
@ -38,7 +38,7 @@
</component>
<component id="fb937" 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"/>
@ -50,7 +50,7 @@
</component>
<toolbar id="e747d" binding="statusStrip">
<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">
<minimum-size width="-1" height="20"/>
<preferred-size width="-1" height="20"/>
<maximum-size width="-1" height="20"/>
@ -62,16 +62,6 @@
<border type="none"/>
<children/>
</toolbar>
<hspacer id="d6bea">
<constraints>
<grid row="1" column="1" row-span="1" col-span="2" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<hspacer id="d86ff">
<constraints>
<grid row="2" column="0" row-span="1" col-span="2" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<component id="9e2ce" class="javax.swing.JButton" binding="buttonCreate">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="1" indent="0" use-parent-layout="false">
@ -84,7 +74,7 @@
</component>
<component id="4f60a" 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"/>
@ -96,12 +86,32 @@
</component>
<grid id="8b0ad" binding="GraphicsOutput" layout-manager="FlowLayout" hgap="5" vgap="5" flow-align="1">
<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="bbe04" class="javax.swing.JButton" binding="buttonCreateModif">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="122" height="30"/>
</grid>
</constraints>
<properties>
<text value="Модификация"/>
</properties>
</component>
<hspacer id="a48ad">
<constraints>
<grid row="1" column="2" row-span="1" col-span="2" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<hspacer id="b7fa3">
<constraints>
<grid row="2" column="0" row-span="1" col-span="3" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
</children>
</grid>
</form>

View File

@ -15,6 +15,7 @@ public class FormShip extends JFrame{
private JButton buttonUp;
private JButton buttonDown;
private JPanel GraphicsOutput;
private JButton buttonCreateModif;
private JLabel JLabelSpeed = new JLabel();
private JLabel JLabelWeight = new JLabel();
private JLabel JLabelColor = new JLabel();
@ -36,6 +37,15 @@ public class FormShip extends JFrame{
validate();
}
private void SetData()
{
Random random = new Random();
ship.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100), GraphicsOutput.getWidth(), GraphicsOutput.getHeight());
JLabelSpeed.setText("орость: " + ship.GetWarmlyShip().GetSpeed() + " ");
JLabelWeight.setText("Вес: " + ship.GetWarmlyShip().GetWeight() + " ");
JLabelColor.setText(("Цвет: " + ship.GetWarmlyShip().GetBodyColor() + " "));
}
private void ButtonMove_Click(String name)
{
if (ship == null) return;
@ -84,10 +94,7 @@ public class FormShip extends JFrame{
public void actionPerformed(ActionEvent e) {
Random random = new Random();
ship = new DrawingShip(random.nextInt(100, 300), random.nextInt(1000, 2000), new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256)));
ship.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100), GraphicsOutput.getWidth(), GraphicsOutput.getHeight());
JLabelSpeed.setText("орость: " + ship.GetWarmlyShip().GetSpeed() + " ");
JLabelWeight.setText("Вес: " + ship.GetWarmlyShip().GetWeight() + " ");
JLabelColor.setText(("Цвет: " + ship.GetWarmlyShip().GetBodyColor() + " "));
SetData();
Draw();
}
});
@ -125,5 +132,17 @@ public class FormShip extends JFrame{
Draw();
}
});
buttonCreateModif.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Random random = new Random();
ship = new DrawningMotorShip(random.nextInt(100, 300), random.nextInt(1000, 3000),
new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256)),
new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256)),
random.nextBoolean(), random.nextBoolean());
SetData();
Draw();
}
});
}
}