Добавлены некоторые классы и форма
This commit is contained in:
parent
b057110fbe
commit
cc5bd478e0
4
.idea/misc.xml
generated
4
.idea/misc.xml
generated
@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11.0.5" project-jdk-type="JavaSDK">
|
||||||
<output url="file://$PROJECT_DIR$/../../../ирино, не трогат!!/!/!/RPP/ProjectAircraftCarrierHard/out" />
|
<output url="file://$PROJECT_DIR$/../../../ирино, не трогат/!/!/!/!/RPP/ProjectAircraftCarrierHard/out" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
6
src/Direction.java
Normal file
6
src/Direction.java
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
public enum Direction {
|
||||||
|
Up,
|
||||||
|
Down,
|
||||||
|
Left,
|
||||||
|
Right;
|
||||||
|
}
|
125
src/DrawingWarship.java
Normal file
125
src/DrawingWarship.java
Normal file
@ -0,0 +1,125 @@
|
|||||||
|
import java.awt.*;
|
||||||
|
import java.util.Random;
|
||||||
|
public class DrawingWarship {
|
||||||
|
private EntityWarship Warship;
|
||||||
|
|
||||||
|
public EntityWarship GetWarship(){return Warship;}
|
||||||
|
|
||||||
|
private int _startPosX;
|
||||||
|
private int _startPosY;
|
||||||
|
|
||||||
|
private Integer _pictureWidth = null;
|
||||||
|
private Integer _pictureHeight = null;
|
||||||
|
|
||||||
|
private final int _warshipWidth = 114;
|
||||||
|
private final int _warshipHeight = 40;
|
||||||
|
|
||||||
|
public void Init(int speed, float weight, Color bodyColor)
|
||||||
|
{
|
||||||
|
Warship = new EntityWarship();
|
||||||
|
Warship.Init(speed, weight, bodyColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetPosition(int x, int y, int width, int height)
|
||||||
|
{
|
||||||
|
if (width >= x + _warshipWidth && height >= y + _warshipHeight && x >= 0 && y >= 0)
|
||||||
|
{
|
||||||
|
_startPosX = x;
|
||||||
|
_startPosY = y;
|
||||||
|
_pictureWidth = width;
|
||||||
|
_pictureHeight = height;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void MoveTransport(Direction direction)
|
||||||
|
{
|
||||||
|
if (_pictureWidth == null || _pictureHeight == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
switch (direction)
|
||||||
|
{
|
||||||
|
// вправо
|
||||||
|
case Right:
|
||||||
|
if (_startPosX + _warshipWidth + Warship.Step < _pictureWidth)
|
||||||
|
{
|
||||||
|
_startPosX += Warship.Step;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
//влево
|
||||||
|
case Left:
|
||||||
|
if(_startPosX - Warship.Step > 0)
|
||||||
|
{
|
||||||
|
_startPosX -= Warship.Step;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
//вверх
|
||||||
|
case Up:
|
||||||
|
if (_startPosY - Warship.Step > 0)
|
||||||
|
{
|
||||||
|
_startPosY -= Warship.Step;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
//вниз
|
||||||
|
case Down:
|
||||||
|
if (_startPosY + _warshipHeight + Warship.Step < _pictureHeight)
|
||||||
|
{
|
||||||
|
_startPosY += Warship.Step;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void DrawTransport(Graphics g){
|
||||||
|
if (_startPosX < 0 || _startPosY < 0 || _pictureHeight == null || _pictureWidth == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Graphics2D g2 = (Graphics2D) g;
|
||||||
|
//главная палуба
|
||||||
|
int[] pointXWarship = {_startPosX + 4, _startPosX + 94, _startPosX + 114, _startPosX + 94, _startPosX + 4};
|
||||||
|
int[] pointYWarship = {_startPosY, _startPosY, _startPosY + 20, _startPosY + 40, _startPosY + 40};
|
||||||
|
g2.setColor(Warship.GetBodyColor());
|
||||||
|
g2.fillPolygon(pointXWarship, pointYWarship, 5);
|
||||||
|
g2.setColor(Color.BLACK);
|
||||||
|
g2.drawPolygon(pointXWarship, pointYWarship, 5);
|
||||||
|
|
||||||
|
//мачта
|
||||||
|
g2.setColor(Color.WHITE);
|
||||||
|
g2.fillOval(_startPosX + 80, _startPosY + 13, 15, 15);
|
||||||
|
//границы мачты
|
||||||
|
g2.setColor(Color.BLACK);
|
||||||
|
g2.drawOval( _startPosX + 80, _startPosY + 13, 15, 15);
|
||||||
|
|
||||||
|
//палуба
|
||||||
|
g2.setColor(Color.WHITE);
|
||||||
|
g2.fillRect(_startPosX + 70, _startPosY + 10, 8, 18);
|
||||||
|
g2.fillRect(_startPosX + 55, _startPosY + 15, 15, 8);
|
||||||
|
//границы палубы
|
||||||
|
g2.setColor(Color.BLACK);
|
||||||
|
g2.drawRect(_startPosX + 70, _startPosY + 10, 8, 18);
|
||||||
|
g2.drawRect(_startPosX + 55, _startPosY + 15, 15, 8);
|
||||||
|
|
||||||
|
//двигатели
|
||||||
|
g2.fillRect(_startPosX, _startPosY + 5, 4, 10);
|
||||||
|
g2.fillRect(_startPosX, _startPosY + 23, 4, 10);
|
||||||
|
|
||||||
|
}
|
||||||
|
public void ChangeBorders(int width, int height)
|
||||||
|
{
|
||||||
|
_pictureWidth = width;
|
||||||
|
_pictureHeight = height;
|
||||||
|
if (_pictureWidth <= _warshipWidth || _pictureHeight <= _warshipHeight)
|
||||||
|
{
|
||||||
|
_pictureWidth = null;
|
||||||
|
_pictureHeight = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (_startPosX + _warshipWidth > _pictureWidth)
|
||||||
|
{
|
||||||
|
_startPosX = _pictureWidth - _warshipWidth;
|
||||||
|
}
|
||||||
|
if (_startPosY + _warshipHeight > _pictureHeight)
|
||||||
|
{
|
||||||
|
_startPosY = _pictureHeight - _warshipHeight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
23
src/EntityWarship.java
Normal file
23
src/EntityWarship.java
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
import java.awt.*;
|
||||||
|
import java.util.Random;
|
||||||
|
public class EntityWarship {
|
||||||
|
private int Speed;
|
||||||
|
public int GetSpeed(){return Speed;}
|
||||||
|
|
||||||
|
private float Weight;
|
||||||
|
public float GetWeight(){return Weight;}
|
||||||
|
|
||||||
|
private Color BodyColor ;
|
||||||
|
public Color GetBodyColor (){return BodyColor;}
|
||||||
|
|
||||||
|
public float Step;
|
||||||
|
public void Init(int speed, float weight, Color bodyColor)
|
||||||
|
{
|
||||||
|
Random rnd = new Random();
|
||||||
|
Speed = speed <= 0 ? rnd.nextInt(100) + 50 : speed;
|
||||||
|
Weight = weight <= 0 ? rnd.nextInt(30)+40 : weight;
|
||||||
|
BodyColor= bodyColor;
|
||||||
|
Step = Speed * 2000 / Weight;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
89
src/FormWarship.form
Normal file
89
src/FormWarship.form
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
<?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">
|
||||||
|
<margin top="0" left="0" bottom="0" right="0"/>
|
||||||
|
<constraints>
|
||||||
|
<xy x="20" y="20" width="993" height="515"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children>
|
||||||
|
<component id="80b72" class="javax.swing.JButton" binding="buttonCreate">
|
||||||
|
<constraints>
|
||||||
|
<grid row="2" column="0" 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="Create"/>
|
||||||
|
</properties>
|
||||||
|
</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"/>
|
||||||
|
</constraints>
|
||||||
|
</hspacer>
|
||||||
|
<vspacer id="588c1">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
</vspacer>
|
||||||
|
<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">
|
||||||
|
<minimum-size width="40" height="40"/>
|
||||||
|
<preferred-size width="40" height="40"/>
|
||||||
|
<maximum-size width="40" height="40"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value=" "/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<toolbar id="3697c" 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">
|
||||||
|
<preferred-size width="-1" height="20"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children/>
|
||||||
|
</toolbar>
|
||||||
|
<component id="9242f" 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">
|
||||||
|
<minimum-size width="40" height="40"/>
|
||||||
|
<preferred-size width="40" height="40"/>
|
||||||
|
<maximum-size width="40" height="40"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value=" "/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<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">
|
||||||
|
<minimum-size width="40" height="40"/>
|
||||||
|
<preferred-size width="40" height="40"/>
|
||||||
|
<maximum-size width="40" height="40"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value=" "/>
|
||||||
|
</properties>
|
||||||
|
</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">
|
||||||
|
<minimum-size width="40" height="40"/>
|
||||||
|
<preferred-size width="40" height="40"/>
|
||||||
|
<maximum-size width="40" height="40"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value=" "/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
</form>
|
32
src/FormWarship.java
Normal file
32
src/FormWarship.java
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class FormWarship extends JFrame {
|
||||||
|
|
||||||
|
private JPanel mainPanel;
|
||||||
|
private JButton buttonCreate;
|
||||||
|
private JButton buttonLeft;
|
||||||
|
private JButton buttonUp;
|
||||||
|
private JButton buttonDown;
|
||||||
|
private JButton buttonRight;
|
||||||
|
private JToolBar statusStrip;
|
||||||
|
|
||||||
|
public FormWarship(){
|
||||||
|
setContentPane(mainPanel);
|
||||||
|
setTitle("Warship");
|
||||||
|
setSize(900,700);
|
||||||
|
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
||||||
|
setVisible(true);
|
||||||
|
|
||||||
|
buttonCreate.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
Random rnd = new Random();
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,4 +1,6 @@
|
|||||||
public class Main {
|
public class Main {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
new FormWarship();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user