PIBD-11 Ryabov I.V. LabWork02 Hard #5
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 {
|
||||
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) {
|
||||
public void DrawEngines(Graphics g, int x, int y, Color 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.Init(speed, weight, bodyColor, additionalColor, rockets,bombs ,engines);
|
||||
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;
|
||||
_startPosY=null;
|
||||
_pictureWidth = null;
|
||||
_pictureHeight = null;
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Установка границ поля
|
||||
@ -203,6 +203,7 @@ public class DrawingStormtrooper {
|
||||
g.drawLine(_startPosX+ 50, _startPosY, _startPosX + 60, _startPosY);
|
||||
g.drawLine(_startPosX+ 60, _startPosY, _startPosX + 65, _startPosY + 60);
|
||||
///Нос бомбардировщика
|
||||
g.setColor(EntityStormtrooper.getBodyColor());
|
||||
Point[] Nose = new Point[3];
|
||||
int[] arrX = {_startPosX + 20, _startPosX,_startPosX+20};
|
||||
int[] arrY = {_startPosY + 80,_startPosY + 70,_startPosY + 60};
|
||||
@ -214,7 +215,6 @@ public class DrawingStormtrooper {
|
||||
g.setColor(EntityStormtrooper.getAdditionalColor());
|
||||
g.fillRect( _startPosX + 35, _startPosY + 20, 15, 5);
|
||||
g.fillRect( _startPosX + 35, _startPosY + 110, 15, 5);
|
||||
|
||||
}
|
||||
//Бомбы бомбардировщика
|
||||
if (EntityStormtrooper.getBombs())
|
||||
@ -224,26 +224,7 @@ public class DrawingStormtrooper {
|
||||
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;
|
||||
}
|
||||
drawingEngines.SwitchDrawEngines(g, _startPosX, _startPosY, EntityStormtrooper.getBodyColor());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,6 @@ public class EntityStormtrooper {
|
||||
public Color getBodyColor() {
|
||||
return BodyColor;
|
||||
}
|
||||
|
||||
private Color AdditionalColor;
|
||||
public Color getAdditionalColor() {
|
||||
return AdditionalColor;
|
||||
|
@ -7,16 +7,16 @@ import java.awt.event.ComponentEvent;
|
||||
import java.util.Random;
|
||||
|
||||
public class FormStormtrooper extends JFrame {
|
||||
private String title;
|
||||
private Dimension dimension;
|
||||
private final String title;
|
||||
private final 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();
|
||||
private final CanvasStormtrooper canvasStormtrooper = new CanvasStormtrooper();
|
||||
private final JButton CreateButton = new JButton("Создать");
|
||||
private final JButton UpButton = new JButton();
|
||||
private final JButton DownButton = new JButton();
|
||||
private final JButton LeftButton = new JButton();
|
||||
private final JButton RightButton = new JButton();
|
||||
public FormStormtrooper(String title, Dimension dimension) {
|
||||
this.title = title;
|
||||
this.dimension = dimension;
|
||||
@ -25,23 +25,21 @@ public class FormStormtrooper extends JFrame {
|
||||
setTitle(title);
|
||||
setMinimumSize(dimension);
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
Width = getWidth() - 15;
|
||||
Height = getHeight() - 35;
|
||||
|
||||
Width = getWidth() - 13;
|
||||
Height = getHeight() - 30;
|
||||
CreateButton.setName("createButton");
|
||||
Icon iconUp = new ImageIcon("src\\Resources\\arrowUp.png");
|
||||
Icon iconUp = new ImageIcon("Resources\\arrowUp.jpg");
|
||||
UpButton.setIcon(iconUp);
|
||||
UpButton.setName("UP");
|
||||
DownButton.setName("DOWN");
|
||||
Icon iconDown = new ImageIcon("src\\Resources\\arrowDown.png");
|
||||
Icon iconDown = new ImageIcon("Resources\\arrowDown.jpg");
|
||||
DownButton.setIcon(iconDown);
|
||||
LeftButton.setName("LEFT");
|
||||
Icon iconLeft = new ImageIcon("src\\Resources\\arrowLeft.png");
|
||||
Icon iconLeft = new ImageIcon("Resources\\arrowLeft.jpg");
|
||||
LeftButton.setIcon(iconLeft);
|
||||
RightButton.setName("RIGHT");
|
||||
Icon iconRight = new ImageIcon("arrowRight.png");
|
||||
Icon iconRight = new ImageIcon("Resources\\arrowRight.jpg");
|
||||
RightButton.setIcon(iconRight);
|
||||
|
||||
CreateButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
@ -50,12 +48,12 @@ public class FormStormtrooper extends JFrame {
|
||||
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));;
|
||||
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();;
|
||||
boolean bombs = new Random().nextBoolean();
|
||||
boolean engines = new Random().nextBoolean();
|
||||
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.SetPosition( StartPositionX, StartPositionY);
|
||||
canvasStormtrooper.repaint();
|
||||
@ -66,21 +64,13 @@ public class FormStormtrooper extends JFrame {
|
||||
@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;
|
||||
}
|
||||
boolean result = switch ((((JButton) (event.getSource())).getName())) {
|
||||
case "UP" -> canvasStormtrooper._drawingStormtrooper.MoveTransport(DirectionType.Up);
|
||||
case "DOWN" -> canvasStormtrooper._drawingStormtrooper.MoveTransport(DirectionType.Down);
|
||||
case "LEFT" -> canvasStormtrooper._drawingStormtrooper.MoveTransport(DirectionType.Left);
|
||||
case "RIGHT" -> canvasStormtrooper._drawingStormtrooper.MoveTransport(DirectionType.Right);
|
||||
default -> false;
|
||||
};
|
||||
if (result) {
|
||||
canvasStormtrooper.repaint();
|
||||
}
|
||||
@ -90,15 +80,14 @@ public class FormStormtrooper extends JFrame {
|
||||
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);
|
||||
CreateButton.setBounds(10, getHeight() - 90, 130, 40);
|
||||
UpButton.setBounds(getWidth() - 180, getHeight() - 210, 70, 70);
|
||||
DownButton.setBounds(getWidth() - 180, getHeight() - 140, 70, 70);
|
||||
RightButton.setBounds(getWidth() - 110, getHeight() - 140, 70, 70);
|
||||
LeftButton.setBounds(getWidth() - 250, getHeight() - 140, 70, 70);
|
||||
add(CreateButton);
|
||||
add(UpButton);
|
||||
add(DownButton);
|
||||
@ -106,19 +95,17 @@ public class FormStormtrooper extends JFrame {
|
||||
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);
|
||||
Width = getWidth() - 13;
|
||||
Height = getHeight() - 30;
|
||||
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);
|
||||
CreateButton.setBounds(10, getHeight() - 90, 130, 40);
|
||||
UpButton.setBounds(getWidth() - 180, getHeight() - 210, 70, 70);
|
||||
DownButton.setBounds(getWidth() - 180, getHeight() - 140, 70, 70);
|
||||
RightButton.setBounds(getWidth() - 110, getHeight() - 140, 70, 70);
|
||||
LeftButton.setBounds(getWidth() - 250, getHeight() - 140, 70, 70);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user