PIBD-11 Ryabov I.V. LabWork02 Hard #5
124
ProjectStormtrooper/.idea/uiDesigner.xml
Normal file
124
ProjectStormtrooper/.idea/uiDesigner.xml
Normal file
@ -0,0 +1,124 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Palette2">
|
||||
<group name="Swing">
|
||||
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
|
||||
</item>
|
||||
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
|
||||
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
|
||||
<initial-values>
|
||||
<property name="text" value="Button" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="RadioButton" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="CheckBox" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="Label" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||
<preferred-size width="200" height="200" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||
<preferred-size width="200" height="200" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
|
||||
<preferred-size width="-1" height="20" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
|
||||
</item>
|
||||
</group>
|
||||
</component>
|
||||
</project>
|
16
ProjectStormtrooper/src/CanvasStormtrooper.java
Normal file
16
ProjectStormtrooper/src/CanvasStormtrooper.java
Normal file
@ -0,0 +1,16 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class CanvasStormtrooper extends JComponent {
|
||||
public DrawingStormtrooper _drawingStormtrooper;
|
||||
public CanvasStormtrooper(){}
|
||||
public void paintComponent(Graphics g) {
|
||||
if (_drawingStormtrooper == null) {
|
||||
return;
|
||||
}
|
||||
super.paintComponents(g);
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
_drawingStormtrooper.DrawTransport(g2d);
|
||||
super.repaint();
|
||||
}
|
||||
}
|
10
ProjectStormtrooper/src/DirectionType.java
Normal file
10
ProjectStormtrooper/src/DirectionType.java
Normal file
@ -0,0 +1,10 @@
|
||||
public enum DirectionType {
|
||||
///Вверх
|
||||
Up,
|
||||
///Вниз
|
||||
Down,
|
||||
///Влево
|
||||
Left,
|
||||
///Вправо
|
||||
Right
|
||||
}
|
21
ProjectStormtrooper/src/DrawingEngines.java
Normal file
21
ProjectStormtrooper/src/DrawingEngines.java
Normal file
@ -0,0 +1,21 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawingEngines {
|
||||
private NumberOfEngines numberOfEngines;
|
||||
|
||||
public NumberOfEngines getNumberOfEngines() {
|
||||
return numberOfEngines;
|
||||
}
|
||||
DrawingEngines (int a){
|
||||
setAmountOfEngines(a);
|
||||
}
|
||||
public void setAmountOfEngines(int amount){
|
||||
if(NumberOfEngines.contains(amount)) {
|
||||
numberOfEngines = NumberOfEngines.getNumber(amount);
|
||||
}
|
||||
}
|
||||
public void DrawDecks(Graphics g, int x, int y, int width, int height, Color bodyColor) {
|
||||
g.setColor(bodyColor);
|
||||
g.fillRect(x, y, width, height);
|
||||
}
|
||||
}
|
249
ProjectStormtrooper/src/DrawingStormtrooper.java
Normal file
249
ProjectStormtrooper/src/DrawingStormtrooper.java
Normal file
@ -0,0 +1,249 @@
|
||||
import java.awt.*;
|
||||
import java.util.Random;
|
||||
|
||||
public class DrawingStormtrooper {
|
||||
public EntityStormtrooper EntityStormtrooper;
|
||||
public DrawingEngines drawingEngines =null;
|
||||
/// <summary>
|
||||
/// Ширина окна
|
||||
/// </summary>
|
||||
private Integer _pictureWidth;
|
||||
|
||||
/// <summary>
|
||||
/// Высота окна
|
||||
/// </summary>
|
||||
private Integer _pictureHeight;
|
||||
|
||||
/// <summary>
|
||||
/// Левая координата прорисовки бомбардировщика
|
||||
/// </summary>
|
||||
private Integer _startPosX;
|
||||
|
||||
/// <summary>
|
||||
/// Верхняя кооридната прорисовки бомбардировщика
|
||||
/// </summary>
|
||||
private Integer _startPosY;
|
||||
|
||||
/// <summary>
|
||||
/// Ширина прорисовки бомбардировщика
|
||||
/// </summary>
|
||||
private final Integer _drawningStormtrooperWidth = 140;
|
||||
|
||||
/// <summary>
|
||||
/// Высота прорисовки бомбардировщика
|
||||
/// </summary>
|
||||
private final Integer _drawningStormtrooperHeight = 135;
|
||||
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="engines">Признак наличия двигателей</param>
|
||||
/// <param name="bombs">Признак наличия бомб</param>
|
||||
/// <param name="rockets">Признак наличия ракет</param>
|
||||
public void Init(int speed, float weight, Color bodyColor, Color additionalColor,boolean rockets, boolean bombs, boolean engines)
|
||||
{
|
||||
EntityStormtrooper = new EntityStormtrooper();
|
||||
EntityStormtrooper.Init(speed, weight, bodyColor, additionalColor, rockets,bombs ,engines);
|
||||
if(engines==true){
|
||||
drawingEngines = new DrawingEngines((int)((Math.random()*3)+1)*2);
|
||||
}
|
||||
_startPosX=null;
|
||||
_startPosY=null;
|
||||
_pictureWidth = null;
|
||||
_pictureHeight = null;
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Установка границ поля
|
||||
/// </summary>
|
||||
/// <param name="width">Ширина поля</param>
|
||||
/// <param name="height">Высота поля</param>
|
||||
/// <returns> true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах</returns>
|
||||
public boolean SetPictureSize(int width, int height)
|
||||
{
|
||||
// TODO проверка, что объект "влезает" в размеры поля
|
||||
// если влезает, сохраняем границы и корректируем позицию объекта, если она была уже установлена
|
||||
if (width < _drawningStormtrooperWidth || height < _drawningStormtrooperHeight) return false;
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
if (_startPosX !=null || _startPosY !=null)
|
||||
{
|
||||
if (_startPosX + _drawningStormtrooperWidth > _pictureWidth)
|
||||
{
|
||||
_startPosX = -_drawningStormtrooperWidth + _pictureWidth;
|
||||
}
|
||||
else if (_startPosX < 0)
|
||||
{
|
||||
_startPosX = 0;
|
||||
}
|
||||
if (_startPosY + _drawningStormtrooperHeight > _pictureHeight)
|
||||
{
|
||||
_startPosY = -_drawningStormtrooperHeight + _pictureHeight;
|
||||
}
|
||||
else if (_startPosY < 0)
|
||||
{
|
||||
_startPosY = 0;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
/// Установка позиции
|
||||
/// </summary>
|
||||
/// <param name="x">Координата X</param>
|
||||
/// <param name="y">Координата Y</param>
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
if (!(_pictureHeight != null && _pictureWidth != null)) return;
|
||||
// TODO если при установке объекта в эти координаты, он будет "выходить" за границы формы
|
||||
// то надо изменить координаты, чтобы он оставался в этих границах
|
||||
if (x + _drawningStormtrooperWidth > _pictureWidth)
|
||||
{
|
||||
_startPosX = x - (x + _drawningStormtrooperWidth - _pictureWidth);
|
||||
}
|
||||
else if (x < 0)
|
||||
{
|
||||
_startPosX = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
_startPosX = x;
|
||||
}
|
||||
if (y + _drawningStormtrooperHeight > _pictureHeight)
|
||||
{
|
||||
_startPosY = y - (y + _drawningStormtrooperHeight - _pictureHeight);
|
||||
}
|
||||
else if (y < 0)
|
||||
{
|
||||
_startPosY = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
_startPosY = y;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Изменение направления перемещения
|
||||
/// </summary>
|
||||
/// <param name="direction">Направление</param>
|
||||
/// <returns>true - перемещене выполнено, false - перемещение невозможно</returns>
|
||||
public boolean MoveTransport(DirectionType direction)
|
||||
{
|
||||
if (EntityStormtrooper == null || _startPosX==null || _startPosY==null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
switch (direction)
|
||||
{
|
||||
//влево
|
||||
case DirectionType.Left:
|
||||
if (_startPosX - EntityStormtrooper.Step > 0)
|
||||
{
|
||||
_startPosX -= (int)EntityStormtrooper.Step;
|
||||
}
|
||||
return true;
|
||||
//вверх
|
||||
case DirectionType.Up:
|
||||
if (_startPosY - EntityStormtrooper.Step > 0)
|
||||
{
|
||||
_startPosY -= (int)EntityStormtrooper.Step;
|
||||
}
|
||||
return true;
|
||||
// вправо
|
||||
case DirectionType.Right:
|
||||
//TODO прописать логику сдвига в право
|
||||
if (_startPosX + _drawningStormtrooperWidth + EntityStormtrooper.Step < _pictureWidth)
|
||||
{
|
||||
_startPosX += (int)EntityStormtrooper.Step;
|
||||
};
|
||||
return true;
|
||||
//вниз
|
||||
case DirectionType.Down:
|
||||
//TODO прописать логику сдвига в вниз
|
||||
if (_startPosY + _drawningStormtrooperHeight + EntityStormtrooper.Step < _pictureHeight)
|
||||
{
|
||||
_startPosY += (int)EntityStormtrooper.Step;
|
||||
}
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Прорисовка объекта
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityStormtrooper == null || _startPosX==null || _startPosY==null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
g.setColor(Color.black);
|
||||
//Brush bodyColorBrush = new SolidBrush(EntityStormtrooper.BodyColor);
|
||||
//Brush additionalBrush = new SolidBrush(EntityStormtrooper.AdditionalColor);
|
||||
//Тело бомбардировщика
|
||||
g.drawRect(_startPosX + 20, _startPosY + 60, 120, 20);
|
||||
//Задние крылья бомбардировщика
|
||||
g.drawLine(_startPosX+ 140, _startPosY+ 30, _startPosX+ 140, _startPosY+ 110);
|
||||
g.drawLine(_startPosX+ 120, _startPosY+ 90, _startPosX+ 120, _startPosY+ 80);
|
||||
g.drawLine(_startPosX+ 140, _startPosY+ 110, _startPosX + 120, _startPosY + 90);
|
||||
g.drawLine(_startPosX+ 140, _startPosY+ 30, _startPosX+ 120, _startPosY+ 50);
|
||||
g.drawLine(_startPosX+ 120, _startPosY+ 50, _startPosX+ 120, _startPosY+ 60);
|
||||
//Крылья бомбардировщика
|
||||
g.drawLine(_startPosX+ 50, _startPosY, _startPosX + 50, _startPosY + 60);
|
||||
g.drawLine(_startPosX+ 50, _startPosY + 80, _startPosX + 50, _startPosY + 135);
|
||||
g.drawLine(_startPosX+ 50, _startPosY + 135, _startPosX + 60, _startPosY + 135);
|
||||
g.drawLine(_startPosX+ 60, _startPosY + 135, _startPosX + 65, _startPosY + 80);
|
||||
g.drawLine(_startPosX+ 50, _startPosY, _startPosX + 60, _startPosY);
|
||||
g.drawLine(_startPosX+ 60, _startPosY, _startPosX + 65, _startPosY + 60);
|
||||
///Нос бомбардировщика
|
||||
Point[] Nose = new Point[3];
|
||||
int[] arrX = {_startPosX + 20, _startPosX,_startPosX+20};
|
||||
int[] arrY = {_startPosY + 80,_startPosY + 70,_startPosY + 60};
|
||||
Polygon poly = new Polygon(arrX,arrY,3);
|
||||
g.fillPolygon(poly);
|
||||
//Ракеты бомбардировщика
|
||||
if (EntityStormtrooper.getRockets())
|
||||
{
|
||||
g.setColor(EntityStormtrooper.getAdditionalColor());
|
||||
g.fillRect( _startPosX + 35, _startPosY + 20, 15, 5);
|
||||
g.fillRect( _startPosX + 35, _startPosY + 110, 15, 5);
|
||||
|
||||
}
|
||||
//Бомбы бомбардировщика
|
||||
if (EntityStormtrooper.getBombs())
|
||||
{
|
||||
g.setColor(EntityStormtrooper.getAdditionalColor());
|
||||
g.fillRect(_startPosX + 40, _startPosY + 40, 10, 10);
|
||||
g.fillRect(_startPosX + 40, _startPosY + 90, 10, 10);
|
||||
}
|
||||
if(EntityStormtrooper.getEngines() && drawingEngines!=null){
|
||||
switch(drawingEngines.getNumberOfEngines()){
|
||||
case TWO:
|
||||
drawingEngines.DrawDecks(g,_startPosX + 65, _startPosY + 50, 10, 10,EntityStormtrooper.getBodyColor());
|
||||
drawingEngines.DrawDecks(g,_startPosX + 65, _startPosY + 81, 10, 10,EntityStormtrooper.getBodyColor());
|
||||
break;
|
||||
case FOUR:
|
||||
drawingEngines.DrawDecks(g,_startPosX + 62, _startPosY + 10, 10, 10,EntityStormtrooper.getBodyColor());
|
||||
drawingEngines.DrawDecks(g,_startPosX + 64, _startPosY + 101, 10, 10,EntityStormtrooper.getBodyColor());
|
||||
drawingEngines.DrawDecks(g,_startPosX + 64, _startPosY + 30, 10, 10,EntityStormtrooper.getBodyColor());
|
||||
drawingEngines.DrawDecks(g,_startPosX + 62, _startPosY + 121, 10, 10,EntityStormtrooper.getBodyColor());
|
||||
break;
|
||||
case SIX:
|
||||
drawingEngines.DrawDecks(g,_startPosX + 62, _startPosY + 10, 10, 10,EntityStormtrooper.getBodyColor());
|
||||
drawingEngines.DrawDecks(g,_startPosX + 64, _startPosY + 30, 10, 10,EntityStormtrooper.getBodyColor());
|
||||
drawingEngines.DrawDecks(g,_startPosX + 65, _startPosY + 50, 10, 10,EntityStormtrooper.getBodyColor());
|
||||
drawingEngines.DrawDecks(g,_startPosX + 65, _startPosY + 81, 10, 10,EntityStormtrooper.getBodyColor());
|
||||
drawingEngines.DrawDecks(g,_startPosX + 64, _startPosY + 101, 10, 10,EntityStormtrooper.getBodyColor());
|
||||
drawingEngines.DrawDecks(g,_startPosX + 62, _startPosY + 121, 10, 10,EntityStormtrooper.getBodyColor());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
42
ProjectStormtrooper/src/EntityStormtrooper.java
Normal file
42
ProjectStormtrooper/src/EntityStormtrooper.java
Normal file
@ -0,0 +1,42 @@
|
||||
import java.awt.*;
|
||||
public class EntityStormtrooper {
|
||||
private int Speed;
|
||||
public int getSpeed() {
|
||||
return Speed;
|
||||
}
|
||||
private float Weight;
|
||||
public float getWeight() {
|
||||
return Weight;
|
||||
}
|
||||
private Color BodyColor;
|
||||
public Color getBodyColor() {
|
||||
return BodyColor;
|
||||
}
|
||||
|
||||
private Color AdditionalColor;
|
||||
public Color getAdditionalColor() {
|
||||
return AdditionalColor;
|
||||
}
|
||||
private boolean Rockets;
|
||||
public boolean getRockets() {
|
||||
return Rockets;
|
||||
}
|
||||
private boolean Bombs;
|
||||
public boolean getBombs() {
|
||||
return Bombs;
|
||||
}
|
||||
private boolean Engines;
|
||||
public boolean getEngines() {return Engines;}
|
||||
public float Step;
|
||||
public void Init(int speed, float weight, Color bodyColor, Color additionalColor, boolean rockets, boolean bombs, boolean engines)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
AdditionalColor = additionalColor;
|
||||
Rockets = rockets;
|
||||
Bombs = bombs;
|
||||
Engines = engines;
|
||||
Step = Speed * 100 / Weight;
|
||||
}
|
||||
}
|
125
ProjectStormtrooper/src/FormStormtrooper.java
Normal file
125
ProjectStormtrooper/src/FormStormtrooper.java
Normal file
@ -0,0 +1,125 @@
|
||||
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.Random;
|
||||
|
||||
public class FormStormtrooper extends JFrame {
|
||||
private String title;
|
||||
private Dimension dimension;
|
||||
private int Width;
|
||||
private int Height;
|
||||
private CanvasStormtrooper canvasStormtrooper = new CanvasStormtrooper();
|
||||
private JButton CreateButton = new JButton("Создать");;
|
||||
private JButton UpButton = new JButton();
|
||||
private JButton DownButton = new JButton();;
|
||||
private JButton LeftButton = new JButton();;
|
||||
private JButton RightButton = new JButton();
|
||||
public FormStormtrooper(String title, Dimension dimension) {
|
||||
this.title = title;
|
||||
this.dimension = dimension;
|
||||
}
|
||||
public void Init() {
|
||||
setTitle(title);
|
||||
setMinimumSize(dimension);
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
Width = getWidth() - 15;
|
||||
Height = getHeight() - 35;
|
||||
|
||||
CreateButton.setName("createButton");
|
||||
Icon iconUp = new ImageIcon("src\\Resources\\arrowUp.png");
|
||||
UpButton.setIcon(iconUp);
|
||||
UpButton.setName("UP");
|
||||
DownButton.setName("DOWN");
|
||||
Icon iconDown = new ImageIcon("src\\Resources\\arrowDown.png");
|
||||
DownButton.setIcon(iconDown);
|
||||
LeftButton.setName("LEFT");
|
||||
Icon iconLeft = new ImageIcon("src\\Resources\\arrowLeft.png");
|
||||
LeftButton.setIcon(iconLeft);
|
||||
RightButton.setName("RIGHT");
|
||||
Icon iconRight = new ImageIcon("arrowRight.png");
|
||||
RightButton.setIcon(iconRight);
|
||||
|
||||
CreateButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
int StartPositionX = (int)(Math.random() * 90 + 10);
|
||||
int StartPositionY = (int)(Math.random() * 90 + 10);
|
||||
int speed = (int)(Math.random() * 300 + 100);
|
||||
float weight = (float) (Math.random() * 3000 + 1000);
|
||||
Color bodyColor = new Color((int)(Math.random() * 255 + 0),(int)(Math.random() * 255 + 0),(int)(Math.random() * 255 + 0));
|
||||
Color additionalColor = new Color((int)(Math.random() * 255 + 0),(int)(Math.random() * 255 + 0),(int)(Math.random() * 255 + 0));;
|
||||
boolean rockets = new Random().nextBoolean();
|
||||
boolean boombs = new Random().nextBoolean();;
|
||||
boolean engines = new Random().nextBoolean();;
|
||||
canvasStormtrooper._drawingStormtrooper = new DrawingStormtrooper();
|
||||
canvasStormtrooper._drawingStormtrooper.Init(speed, weight, bodyColor, additionalColor,rockets, boombs, engines);
|
||||
canvasStormtrooper._drawingStormtrooper.SetPictureSize(Width, Height);
|
||||
canvasStormtrooper._drawingStormtrooper.SetPosition( StartPositionX, StartPositionY);
|
||||
canvasStormtrooper.repaint();
|
||||
}
|
||||
});
|
||||
|
||||
ActionListener actionListener = new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
if (canvasStormtrooper._drawingStormtrooper == null) return;
|
||||
boolean result = false;
|
||||
switch ((((JButton)(event.getSource())).getName())) {
|
||||
case "UP":
|
||||
result = canvasStormtrooper._drawingStormtrooper.MoveTransport(DirectionType.Up);
|
||||
break;
|
||||
case "DOWN":
|
||||
result = canvasStormtrooper._drawingStormtrooper.MoveTransport(DirectionType.Down);
|
||||
break;
|
||||
case "LEFT":
|
||||
result = canvasStormtrooper._drawingStormtrooper.MoveTransport(DirectionType.Left);
|
||||
break;
|
||||
case "RIGHT":
|
||||
result = canvasStormtrooper._drawingStormtrooper.MoveTransport(DirectionType.Right);
|
||||
break;
|
||||
}
|
||||
if (result) {
|
||||
canvasStormtrooper.repaint();
|
||||
}
|
||||
}
|
||||
};
|
||||
UpButton.addActionListener(actionListener);
|
||||
DownButton.addActionListener(actionListener);
|
||||
LeftButton.addActionListener(actionListener);
|
||||
RightButton.addActionListener(actionListener);
|
||||
|
||||
setSize(dimension.width,dimension.height);
|
||||
setLayout(null);
|
||||
canvasStormtrooper.setBounds(0,0, getWidth(), getHeight());
|
||||
CreateButton.setBounds(10, getHeight() - 90, 100, 40);
|
||||
UpButton.setBounds(getWidth() - 140, getHeight() - 160, 50, 50);
|
||||
DownButton.setBounds(getWidth() - 140, getHeight() - 100, 50, 50);
|
||||
RightButton.setBounds(getWidth() - 80, getHeight() - 100, 50, 50);
|
||||
LeftButton.setBounds(getWidth() - 200, getHeight() - 100, 50, 50);
|
||||
add(CreateButton);
|
||||
add(UpButton);
|
||||
add(DownButton);
|
||||
add(RightButton);
|
||||
add(LeftButton);
|
||||
add(canvasStormtrooper);
|
||||
setVisible(true);
|
||||
//обработка события изменения размеров окна
|
||||
addComponentListener(new ComponentAdapter() {
|
||||
public void componentResized(ComponentEvent e) {
|
||||
Width = getWidth() - 15;
|
||||
Height = getHeight() - 35;
|
||||
if (canvasStormtrooper._drawingStormtrooper != null)
|
||||
canvasStormtrooper._drawingStormtrooper.SetPictureSize(Width, Height);
|
||||
canvasStormtrooper.setBounds(0,0, getWidth(), getHeight());
|
||||
CreateButton.setBounds(10, getHeight() - 90, 100, 40);
|
||||
UpButton.setBounds(getWidth() - 140, getHeight() - 160, 50, 50);
|
||||
DownButton.setBounds(getWidth() - 140, getHeight() - 100, 50, 50);
|
||||
RightButton.setBounds(getWidth() - 80, getHeight() - 100, 50, 50);
|
||||
LeftButton.setBounds(getWidth() - 200, getHeight() - 100, 50, 50);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -1,5 +1,8 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Hello world!");
|
||||
FormStormtrooper form = new FormStormtrooper("Бомбардировщик", new Dimension(800,800));
|
||||
form.Init();
|
||||
}
|
||||
}
|
28
ProjectStormtrooper/src/NumberOfEngines.java
Normal file
28
ProjectStormtrooper/src/NumberOfEngines.java
Normal file
@ -0,0 +1,28 @@
|
||||
public enum NumberOfEngines {
|
||||
TWO(2),
|
||||
FOUR(4),
|
||||
SIX(6);
|
||||
|
||||
private final int value;
|
||||
NumberOfEngines(int value){
|
||||
this.value=value;
|
||||
}
|
||||
public static NumberOfEngines getNumber(int amount){
|
||||
NumberOfEngines [] num = NumberOfEngines.values();
|
||||
for(int i =0 ; i <num.length;i++){
|
||||
if(amount==num[i].value){
|
||||
return num[i];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public static boolean contains(int amount){
|
||||
NumberOfEngines [] num = NumberOfEngines.values();
|
||||
for(int i =0 ; i <num.length;i++){
|
||||
if(amount==num[i].value){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user