Правки
This commit is contained in:
parent
4937e3672f
commit
f13d7a60f8
BIN
ProjectStormtrooper/Resources/arrowDown.jpg
Normal file
BIN
ProjectStormtrooper/Resources/arrowDown.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 857 B |
BIN
ProjectStormtrooper/Resources/arrowLeft.jpg
Normal file
BIN
ProjectStormtrooper/Resources/arrowLeft.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 800 B |
BIN
ProjectStormtrooper/Resources/arrowRight.jpg
Normal file
BIN
ProjectStormtrooper/Resources/arrowRight.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 786 B |
BIN
ProjectStormtrooper/Resources/arrowUp.jpg
Normal file
BIN
ProjectStormtrooper/Resources/arrowUp.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 453 B |
@ -2,20 +2,44 @@ import java.awt.*;
|
|||||||
|
|
||||||
public class DrawingEngines {
|
public class DrawingEngines {
|
||||||
private NumberOfEngines numberOfEngines;
|
private NumberOfEngines numberOfEngines;
|
||||||
|
|
||||||
public NumberOfEngines getNumberOfEngines() {
|
public NumberOfEngines getNumberOfEngines() {
|
||||||
return numberOfEngines;
|
return numberOfEngines;
|
||||||
}
|
}
|
||||||
DrawingEngines (int a){
|
|
||||||
setAmountOfEngines(a);
|
|
||||||
}
|
|
||||||
public void setAmountOfEngines(int amount){
|
public void setAmountOfEngines(int amount){
|
||||||
if(NumberOfEngines.contains(amount)) {
|
if(NumberOfEngines.contains(amount)) {
|
||||||
numberOfEngines = NumberOfEngines.getNumber(amount);
|
numberOfEngines = NumberOfEngines.getNumber(amount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void DrawDecks(Graphics g, int x, int y, int width, int height, Color bodyColor) {
|
public void DrawEngines(Graphics g, int x, int y, Color bodyColor) {
|
||||||
g.setColor(bodyColor);
|
g.setColor(bodyColor);
|
||||||
g.fillRect(x, y, width, height);
|
g.fillRect(x, y, 10, 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void drawTwoEngines(Graphics g, int x, int y, Color bodyColor){
|
||||||
|
DrawEngines(g,x + 65, y + 50, bodyColor);
|
||||||
|
DrawEngines(g,x + 65, y + 81,bodyColor);
|
||||||
|
}
|
||||||
|
private void drawFourEngines(Graphics g, int x, int y, Color bodyColor){
|
||||||
|
DrawEngines(g,x + 62, y + 10,bodyColor);
|
||||||
|
DrawEngines(g,x + 64, y + 101,bodyColor);
|
||||||
|
DrawEngines(g,x + 64, y + 30,bodyColor);
|
||||||
|
DrawEngines(g,x + 62, y + 121,bodyColor);
|
||||||
|
}
|
||||||
|
private void drawSixEngines(Graphics g, int x, int y, Color bodyColor){
|
||||||
|
drawFourEngines(g,x,y,bodyColor);
|
||||||
|
drawTwoEngines(g,x,y,bodyColor);
|
||||||
|
}
|
||||||
|
public void SwitchDrawEngines(Graphics g, int x, int y, Color bodyColor){
|
||||||
|
switch(getNumberOfEngines()){
|
||||||
|
case TWO:
|
||||||
|
drawTwoEngines(g,x,y,bodyColor);
|
||||||
|
break;
|
||||||
|
case FOUR:
|
||||||
|
drawFourEngines(g,x,y,bodyColor);
|
||||||
|
break;
|
||||||
|
case SIX:
|
||||||
|
drawSixEngines(g,x,y,bodyColor);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,13 +49,13 @@ public class DrawingStormtrooper {
|
|||||||
EntityStormtrooper = new EntityStormtrooper();
|
EntityStormtrooper = new EntityStormtrooper();
|
||||||
EntityStormtrooper.Init(speed, weight, bodyColor, additionalColor, rockets,bombs ,engines);
|
EntityStormtrooper.Init(speed, weight, bodyColor, additionalColor, rockets,bombs ,engines);
|
||||||
if(engines==true){
|
if(engines==true){
|
||||||
drawingEngines = new DrawingEngines((int)((Math.random()*3)+1)*2);
|
drawingEngines = new DrawingEngines();
|
||||||
|
drawingEngines.setAmountOfEngines((int)((Math.random()*3)+1)*2);;
|
||||||
}
|
}
|
||||||
_startPosX=null;
|
_startPosX=null;
|
||||||
_startPosY=null;
|
_startPosY=null;
|
||||||
_pictureWidth = null;
|
_pictureWidth = null;
|
||||||
_pictureHeight = null;
|
_pictureHeight = null;
|
||||||
|
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Установка границ поля
|
/// Установка границ поля
|
||||||
@ -203,6 +203,7 @@ public class DrawingStormtrooper {
|
|||||||
g.drawLine(_startPosX+ 50, _startPosY, _startPosX + 60, _startPosY);
|
g.drawLine(_startPosX+ 50, _startPosY, _startPosX + 60, _startPosY);
|
||||||
g.drawLine(_startPosX+ 60, _startPosY, _startPosX + 65, _startPosY + 60);
|
g.drawLine(_startPosX+ 60, _startPosY, _startPosX + 65, _startPosY + 60);
|
||||||
///Нос бомбардировщика
|
///Нос бомбардировщика
|
||||||
|
g.setColor(EntityStormtrooper.getBodyColor());
|
||||||
Point[] Nose = new Point[3];
|
Point[] Nose = new Point[3];
|
||||||
int[] arrX = {_startPosX + 20, _startPosX,_startPosX+20};
|
int[] arrX = {_startPosX + 20, _startPosX,_startPosX+20};
|
||||||
int[] arrY = {_startPosY + 80,_startPosY + 70,_startPosY + 60};
|
int[] arrY = {_startPosY + 80,_startPosY + 70,_startPosY + 60};
|
||||||
@ -214,7 +215,6 @@ public class DrawingStormtrooper {
|
|||||||
g.setColor(EntityStormtrooper.getAdditionalColor());
|
g.setColor(EntityStormtrooper.getAdditionalColor());
|
||||||
g.fillRect( _startPosX + 35, _startPosY + 20, 15, 5);
|
g.fillRect( _startPosX + 35, _startPosY + 20, 15, 5);
|
||||||
g.fillRect( _startPosX + 35, _startPosY + 110, 15, 5);
|
g.fillRect( _startPosX + 35, _startPosY + 110, 15, 5);
|
||||||
|
|
||||||
}
|
}
|
||||||
//Бомбы бомбардировщика
|
//Бомбы бомбардировщика
|
||||||
if (EntityStormtrooper.getBombs())
|
if (EntityStormtrooper.getBombs())
|
||||||
@ -224,26 +224,7 @@ public class DrawingStormtrooper {
|
|||||||
g.fillRect(_startPosX + 40, _startPosY + 90, 10, 10);
|
g.fillRect(_startPosX + 40, _startPosY + 90, 10, 10);
|
||||||
}
|
}
|
||||||
if(EntityStormtrooper.getEngines() && drawingEngines!=null){
|
if(EntityStormtrooper.getEngines() && drawingEngines!=null){
|
||||||
switch(drawingEngines.getNumberOfEngines()){
|
drawingEngines.SwitchDrawEngines(g, _startPosX, _startPosY, EntityStormtrooper.getBodyColor());
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,6 @@ public class EntityStormtrooper {
|
|||||||
public Color getBodyColor() {
|
public Color getBodyColor() {
|
||||||
return BodyColor;
|
return BodyColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Color AdditionalColor;
|
private Color AdditionalColor;
|
||||||
public Color getAdditionalColor() {
|
public Color getAdditionalColor() {
|
||||||
return AdditionalColor;
|
return AdditionalColor;
|
||||||
|
@ -7,16 +7,16 @@ import java.awt.event.ComponentEvent;
|
|||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
public class FormStormtrooper extends JFrame {
|
public class FormStormtrooper extends JFrame {
|
||||||
private String title;
|
private final String title;
|
||||||
private Dimension dimension;
|
private final Dimension dimension;
|
||||||
private int Width;
|
private int Width;
|
||||||
private int Height;
|
private int Height;
|
||||||
private CanvasStormtrooper canvasStormtrooper = new CanvasStormtrooper();
|
private final CanvasStormtrooper canvasStormtrooper = new CanvasStormtrooper();
|
||||||
private JButton CreateButton = new JButton("Создать");;
|
private final JButton CreateButton = new JButton("Создать");
|
||||||
private JButton UpButton = new JButton();
|
private final JButton UpButton = new JButton();
|
||||||
private JButton DownButton = new JButton();;
|
private final JButton DownButton = new JButton();
|
||||||
private JButton LeftButton = new JButton();;
|
private final JButton LeftButton = new JButton();
|
||||||
private JButton RightButton = new JButton();
|
private final JButton RightButton = new JButton();
|
||||||
public FormStormtrooper(String title, Dimension dimension) {
|
public FormStormtrooper(String title, Dimension dimension) {
|
||||||
this.title = title;
|
this.title = title;
|
||||||
this.dimension = dimension;
|
this.dimension = dimension;
|
||||||
@ -25,23 +25,21 @@ public class FormStormtrooper extends JFrame {
|
|||||||
setTitle(title);
|
setTitle(title);
|
||||||
setMinimumSize(dimension);
|
setMinimumSize(dimension);
|
||||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
Width = getWidth() - 15;
|
Width = getWidth() - 13;
|
||||||
Height = getHeight() - 35;
|
Height = getHeight() - 30;
|
||||||
|
|
||||||
CreateButton.setName("createButton");
|
CreateButton.setName("createButton");
|
||||||
Icon iconUp = new ImageIcon("src\\Resources\\arrowUp.png");
|
Icon iconUp = new ImageIcon("Resources\\arrowUp.jpg");
|
||||||
UpButton.setIcon(iconUp);
|
UpButton.setIcon(iconUp);
|
||||||
UpButton.setName("UP");
|
UpButton.setName("UP");
|
||||||
DownButton.setName("DOWN");
|
DownButton.setName("DOWN");
|
||||||
Icon iconDown = new ImageIcon("src\\Resources\\arrowDown.png");
|
Icon iconDown = new ImageIcon("Resources\\arrowDown.jpg");
|
||||||
DownButton.setIcon(iconDown);
|
DownButton.setIcon(iconDown);
|
||||||
LeftButton.setName("LEFT");
|
LeftButton.setName("LEFT");
|
||||||
Icon iconLeft = new ImageIcon("src\\Resources\\arrowLeft.png");
|
Icon iconLeft = new ImageIcon("Resources\\arrowLeft.jpg");
|
||||||
LeftButton.setIcon(iconLeft);
|
LeftButton.setIcon(iconLeft);
|
||||||
RightButton.setName("RIGHT");
|
RightButton.setName("RIGHT");
|
||||||
Icon iconRight = new ImageIcon("arrowRight.png");
|
Icon iconRight = new ImageIcon("Resources\\arrowRight.jpg");
|
||||||
RightButton.setIcon(iconRight);
|
RightButton.setIcon(iconRight);
|
||||||
|
|
||||||
CreateButton.addActionListener(new ActionListener() {
|
CreateButton.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
@ -50,12 +48,12 @@ public class FormStormtrooper extends JFrame {
|
|||||||
int speed = (int)(Math.random() * 300 + 100);
|
int speed = (int)(Math.random() * 300 + 100);
|
||||||
float weight = (float) (Math.random() * 3000 + 1000);
|
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 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));;
|
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 rockets = new Random().nextBoolean();
|
||||||
boolean boombs = new Random().nextBoolean();;
|
boolean bombs = new Random().nextBoolean();
|
||||||
boolean engines = new Random().nextBoolean();;
|
boolean engines = new Random().nextBoolean();
|
||||||
canvasStormtrooper._drawingStormtrooper = new DrawingStormtrooper();
|
canvasStormtrooper._drawingStormtrooper = new DrawingStormtrooper();
|
||||||
canvasStormtrooper._drawingStormtrooper.Init(speed, weight, bodyColor, additionalColor,rockets, boombs, engines);
|
canvasStormtrooper._drawingStormtrooper.Init(speed, weight, bodyColor, additionalColor,rockets, bombs, engines);
|
||||||
canvasStormtrooper._drawingStormtrooper.SetPictureSize(Width, Height);
|
canvasStormtrooper._drawingStormtrooper.SetPictureSize(Width, Height);
|
||||||
canvasStormtrooper._drawingStormtrooper.SetPosition( StartPositionX, StartPositionY);
|
canvasStormtrooper._drawingStormtrooper.SetPosition( StartPositionX, StartPositionY);
|
||||||
canvasStormtrooper.repaint();
|
canvasStormtrooper.repaint();
|
||||||
@ -66,21 +64,13 @@ public class FormStormtrooper extends JFrame {
|
|||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent event) {
|
public void actionPerformed(ActionEvent event) {
|
||||||
if (canvasStormtrooper._drawingStormtrooper == null) return;
|
if (canvasStormtrooper._drawingStormtrooper == null) return;
|
||||||
boolean result = false;
|
boolean result = switch ((((JButton) (event.getSource())).getName())) {
|
||||||
switch ((((JButton)(event.getSource())).getName())) {
|
case "UP" -> canvasStormtrooper._drawingStormtrooper.MoveTransport(DirectionType.Up);
|
||||||
case "UP":
|
case "DOWN" -> canvasStormtrooper._drawingStormtrooper.MoveTransport(DirectionType.Down);
|
||||||
result = canvasStormtrooper._drawingStormtrooper.MoveTransport(DirectionType.Up);
|
case "LEFT" -> canvasStormtrooper._drawingStormtrooper.MoveTransport(DirectionType.Left);
|
||||||
break;
|
case "RIGHT" -> canvasStormtrooper._drawingStormtrooper.MoveTransport(DirectionType.Right);
|
||||||
case "DOWN":
|
default -> false;
|
||||||
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) {
|
if (result) {
|
||||||
canvasStormtrooper.repaint();
|
canvasStormtrooper.repaint();
|
||||||
}
|
}
|
||||||
@ -90,15 +80,14 @@ public class FormStormtrooper extends JFrame {
|
|||||||
DownButton.addActionListener(actionListener);
|
DownButton.addActionListener(actionListener);
|
||||||
LeftButton.addActionListener(actionListener);
|
LeftButton.addActionListener(actionListener);
|
||||||
RightButton.addActionListener(actionListener);
|
RightButton.addActionListener(actionListener);
|
||||||
|
|
||||||
setSize(dimension.width,dimension.height);
|
setSize(dimension.width,dimension.height);
|
||||||
setLayout(null);
|
setLayout(null);
|
||||||
canvasStormtrooper.setBounds(0,0, getWidth(), getHeight());
|
canvasStormtrooper.setBounds(0,0, getWidth(), getHeight());
|
||||||
CreateButton.setBounds(10, getHeight() - 90, 100, 40);
|
CreateButton.setBounds(10, getHeight() - 90, 130, 40);
|
||||||
UpButton.setBounds(getWidth() - 140, getHeight() - 160, 50, 50);
|
UpButton.setBounds(getWidth() - 180, getHeight() - 210, 70, 70);
|
||||||
DownButton.setBounds(getWidth() - 140, getHeight() - 100, 50, 50);
|
DownButton.setBounds(getWidth() - 180, getHeight() - 140, 70, 70);
|
||||||
RightButton.setBounds(getWidth() - 80, getHeight() - 100, 50, 50);
|
RightButton.setBounds(getWidth() - 110, getHeight() - 140, 70, 70);
|
||||||
LeftButton.setBounds(getWidth() - 200, getHeight() - 100, 50, 50);
|
LeftButton.setBounds(getWidth() - 250, getHeight() - 140, 70, 70);
|
||||||
add(CreateButton);
|
add(CreateButton);
|
||||||
add(UpButton);
|
add(UpButton);
|
||||||
add(DownButton);
|
add(DownButton);
|
||||||
@ -106,19 +95,17 @@ public class FormStormtrooper extends JFrame {
|
|||||||
add(LeftButton);
|
add(LeftButton);
|
||||||
add(canvasStormtrooper);
|
add(canvasStormtrooper);
|
||||||
setVisible(true);
|
setVisible(true);
|
||||||
//обработка события изменения размеров окна
|
|
||||||
addComponentListener(new ComponentAdapter() {
|
addComponentListener(new ComponentAdapter() {
|
||||||
public void componentResized(ComponentEvent e) {
|
public void componentResized(ComponentEvent e) {
|
||||||
Width = getWidth() - 15;
|
Width = getWidth() - 13;
|
||||||
Height = getHeight() - 35;
|
Height = getHeight() - 30;
|
||||||
if (canvasStormtrooper._drawingStormtrooper != null)
|
if (canvasStormtrooper._drawingStormtrooper != null)canvasStormtrooper._drawingStormtrooper.SetPictureSize(Width, Height);
|
||||||
canvasStormtrooper._drawingStormtrooper.SetPictureSize(Width, Height);
|
|
||||||
canvasStormtrooper.setBounds(0,0, getWidth(), getHeight());
|
canvasStormtrooper.setBounds(0,0, getWidth(), getHeight());
|
||||||
CreateButton.setBounds(10, getHeight() - 90, 100, 40);
|
CreateButton.setBounds(10, getHeight() - 90, 130, 40);
|
||||||
UpButton.setBounds(getWidth() - 140, getHeight() - 160, 50, 50);
|
UpButton.setBounds(getWidth() - 180, getHeight() - 210, 70, 70);
|
||||||
DownButton.setBounds(getWidth() - 140, getHeight() - 100, 50, 50);
|
DownButton.setBounds(getWidth() - 180, getHeight() - 140, 70, 70);
|
||||||
RightButton.setBounds(getWidth() - 80, getHeight() - 100, 50, 50);
|
RightButton.setBounds(getWidth() - 110, getHeight() - 140, 70, 70);
|
||||||
LeftButton.setBounds(getWidth() - 200, getHeight() - 100, 50, 50);
|
LeftButton.setBounds(getWidth() - 250, getHeight() - 140, 70, 70);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user