лаба 1, готовая

This commit is contained in:
a.puchkina 2023-12-24 18:28:19 +04:00
parent fb2bc6276b
commit 89e34392e0
11 changed files with 445 additions and 4 deletions

View File

@ -1,12 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AutoImportSettings">
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="d76a7414-ef61-4559-85d8-aee9cbb6c975" name="Changes" comment="" />
<list default="true" id="d76a7414-ef61-4559-85d8-aee9cbb6c975" name="Changes" comment="Создание проекта">
<change afterPath="$PROJECT_DIR$/src/DirectionType.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/DrawningAirplaneWithRadar.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/DrawningIlluminators.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/EntityAirplaneWithRadar.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/NumberType.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/images/down-arrow.png" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/images/left-arrow.png" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/images/right-arrow.png" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/images/upper-arrow.png" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/Main.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Main.java" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
<component name="MarkdownSettingsMigration">
<option name="stateVersion" value="1" />
</component>
<component name="ProjectId" id="2Zzag09YMkXgcrrL97rYHmYPGZX" />
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
<component name="ProjectViewState">
@ -16,9 +37,16 @@
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
"RunOnceActivity.OpenProjectViewOnStart": "true",
"RunOnceActivity.ShowReadmeOnStart": "true"
"RunOnceActivity.ShowReadmeOnStart": "true",
"last_opened_file_path": "D:/Проекты Idea/ProjectAirplaneWithRadar_HARD/src"
}
}]]></component>
<component name="RecentsManager">
<key name="CopyFile.RECENT_KEYS">
<recent name="D:\Проекты Idea\ProjectAirplaneWithRadar_HARD\src" />
<recent name="D:\Проекты Idea\ProjectAirplaneWithRadar_HARD\src\images" />
</key>
</component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
@ -28,6 +56,18 @@
<option name="presentableId" value="Default" />
<updated>1703427470510</updated>
</task>
<task id="LOCAL-00001" summary="Создание проекта">
<created>1703427528828</created>
<option name="number" value="00001" />
<option name="presentableId" value="LOCAL-00001" />
<option name="project" value="LOCAL" />
<updated>1703427528828</updated>
</task>
<option name="localTasksCounter" value="2" />
<servers />
</component>
<component name="VcsManagerConfiguration">
<MESSAGE value="Создание проекта" />
<option name="LAST_COMMIT_MESSAGE" value="Создание проекта" />
</component>
</project>

6
src/DirectionType.java Normal file
View File

@ -0,0 +1,6 @@
public enum DirectionType {
Up,
Down,
Left,
Right
}

View File

@ -0,0 +1,200 @@
import javax.swing.*;
import java.awt.*;
import java.util.Random;
public class DrawningAirplaneWithRadar {
JPanel AirplaneWithRadarPanel;
private EntityAirplaneWithRadar EntityAirplaneWithRadar;
private int _pictureWidth;
private int _pictureHeight;
private int _startPosX = 0;
private int _startPosY = 0;
private int _airplaneWidth = 200;
private int _airplaneHeight = 85;
private DrawningIlluminators DrawningIlluminators;
public EntityAirplaneWithRadar EntityAirplaneWithRadar(){
return EntityAirplaneWithRadar;
}
public boolean Init(int speed, double weight, Color bodyColor, Color illuminatorColor, Color additionalColor, int illuminatorNumb,
int width, int height, boolean radar, boolean tank, JPanel airplaneWithRadarPanel){
if(width <= _airplaneWidth || height <= _airplaneHeight)
return false;
_startPosY=0;
_startPosX = 0;
airplaneWithRadarPanel.setSize(width, height);
AirplaneWithRadarPanel = airplaneWithRadarPanel;
airplaneWithRadarPanel.paint(AirplaneWithRadarPanel.getGraphics());
_pictureWidth = width;
_pictureHeight = height;
EntityAirplaneWithRadar = new EntityAirplaneWithRadar();
EntityAirplaneWithRadar.Init(speed, weight, bodyColor, illuminatorColor, additionalColor, illuminatorNumb, radar, tank);
DrawningIlluminators = new DrawningIlluminators();
DrawningIlluminators.Init(_airplaneWidth, _airplaneHeight,_startPosX,_startPosY,illuminatorColor,airplaneWithRadarPanel);
Random rand = new Random();
DrawningIlluminators.ChangeIlluminatorNumb(rand.nextInt(1, 5));
return true;
}
public void SetPosition(int x, int y){
if (x < 0 || y < 0 || x + _airplaneWidth >= _pictureWidth || y + _airplaneHeight >= _pictureHeight)
{
x = y = 10;
_startPosX = x;
_startPosY = y;
}
_startPosX = x;
_startPosY = y;
DrawningIlluminators.CurX = _startPosX;
DrawningIlluminators.CurY = _startPosY;
}
public void MoveTransport(DirectionType direction){
if (EntityAirplaneWithRadar == null)
return;
AirplaneWithRadarPanel.paint(AirplaneWithRadarPanel.getGraphics());
switch (direction)
{
case Left:
if (_startPosX - EntityAirplaneWithRadar.Step() >= 0)
_startPosX -= (int)EntityAirplaneWithRadar.Step();
else
_startPosX = 0;
break;
case Up:
if (_startPosY - EntityAirplaneWithRadar.Step() >= 0)
_startPosY -= (int)EntityAirplaneWithRadar.Step();
else
_startPosY = 0;
break;
case Right:
if (_startPosX + EntityAirplaneWithRadar.Step() + _airplaneWidth < _pictureWidth)
_startPosX += (int)EntityAirplaneWithRadar.Step();
else
_startPosX = _pictureWidth - _airplaneWidth;
break;
case Down:
if (_startPosY + EntityAirplaneWithRadar.Step() + _airplaneHeight < _pictureHeight)
_startPosY += (int)EntityAirplaneWithRadar.Step();
else
_startPosY = _pictureHeight - _airplaneHeight;
break;
}
DrawningIlluminators.CurX = _startPosX;
DrawningIlluminators.CurY = _startPosY;
}
public void DrawAirplaneWithRadar(){
Graphics2D g2d = (Graphics2D)AirplaneWithRadarPanel.getGraphics();
if (EntityAirplaneWithRadar == null)
return;
g2d.setColor(Color.BLACK);
g2d.setStroke(new BasicStroke(1));
//фюззеляж
g2d.setColor(EntityAirplaneWithRadar.BodyColor());
g2d.fillRect(_startPosX + 4, _startPosY + 40, 150, 30);
g2d.setColor(Color.BLACK);
g2d.drawRect(_startPosX + 4, _startPosY + 40, 150, 30);
int[] curvePointsX =
{
_startPosX + 4,
_startPosX + 4,
_startPosX + 50,
};
int[] curvePointsY =
{
_startPosY + 40,
_startPosY + 0,
_startPosY + 40,
};
// киль
g2d.setColor(EntityAirplaneWithRadar.AdditionalColor());
g2d.fillPolygon(curvePointsX, curvePointsY, curvePointsY.length);
g2d.setColor(Color.BLACK);
g2d.drawPolygon(curvePointsX, curvePointsY, curvePointsY.length);
// стабилизатор и крыло
g2d.setColor(Color.darkGray);
g2d.fillOval(_startPosX, _startPosY + 35, 55, 10);
g2d.drawOval(_startPosX, _startPosY + 35, 55, 10);
g2d.fillOval(_startPosX + 55, _startPosY + 57, 70, 8);
g2d.drawOval(_startPosX + 55, _startPosY + 57, 70, 8);
// шасси
g2d.setStroke(new BasicStroke(3));
g2d.drawLine(_startPosX + 50, _startPosY + 70, _startPosX + 50, _startPosY + 80);
g2d.drawLine(_startPosX + 140, _startPosY + 70, _startPosX + 140, _startPosY + 80);
g2d.fillRect(_startPosX + 44, _startPosY + 80, 5, 5);
g2d.fillRect(_startPosX + 51, _startPosY + 80, 5, 5);
g2d.fillRect(_startPosX + 138, _startPosY + 80, 5, 5);
// кабина
g2d.setColor(EntityAirplaneWithRadar.AdditionalColor());
int[] curvePoints2X =
{
_startPosX + 150,
_startPosX + 190,
_startPosX + 150,
};
int[] curvePoints2Y =
{
_startPosY + 55,
_startPosY + 55,
_startPosY + 72,
};
g2d.fillPolygon(curvePoints2X, curvePoints2Y, curvePoints2Y.length);
g2d.setColor(Color.CYAN);
int[] curvePoints3X =
{
_startPosX + 150,
_startPosX + 150,
_startPosX + 190,
};
int[] curvePoints3Y =
{
_startPosY + 55,
_startPosY + 38,
_startPosY + 55,
};
g2d.fillPolygon(curvePoints3X, curvePoints3Y, curvePoints3Y.length);
g2d.setColor(Color.DARK_GRAY);
g2d.setStroke(new BasicStroke(1));
g2d.drawLine(_startPosX + 150, _startPosY + 55, _startPosX + 150, _startPosY + 38);
g2d.drawLine(_startPosX + 150, _startPosY + 38, _startPosX + 190, _startPosY + 55);
g2d.drawLine(_startPosX + 190, _startPosY + 55, _startPosX + 150, _startPosY + 55);
g2d.drawLine(_startPosX + 150, _startPosY + 72,_startPosX + 150, _startPosY + 55);
g2d.drawLine(_startPosX + 150, _startPosY + 72,_startPosX + 190, _startPosY + 55);
// радар
if (EntityAirplaneWithRadar.Radar())
{
g2d.setColor(EntityAirplaneWithRadar.AdditionalColor());
g2d.fillOval(_startPosX + 65, _startPosY + 25, 50, 10);
g2d.drawOval(_startPosX + 65, _startPosY + 25, 50, 10);
g2d.fillRect(_startPosX + 85, _startPosY + 35, 10, 5);
g2d.drawRect(_startPosX + 85, _startPosY + 35, 10, 5);
}
// бак
if (EntityAirplaneWithRadar.Tank())
{
g2d.fillRect(_startPosX + 70, _startPosY + 65, 45, 15);
int[] curvePoints4X =
{
_startPosX + 70,
_startPosX + 60,
_startPosX + 70,
};
int[] curvePoints4Y =
{
_startPosY + 65,
_startPosY + 72,
_startPosY + 80,
};
g2d.fillPolygon(curvePoints4X, curvePoints4Y, curvePoints4Y.length);
int[] curvePoints5X =
{
_startPosX + 115,
_startPosX + 125,
_startPosX + 115,
};
g2d.fillPolygon(curvePoints5X, curvePoints4Y, curvePoints4Y.length);
}
DrawningIlluminators.DrawIlluminators();
}
}

View File

@ -0,0 +1,57 @@
import javax.swing.*;
import java.awt.*;
public class DrawningIlluminators {
JPanel AirplaneWithRadarPanel;
private NumberType IlluminatorNumb;
private Color IlluminatorColor;
private int Width, Height;
public int CurX, CurY;
boolean Init(int width, int height, int curX, int curY, Color illuminatorColor, JPanel airplaneWithRadarPanel){
Width = width;
Height = height;
CurX = curX;
CurY = curY;
IlluminatorColor = illuminatorColor;
AirplaneWithRadarPanel = airplaneWithRadarPanel;
return true;
}
public void ChangeIlluminatorNumb(int x){
if(x <= 2)
IlluminatorNumb = NumberType.Ten;
if(x == 3)
IlluminatorNumb = NumberType.Twenty;
if(x >= 4)
IlluminatorNumb = NumberType.Thirty;
}
public NumberType IlluminatorNumb(){
return IlluminatorNumb;
}
public void DrawIlluminators(){
Graphics2D g2d = (Graphics2D)AirplaneWithRadarPanel.getGraphics();
g2d.setColor(IlluminatorColor);
int x = CurX;
int y = CurY;
for( int i =0; i<10;i++){
g2d.fillOval( x+53 , y+43 , 5, 5);
x+=7;
}
//20 иллюминаторов
if (IlluminatorNumb == NumberType.Twenty || IlluminatorNumb == NumberType.Thirty)
{
x = CurX;
for( int i =0; i<10;i++){
g2d.fillOval( x+53 , y+51 , 5, 5);
x+=7;
}
}
//30 иллюминаторов
if (IlluminatorNumb == NumberType.Thirty)
{
x = CurX;
for( int i =0; i<10;i++){
g2d.fillOval( x+53 , y+59 , 5, 5);
x+=7;
}
}
}
}

View File

@ -0,0 +1,43 @@
import java.awt.*;
public class EntityAirplaneWithRadar {
private int Speed, IlluminatorNumb;
private double Weight, Step;
private Color BodyColor, AdditionalColor, IlluminatorColor;
private boolean Radar;
private boolean Tank;
public int Speed(){
return Speed;
}
public int IlluminatorNumb(){
return IlluminatorNumb;
}
public double Weight(){
return Weight;
}
public double Step(){
return Step;
}
public Color BodyColor(){
return BodyColor;
}
public Color AdditionalColor(){
return AdditionalColor;
}
public Color IlluminatorColor(){
return IlluminatorColor;
}
public boolean Radar(){return Radar;}
public boolean Tank(){return Tank;}
public void Init(int speed, double weight, Color bodyColor, Color illuminatorColor, Color additionalColor, int illuminatorNumb,
boolean radar, boolean tank ){
Speed = speed;
Weight = weight;
Step = (double)Speed * 100 / Weight;
BodyColor = bodyColor;
IlluminatorColor=illuminatorColor;
AdditionalColor = additionalColor;
IlluminatorNumb = illuminatorNumb;
Radar = radar;
Tank = tank;
}
}

View File

@ -1,5 +1,95 @@
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.Random;
import javax.imageio.ImageIO;
import javax.swing.*;
public class Main {
public static void main(String[] args) {
System.out.println("Hello world!");
public static void main(String[] args) throws IOException {
JFrame AirplaneWithRadarFrame = new JFrame();
JPanel AirplaneWithRadarPanel = new JPanel();
AirplaneWithRadarFrame.setLayout(new BorderLayout());
AirplaneWithRadarFrame.setSize(900, 500);
AirplaneWithRadarFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
AirplaneWithRadarFrame.setLayout(new BorderLayout(1,1));
AirplaneWithRadarFrame.setResizable(false);
DrawningAirplaneWithRadar DrawningEntityAirplaneWithRadar = new DrawningAirplaneWithRadar();
AirplaneWithRadarPanel.setLayout(null);
BufferedImage RightIcon = ImageIO.read(new File("src\\images\\right-arrow.png"));
BufferedImage LeftIcon = ImageIO.read(new File("src\\images\\left-arrow.png"));
BufferedImage UpIcon = ImageIO.read(new File("src\\images\\upper-arrow.png"));
BufferedImage DownIcon = ImageIO.read(new File("src\\images\\down-arrow.png"));
JButton RightButton = new JButton(new ImageIcon(RightIcon));
JButton LeftButton = new JButton(new ImageIcon(LeftIcon));
JButton UpButton = new JButton(new ImageIcon(UpIcon));
JButton DownButton = new JButton(new ImageIcon(DownIcon));
JButton CreateButton = new JButton();
CreateButton.setText("Создать");
CreateButton.setBounds(12, 401, 90, 40);
RightButton.setBounds(840,411,30,30);
LeftButton.setBounds(768,411,30,30);
UpButton.setBounds(804,375,30,30);
DownButton.setBounds(804,411,30,30);
AirplaneWithRadarPanel.add(CreateButton);
AirplaneWithRadarPanel.add(RightButton);
AirplaneWithRadarPanel.add(LeftButton);
AirplaneWithRadarPanel.add(UpButton);
AirplaneWithRadarPanel.add(DownButton);
AirplaneWithRadarFrame.add(AirplaneWithRadarPanel, BorderLayout.CENTER);
Random random = new Random();
CreateButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
DrawningEntityAirplaneWithRadar.Init(random.nextInt(100, 300), random.nextDouble(1000, 3000),
Color.getHSBColor(random.nextInt(0, 301), random.nextInt(0, 301), random.nextInt(0, 301)),
Color.getHSBColor(random.nextInt(0, 301), random.nextInt(0, 301), random.nextInt(0, 301)),
Color.getHSBColor(random.nextInt(0, 301), random.nextInt(0, 301), random.nextInt(0, 301)),
random.nextInt(1, 4)*10,
AirplaneWithRadarPanel.getWidth(), AirplaneWithRadarPanel.getHeight(), random.nextBoolean(), random.nextBoolean(), AirplaneWithRadarPanel);
DrawningEntityAirplaneWithRadar.SetPosition(random.nextInt(90) + 10, random.nextInt(90) + 10);
DrawningEntityAirplaneWithRadar.DrawAirplaneWithRadar();
}
});
RightButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if(DrawningEntityAirplaneWithRadar.EntityAirplaneWithRadar() == null)
return;
DrawningEntityAirplaneWithRadar.MoveTransport(DirectionType.Right);
DrawningEntityAirplaneWithRadar.DrawAirplaneWithRadar();
}
});
LeftButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if(DrawningEntityAirplaneWithRadar.EntityAirplaneWithRadar() == null)
return;
DrawningEntityAirplaneWithRadar.MoveTransport(DirectionType.Left);
DrawningEntityAirplaneWithRadar.DrawAirplaneWithRadar();
}
});
UpButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if(DrawningEntityAirplaneWithRadar.EntityAirplaneWithRadar() == null)
return;
DrawningEntityAirplaneWithRadar.MoveTransport(DirectionType.Up);
DrawningEntityAirplaneWithRadar.DrawAirplaneWithRadar();
}
});
DownButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if(DrawningEntityAirplaneWithRadar.EntityAirplaneWithRadar() == null)
return;
DrawningEntityAirplaneWithRadar.MoveTransport(DirectionType.Down);
DrawningEntityAirplaneWithRadar.DrawAirplaneWithRadar();
}
});
AirplaneWithRadarFrame.setVisible(true);
}
}

5
src/NumberType.java Normal file
View File

@ -0,0 +1,5 @@
public enum NumberType {
Ten,
Twenty,
Thirty
}

BIN
src/images/down-arrow.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 281 B

BIN
src/images/left-arrow.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 265 B

BIN
src/images/right-arrow.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 224 B

BIN
src/images/upper-arrow.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 264 B