Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
f1cd73f9c4 | ||
|
65ce3bff95 |
155
AirFighter/src/AbstractMap.java
Normal file
155
AirFighter/src/AbstractMap.java
Normal file
@ -0,0 +1,155 @@
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
public abstract class AbstractMap {
|
||||
private IDrawningObject _drawningObject = null;
|
||||
protected int[][] _map = null;
|
||||
protected int _width;
|
||||
protected int _height;
|
||||
protected float _size_x;
|
||||
protected float _size_y;
|
||||
protected final int _freeRoad = 0;
|
||||
protected final int _barrier = 1;
|
||||
public BufferedImage CreateMap(int width, int height, IDrawningObject drawningObject)
|
||||
{
|
||||
_width = width;
|
||||
_height = height;
|
||||
_drawningObject = drawningObject;
|
||||
GenerateMap();
|
||||
while (!SetObjectOnMap())
|
||||
{
|
||||
GenerateMap();
|
||||
}
|
||||
return DrawMapWithObject();
|
||||
}
|
||||
public BufferedImage MoveObject(Direction direction)
|
||||
{
|
||||
// Проверка коллизии
|
||||
float Left = _drawningObject.GetLeftPosition();
|
||||
float Right = _drawningObject.GetRightPosition();
|
||||
float Top = _drawningObject.GetTopPosition();
|
||||
float Bottom = _drawningObject.GetBottomPosition();
|
||||
|
||||
switch (direction)
|
||||
{
|
||||
case Right:
|
||||
if (Right + _drawningObject.Step() < _width)
|
||||
{
|
||||
Left += _drawningObject.Step();
|
||||
Right += _drawningObject.Step();
|
||||
}
|
||||
break;
|
||||
case Left:
|
||||
if (Left - _drawningObject.Step() >= 0)
|
||||
{
|
||||
Left -= _drawningObject.Step();
|
||||
Right -= _drawningObject.Step();
|
||||
}
|
||||
break;
|
||||
case Up:
|
||||
if (Top - _drawningObject.Step() >= 0)
|
||||
{
|
||||
Top -= _drawningObject.Step();
|
||||
Bottom -= _drawningObject.Step();
|
||||
}
|
||||
break;
|
||||
case Down:
|
||||
if (Bottom + _drawningObject.Step() < _height)
|
||||
{
|
||||
Top += _drawningObject.Step();
|
||||
Bottom += _drawningObject.Step();
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (CheckBarrier((int)Right, (int)Left, (int)Top, (int)Bottom) == 1)
|
||||
{
|
||||
_drawningObject.MoveObject(direction);
|
||||
}
|
||||
return DrawMapWithObject();
|
||||
}
|
||||
private int CheckBarrier(int Right, int Left, int Top, int Bottom)
|
||||
{
|
||||
if(Left < 0 || Top < 0 || Right > _width || Bottom > _height)
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
for (int i = (int)(Top / _size_y); i <= (int)(Bottom / _size_y); i++)
|
||||
{
|
||||
for (int j = (int)(Left / _size_x); j <= (int)(Right / _size_x); j++)
|
||||
{
|
||||
if (_map[i][j] == _barrier)
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
private boolean SetObjectOnMap()
|
||||
{
|
||||
if (_drawningObject == null || _map == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
int x = (int)(Math.random() * 10);
|
||||
int y = (int)(Math.random() * 10);
|
||||
_drawningObject.SetObject(x, y, _width, _height);
|
||||
// Првоерка, что объект не "накладывается" на закрытые участки
|
||||
float Left = _drawningObject.GetLeftPosition();
|
||||
float Right = _drawningObject.GetRightPosition();
|
||||
float Top = _drawningObject.GetTopPosition();
|
||||
float Bottom = _drawningObject.GetBottomPosition();
|
||||
float tempBottom = Bottom;
|
||||
float tempTop = Top;
|
||||
while (CheckBarrier((int)Right, (int)Left, (int)Top, (int)Bottom) == 0)
|
||||
{
|
||||
int flag = 0;
|
||||
while (flag == 0)
|
||||
{
|
||||
|
||||
y += (int)_size_y;
|
||||
Top += (int)_size_y;
|
||||
Bottom += (int)_size_y;
|
||||
_drawningObject.SetObject(x, y, _width, _height);
|
||||
flag = CheckBarrier((int)Right, (int)Left, (int)Top, (int)Bottom);
|
||||
}
|
||||
if (flag == 1)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
x += (int)_size_x;
|
||||
Left += (int)_size_x;
|
||||
Right += (int)_size_x;
|
||||
y = (int)tempTop;
|
||||
Top = (int)tempTop;
|
||||
Bottom = (int)tempBottom;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
private BufferedImage DrawMapWithObject()
|
||||
{
|
||||
BufferedImage bufImg = new BufferedImage(_width, _height, BufferedImage.TYPE_INT_RGB);
|
||||
if (_drawningObject == null || _map == null)
|
||||
{
|
||||
return bufImg;
|
||||
}
|
||||
Graphics gr = bufImg.createGraphics();
|
||||
for (int i = 0; i < _map.length; ++i)
|
||||
{
|
||||
for (int j = 0; j < _map[0].length; ++j)
|
||||
{
|
||||
if (_map[i][j] == _freeRoad)
|
||||
{
|
||||
DrawRoadPart(gr, j, i);
|
||||
}
|
||||
else if (_map[i][j] == _barrier)
|
||||
{
|
||||
DrawBarrierPart(gr, j, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
_drawningObject.DrawningObject(gr);
|
||||
return bufImg;
|
||||
}
|
||||
protected abstract void GenerateMap();
|
||||
protected abstract void DrawRoadPart(Graphics g, int i, int j);
|
||||
protected abstract void DrawBarrierPart(Graphics g, int i, int j);
|
||||
}
|
@ -3,30 +3,45 @@ import java.awt.*;
|
||||
public class DrawningAirFighter {
|
||||
/// Объект сущности военного самолета
|
||||
public EntityAirFighter AirFighter;
|
||||
private DrawningEngine _engine;
|
||||
|
||||
private IDrawningEngine _engine;
|
||||
// Левая координата отрисовки самолета
|
||||
private int _startPosX;
|
||||
protected int _startPosX;
|
||||
// Верхняя кооридната отрисовки самолета
|
||||
private int _startPosY;
|
||||
protected int _startPosY;
|
||||
// Ширина окна отрисовки
|
||||
private int _pictureWidth = 0;
|
||||
// Высота окна отрисовки
|
||||
private int _pictureHeight = 0;
|
||||
// Ширина отрисовки самолета
|
||||
final int _airFighterWidth = 80;
|
||||
public int _airFighterWidth = 80;
|
||||
// Высота отрисовки самолета
|
||||
final int _airFighterHeight = 70;
|
||||
public int _airFighterHeight = 70;
|
||||
|
||||
// Инициализация свойств
|
||||
public void Init(int speed, float weight, Color bodyColor, int numberEngine)
|
||||
public DrawningAirFighter(int speed, float weight, Color bodyColor, int numberEngine, String engineModel)
|
||||
{
|
||||
_engine = new DrawningEngine();
|
||||
_engine.setCodeEngine(numberEngine);
|
||||
AirFighter = new EntityAirFighter();
|
||||
AirFighter.Init(speed, weight, bodyColor);
|
||||
switch(engineModel){
|
||||
case "Классический":
|
||||
_engine = new ModelClassicEngine();
|
||||
break;
|
||||
case "Винтовой":
|
||||
_engine = new ModelScrewEngine();
|
||||
break;
|
||||
case "Рeактивный":
|
||||
_engine = new ModelJetEngine();
|
||||
break;
|
||||
default:
|
||||
_engine = new ModelClassicEngine();
|
||||
break;
|
||||
}
|
||||
_engine.SetCodeEngine(numberEngine);
|
||||
AirFighter = new EntityAirFighter(speed, weight, bodyColor);
|
||||
}
|
||||
protected DrawningAirFighter(int speed, float weight, Color bodyColor, int airFighterWidth, int airFighterHeight, int numberEngines, String engineModel) {
|
||||
this(speed, weight, bodyColor, numberEngines, engineModel);
|
||||
_airFighterWidth = airFighterWidth;
|
||||
_airFighterHeight = airFighterHeight;
|
||||
}
|
||||
|
||||
public void SetPosition(int x, int y, int width, int height) {
|
||||
if(width < _airFighterWidth || height < _airFighterHeight)
|
||||
{
|
||||
@ -91,7 +106,7 @@ public class DrawningAirFighter {
|
||||
g.fillPolygon(pointX, pointY, 20);
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawPolyline(pointX, pointY, 21);
|
||||
_engine.DrawEngine(g, _startPosX, _startPosY, AirFighter.getBodyColor());
|
||||
_engine.Draw(g, _startPosX, _startPosY, AirFighter.getBodyColor());
|
||||
}
|
||||
// Смена границ формы отрисовки
|
||||
public void ChangeBorders(int width, int height)
|
||||
|
@ -1,35 +0,0 @@
|
||||
import java.awt.*;
|
||||
// Класс отрисовки двигателей
|
||||
public class DrawningEngine {
|
||||
private Engine _engine;
|
||||
public void setCodeEngine(int code){
|
||||
_engine = Engine.getByCode(code);
|
||||
}
|
||||
// Отрисовка двигателей
|
||||
public void DrawEngine(Graphics g, int startX, int startY, Color _bodyColor){
|
||||
if(_engine.getEngineCode() >= 2) {
|
||||
g.setColor(_bodyColor);
|
||||
g.fillRect(startX+ 30, startY + 15, 13, 5);
|
||||
g.fillRect(startX+ 30, startY + 50, 13, 5);
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawRect(startX+ 30, startY + 15, 13, 5);
|
||||
g.drawRect(startX+ 30, startY + 50, 13, 5);
|
||||
}
|
||||
if(_engine.getEngineCode() >= 4){
|
||||
g.setColor(_bodyColor);
|
||||
g.fillRect(startX+ 30, startY + 22, 13, 5);
|
||||
g.fillRect(startX+ 30, startY + 43, 13, 5);
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawRect(startX+ 30, startY + 22, 13, 5);
|
||||
g.drawRect(startX+ 30, startY + 43, 13, 5);
|
||||
}
|
||||
if(_engine.getEngineCode() >= 6){
|
||||
g.setColor(_bodyColor);
|
||||
g.fillRect(startX+ 30, startY + 8, 13, 5);
|
||||
g.fillRect(startX+ 30, startY + 57, 13, 5);
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawRect(startX+ 30, startY + 8, 13, 5);
|
||||
g.drawRect(startX+ 30, startY + 57, 13, 5);
|
||||
}
|
||||
}
|
||||
}
|
50
AirFighter/src/DrawningObjectAirFighter.java
Normal file
50
AirFighter/src/DrawningObjectAirFighter.java
Normal file
@ -0,0 +1,50 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawningObjectAirFighter implements IDrawningObject{
|
||||
public DrawningAirFighter _airFighter = null;
|
||||
|
||||
public float Step() {
|
||||
return _airFighter != null ? _airFighter.AirFighter.Step() : 0.0F;
|
||||
}
|
||||
|
||||
public DrawningObjectAirFighter(DrawningAirFighter airFighter) {
|
||||
_airFighter = airFighter;
|
||||
}
|
||||
|
||||
public void SetObject(int x, int y, int width, int height) {
|
||||
if (_airFighter != null) {
|
||||
_airFighter.SetPosition(x, y, width, height);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void MoveObject(Direction direction) {
|
||||
if (_airFighter != null) {
|
||||
_airFighter.MoveTransport(direction);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void DrawningObject(Graphics g) {
|
||||
if (_airFighter != null) {
|
||||
_airFighter.DrawTransport(g);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public float GetLeftPosition() {
|
||||
return (float)_airFighter._startPosX;
|
||||
}
|
||||
|
||||
public float GetRightPosition() {
|
||||
return (float)(_airFighter._startPosX + _airFighter._airFighterWidth);
|
||||
}
|
||||
|
||||
public float GetTopPosition() {
|
||||
return (float)_airFighter._startPosY;
|
||||
}
|
||||
|
||||
public float GetBottomPosition() {
|
||||
return (float)(_airFighter._startPosY + _airFighter._airFighterHeight);
|
||||
}
|
||||
}
|
54
AirFighter/src/DrawningUpgradeAirFighter.java
Normal file
54
AirFighter/src/DrawningUpgradeAirFighter.java
Normal file
@ -0,0 +1,54 @@
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
|
||||
public class DrawningUpgradeAirFighter extends DrawningAirFighter{
|
||||
public DrawningUpgradeAirFighter(int speed, float weight, Color bodyColor, Color dopColor, boolean dopWing, boolean rocket, int numberEngines, String engineModel) {
|
||||
super(speed, weight, bodyColor, 85, 80, numberEngines, engineModel);
|
||||
AirFighter = new EntityUpgradeAirFighter(speed, weight, bodyColor, dopColor, dopWing, rocket);
|
||||
}
|
||||
|
||||
public void DrawTransport(Graphics g) {
|
||||
EntityAirFighter var3 = AirFighter;
|
||||
if (var3 instanceof EntityUpgradeAirFighter upgradeAirFighter) {
|
||||
_startPosX += 5;
|
||||
_startPosY += 5;
|
||||
super.DrawTransport(g);
|
||||
_startPosX -= 5;
|
||||
_startPosY -= 5;
|
||||
int[] _leftRocketPointY;
|
||||
int[] _rightRocketPointX;
|
||||
int[] _rightRocketPointY;
|
||||
int[] _leftRocketPointX;
|
||||
if (upgradeAirFighter.GetDopWing()) {
|
||||
_leftRocketPointX = new int[]{_startPosX, _startPosX, _startPosX + 10, _startPosX};
|
||||
_leftRocketPointY = new int[]{_startPosY + 35, _startPosY + 45, _startPosY + 40, _startPosY + 35};
|
||||
_rightRocketPointX = new int[]{_startPosX + 50, _startPosX + 55, _startPosX + 65, _startPosX + 50};
|
||||
_rightRocketPointY = new int[]{_startPosY + 35, _startPosY + 30, _startPosY + 35, _startPosY + 35};
|
||||
int[] _rightWingPointX = new int[]{_startPosX + 50, _startPosX + 55, _startPosX + 65, _startPosX + 50};
|
||||
int[] _rightWingPointY = new int[]{_startPosY + 45, _startPosY + 50, _startPosY + 45, _startPosY + 45};
|
||||
g.setColor(upgradeAirFighter.GetDopColor());
|
||||
g.fillPolygon(_leftRocketPointX, _leftRocketPointY, 3);
|
||||
g.fillPolygon(_rightRocketPointX, _rightRocketPointY, 3);
|
||||
g.fillPolygon(_rightWingPointX, _rightWingPointY, 3);
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawPolygon(_leftRocketPointX, _leftRocketPointY, 4);
|
||||
g.drawPolygon(_rightRocketPointX, _rightRocketPointY, 4);
|
||||
g.drawPolygon(_rightWingPointX, _rightWingPointY, 4);
|
||||
}
|
||||
|
||||
if (upgradeAirFighter.GetRocket()) {
|
||||
_leftRocketPointX = new int[]{_startPosX + 35, _startPosX + 45, _startPosX + 50, _startPosX + 45, _startPosX + 35, _startPosX + 35};
|
||||
_leftRocketPointY = new int[]{_startPosY, _startPosY, _startPosY + 3, _startPosY + 5, _startPosY + 5, _startPosY};
|
||||
_rightRocketPointX = new int[]{_startPosX + 35, _startPosX + 45, _startPosX + 50, _startPosX + 45, _startPosX + 35, _startPosX + 35};
|
||||
_rightRocketPointY = new int[]{_startPosY + 75, _startPosY + 75, _startPosY + 77, _startPosY + 80, _startPosY + 80, _startPosY + 75};
|
||||
g.setColor(upgradeAirFighter.GetDopColor());
|
||||
g.fillPolygon(_leftRocketPointX, _leftRocketPointY, 5);
|
||||
g.fillPolygon(_rightRocketPointX, _rightRocketPointY, 5);
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawPolygon(_leftRocketPointX, _leftRocketPointY, 6);
|
||||
g.drawPolygon(_rightRocketPointX, _rightRocketPointY, 6);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -11,7 +11,7 @@ public class EntityAirFighter {
|
||||
public float Step() {
|
||||
return Speed * 150 / Weight;
|
||||
}
|
||||
public void Init(int _speed, float _weight, Color _bodyColor){
|
||||
public EntityAirFighter(int _speed, float _weight, Color _bodyColor){
|
||||
Speed = _speed;
|
||||
Weight = _weight;
|
||||
BodyColor = _bodyColor;
|
||||
|
26
AirFighter/src/EntityUpgradeAirFighter.java
Normal file
26
AirFighter/src/EntityUpgradeAirFighter.java
Normal file
@ -0,0 +1,26 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class EntityUpgradeAirFighter extends EntityAirFighter{
|
||||
private Color DopColor;
|
||||
private boolean DopWing;
|
||||
private boolean Rocket;
|
||||
|
||||
public EntityUpgradeAirFighter(int speed, float weight, Color bodyColor, Color dopColor, boolean dopWing, boolean rocket) {
|
||||
super(speed, weight, bodyColor);
|
||||
DopColor = dopColor;
|
||||
DopWing = dopWing;
|
||||
Rocket = rocket;
|
||||
}
|
||||
|
||||
public Color GetDopColor() {
|
||||
return DopColor;
|
||||
}
|
||||
|
||||
public boolean GetDopWing() {
|
||||
return DopWing;
|
||||
}
|
||||
|
||||
public boolean GetRocket() {
|
||||
return Rocket;
|
||||
}
|
||||
}
|
@ -14,6 +14,7 @@ public class FormAirFighter extends JFrame implements ComponentListener{
|
||||
private JButton buttonLeft;
|
||||
private JButton buttonRight;
|
||||
private String item = "2";
|
||||
private String itemEngine = "Классический";
|
||||
private DrawningAirFighter _airFighter;
|
||||
|
||||
// Слушатель кнопки направления
|
||||
@ -50,6 +51,7 @@ public class FormAirFighter extends JFrame implements ComponentListener{
|
||||
panelForDrawing.setLayout(new BorderLayout());
|
||||
panelForDrawing.setSize(getWidth(), getHeight());
|
||||
setContentPane(panelForDrawing);
|
||||
|
||||
// statusLabel
|
||||
JLabel labelSpeed = new JLabel("Скорость:");
|
||||
JLabel labelWeight = new JLabel("Вес:");
|
||||
@ -66,8 +68,7 @@ public class FormAirFighter extends JFrame implements ComponentListener{
|
||||
buttonCreate.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
_airFighter = new DrawningAirFighter();
|
||||
_airFighter.Init((int)(Math.random() * 300 + 200),(int)(Math.random() * 3000 + 2000), new Color((int)(Math.random() * 255), (int)(Math.random() * 255), (int)(Math.random() * 255)), Integer.parseInt(item));
|
||||
_airFighter = new DrawningAirFighter((int)(Math.random() * 300 + 200),(int)(Math.random() * 3000 + 2000), new Color((int)(Math.random() * 255), (int)(Math.random() * 255), (int)(Math.random() * 255)), Integer.parseInt(item), itemEngine);
|
||||
_airFighter.SetPosition((int)(Math.random() * 100 + 10), (int)(Math.random() * 100 + 10), panelForDrawing.getWidth(), panelForDrawing.getHeight());
|
||||
labelSpeed.setText("Скорость: " + _airFighter.AirFighter.getSpeed());
|
||||
labelWeight.setText("Вес: " + _airFighter.AirFighter.getWeight());
|
||||
|
269
AirFighter/src/FormMap.java
Normal file
269
AirFighter/src/FormMap.java
Normal file
@ -0,0 +1,269 @@
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public class FormMap extends JFrame{
|
||||
private AbstractMap _abstractMap;
|
||||
private JLabel panelForDrawing = new JLabel();
|
||||
private JPanel statusLabel = new JPanel();
|
||||
private JButton buttonUp;
|
||||
private JButton buttonDown;
|
||||
private JButton buttonLeft;
|
||||
private JButton buttonRight;
|
||||
private JLabel labelBodyColor;
|
||||
private JLabel labelSpeed;
|
||||
private JLabel labelWeight;
|
||||
private String item = "2";
|
||||
private String itemEngine = "Классический";
|
||||
private String mapItem = "Простая карта";
|
||||
// Слушатель кнопки направления
|
||||
private ActionListener actionListenerDirection = new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
JButton tempButton = (JButton)e.getSource();
|
||||
Direction dir = null;
|
||||
if (buttonUp.equals(tempButton)) {
|
||||
dir = Direction.Up;
|
||||
} else if (buttonDown.equals(tempButton)) {
|
||||
dir = Direction.Down;
|
||||
} else if (buttonLeft.equals(tempButton)) {
|
||||
dir = Direction.Left;
|
||||
} else if (buttonRight.equals(tempButton)) {
|
||||
dir = Direction.Right;
|
||||
}
|
||||
panelForDrawing.setIcon(new ImageIcon(_abstractMap.MoveObject(dir)));
|
||||
panelForDrawing.repaint();
|
||||
}
|
||||
};
|
||||
private void SetData(DrawningAirFighter airFighter){
|
||||
labelSpeed.setText("Скорость: " + airFighter.AirFighter.getSpeed());
|
||||
labelWeight.setText("Вес: " + airFighter.AirFighter.getWeight());
|
||||
labelBodyColor.setText("Цвет: " + airFighter.AirFighter.getBodyColor());
|
||||
BufferedImage bufImg = _abstractMap.CreateMap(panelForDrawing.getWidth(), panelForDrawing.getHeight(), new DrawningObjectAirFighter(airFighter));
|
||||
panelForDrawing.setIcon(new ImageIcon(bufImg));
|
||||
}
|
||||
private void SetMap(String mapName){
|
||||
switch (mapName){
|
||||
case "Простая карта":
|
||||
_abstractMap = new SimpleMap();
|
||||
break;
|
||||
case "Карта шторма":
|
||||
_abstractMap = new StormMap();
|
||||
break;
|
||||
}
|
||||
}
|
||||
public FormMap(){
|
||||
super("Военный самолет");
|
||||
//Panel для отрисовки
|
||||
//panelForDrawing.setLayout(new BorderLayout());
|
||||
panelForDrawing.setLayout(null);
|
||||
panelForDrawing.setPreferredSize(new Dimension(getWidth(), getHeight()));
|
||||
panelForDrawing.setBounds(0, 0, getWidth(), getHeight());
|
||||
add(panelForDrawing);
|
||||
|
||||
// ComboBox для выбора карты
|
||||
String[] maps = {
|
||||
"Простая карта",
|
||||
"Карта шторма"
|
||||
};
|
||||
JComboBox mapComboBox = new JComboBox(maps);
|
||||
mapComboBox.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
JComboBox box = (JComboBox)e.getSource();
|
||||
mapItem = (String)box.getSelectedItem();
|
||||
SetMap(mapItem);
|
||||
}
|
||||
});
|
||||
mapComboBox.setBounds(0, 0, 100, 30);
|
||||
mapComboBox.setSelectedIndex(0);
|
||||
panelForDrawing.add(mapComboBox);
|
||||
|
||||
// ComboBox для выбора модели двигателя
|
||||
String[] engineModel = {
|
||||
"Классический",
|
||||
"Винтовой",
|
||||
"Рeактивный"
|
||||
};
|
||||
JComboBox engineComboBox = new JComboBox(engineModel);
|
||||
engineComboBox.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
JComboBox box = (JComboBox)e.getSource();
|
||||
itemEngine = (String)box.getSelectedItem();
|
||||
}
|
||||
});
|
||||
engineComboBox.setBounds(100, 0, 100, 30);
|
||||
engineComboBox.setSelectedIndex(0);
|
||||
panelForDrawing.add(engineComboBox);
|
||||
|
||||
//ComboBox с количеством двигателей
|
||||
String[] _engine = {
|
||||
"2",
|
||||
"4",
|
||||
"6"
|
||||
};
|
||||
JComboBox editComboBox = new JComboBox(_engine);
|
||||
editComboBox.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
JComboBox box = (JComboBox)e.getSource();
|
||||
item = (String)box.getSelectedItem();
|
||||
}
|
||||
});
|
||||
editComboBox.setBounds(200, 0, 50, 30);
|
||||
panelForDrawing.add(editComboBox);
|
||||
// statusLabel
|
||||
labelSpeed = new JLabel("Скорость:");
|
||||
labelWeight = new JLabel("Вес:");
|
||||
labelBodyColor = new JLabel("Цвет:");
|
||||
statusLabel.add(labelSpeed);
|
||||
statusLabel.add(labelWeight);
|
||||
statusLabel.add(labelBodyColor);
|
||||
statusLabel.setLayout(new FlowLayout(FlowLayout.LEFT));
|
||||
statusLabel.setSize(new Dimension(getWidth(), 30));
|
||||
// Кнопка создания
|
||||
JButton buttonCreate = new JButton("Создать");
|
||||
buttonCreate.setSize(100, 25);
|
||||
buttonCreate.setLayout(new FlowLayout(FlowLayout.LEFT));
|
||||
buttonCreate.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
var airFighter = new DrawningAirFighter((int)(Math.random() * 300 + 200),(int)(Math.random() * 3000 + 2000), new Color((int)(Math.random() * 255), (int)(Math.random() * 255), (int)(Math.random() * 255)), Integer.parseInt(item), itemEngine);
|
||||
SetData(airFighter);
|
||||
}
|
||||
});
|
||||
// Кнопка модификации
|
||||
JButton buttonModific = new JButton("Модифицировать");
|
||||
buttonModific.setSize(100, 25);
|
||||
buttonModific.setLayout(new FlowLayout(FlowLayout.LEFT));
|
||||
buttonModific.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
var airFighter = new DrawningUpgradeAirFighter((int)(Math.random() * 300 + 200),(int)(Math.random() * 3000 + 2000), new Color((int)(Math.random() * 255), (int)(Math.random() * 255), (int)(Math.random() * 255)),
|
||||
new Color((int)(Math.random() * 255), (int)(Math.random()) * 255, (int)(Math.random() * 255)), ((int)(Math.random() * 2)) == 1, ((int)(Math.random() * 2)) == 1, Integer.parseInt(item), itemEngine);
|
||||
SetData(airFighter);
|
||||
}
|
||||
});
|
||||
// Контейнер кнопок и панели с информацией
|
||||
Container container = new Container();
|
||||
container.setPreferredSize(new Dimension(200, 100));
|
||||
container.setLayout(new GridBagLayout());
|
||||
GridBagConstraints constraints = new GridBagConstraints();
|
||||
constraints.weightx = 10;
|
||||
constraints.weighty = 10;
|
||||
|
||||
constraints.anchor = GridBagConstraints.WEST;
|
||||
constraints.gridwidth = 1;
|
||||
constraints.gridx = 0;
|
||||
constraints.gridy = 0;
|
||||
container.add(buttonCreate, constraints);
|
||||
|
||||
constraints.anchor = GridBagConstraints.CENTER;
|
||||
constraints.gridx = 0;
|
||||
constraints.gridy = 0;
|
||||
container.add(buttonModific, constraints);
|
||||
|
||||
constraints.anchor = GridBagConstraints.WEST;
|
||||
constraints.gridx = 0;
|
||||
constraints.gridy = 1;
|
||||
container.add(statusLabel, constraints);
|
||||
|
||||
// Контейнер с кнопками движения
|
||||
Container containerDirection = new Container();
|
||||
containerDirection.setLayout(new GridBagLayout());
|
||||
containerDirection.setPreferredSize(new Dimension(120, 70));
|
||||
GridBagConstraints constraintsDirection = new GridBagConstraints();
|
||||
constraintsDirection.weightx = 40;
|
||||
constraintsDirection.weighty = 40;
|
||||
constraintsDirection.gridwidth = 2;
|
||||
constraintsDirection.gridheight = 1;
|
||||
// Кнопка Up
|
||||
try {
|
||||
BufferedImage bufferedImage = ImageIO.read(new File("C:\\Users\\User\\IdeaProjects\\ProjectAirFighterHard\\AirFighter\\Images\\Up.png"));
|
||||
Image imageUp = bufferedImage.getScaledInstance(30, 30, Image.SCALE_DEFAULT);
|
||||
ImageIcon iconUp = new ImageIcon(imageUp);
|
||||
buttonUp = new JButton(iconUp);
|
||||
buttonUp.setPreferredSize(new Dimension(30, 30));
|
||||
buttonUp.setContentAreaFilled(false);
|
||||
buttonUp.setBorderPainted(false);
|
||||
buttonUp.setActionCommand(Direction.Up.name());
|
||||
buttonUp.addActionListener(actionListenerDirection);
|
||||
constraintsDirection.gridx = 1;
|
||||
constraintsDirection.gridy = 0;
|
||||
containerDirection.add(buttonUp, constraintsDirection);
|
||||
}catch (IOException e){}
|
||||
// Кнопка Down
|
||||
try {
|
||||
BufferedImage bufferedImage = ImageIO.read(new File("C:\\Users\\User\\IdeaProjects\\ProjectAirFighterHard\\AirFighter\\Images\\Down.png"));
|
||||
Image imageDown = bufferedImage.getScaledInstance(30, 30, Image.SCALE_DEFAULT);
|
||||
ImageIcon iconDown = new ImageIcon(imageDown);
|
||||
buttonDown = new JButton(iconDown);
|
||||
buttonDown.setActionCommand(Direction.Down.name());
|
||||
buttonDown.addActionListener(actionListenerDirection);
|
||||
buttonDown.setPreferredSize(new Dimension(30, 30));
|
||||
buttonDown.setContentAreaFilled(false);
|
||||
buttonDown.setBorderPainted(false);
|
||||
constraintsDirection.gridx = 1;
|
||||
constraintsDirection.gridy = 1;
|
||||
containerDirection.add(buttonDown, constraintsDirection);
|
||||
}catch (IOException e){}
|
||||
// Кнопка Left
|
||||
try {
|
||||
BufferedImage bufferedImage = ImageIO.read(new File("C:\\Users\\User\\IdeaProjects\\ProjectAirFighterHard\\AirFighter\\Images\\Left.png"));
|
||||
Image imageLeft = bufferedImage.getScaledInstance(30, 30, Image.SCALE_DEFAULT);
|
||||
ImageIcon iconLeft = new ImageIcon(imageLeft);
|
||||
buttonLeft = new JButton(iconLeft);
|
||||
buttonLeft.setActionCommand(Direction.Left.name());
|
||||
buttonLeft.addActionListener(actionListenerDirection);
|
||||
buttonLeft.setPreferredSize(new Dimension(30, 30));
|
||||
buttonLeft.setContentAreaFilled(false);
|
||||
buttonLeft.setBorderPainted(false);
|
||||
constraintsDirection.fill = GridBagConstraints.WEST;
|
||||
constraintsDirection.gridx = 0;
|
||||
containerDirection.add(buttonLeft, constraintsDirection);
|
||||
}catch (IOException e){}
|
||||
// Кнопка Right
|
||||
try {
|
||||
BufferedImage bufferedImage = ImageIO.read(new File("C:\\Users\\User\\IdeaProjects\\ProjectAirFighterHard\\AirFighter\\Images\\Right.png"));
|
||||
Image imageRight = bufferedImage.getScaledInstance(30, 30, Image.SCALE_DEFAULT);
|
||||
ImageIcon iconRight = new ImageIcon(imageRight);
|
||||
buttonRight = new JButton(iconRight);
|
||||
buttonRight.setActionCommand(Direction.Right.name());
|
||||
buttonRight.addActionListener(actionListenerDirection);
|
||||
buttonRight.setPreferredSize(new Dimension(30, 30));
|
||||
buttonRight.setContentAreaFilled(false);
|
||||
buttonRight.setBorderPainted(false);
|
||||
constraintsDirection.fill = GridBagConstraints.EAST;
|
||||
constraintsDirection.gridx = 2;
|
||||
containerDirection.add(buttonRight, constraintsDirection);
|
||||
}catch (IOException e){}
|
||||
|
||||
constraints.anchor = GridBagConstraints.EAST;
|
||||
constraints.gridx = 1;
|
||||
constraints.gridy = 0;
|
||||
container.add(containerDirection, constraints);
|
||||
|
||||
add(container, BorderLayout.SOUTH);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
// Создание формы
|
||||
FormMap _formMap = new FormMap();
|
||||
_formMap.setSize (800,600);
|
||||
_formMap.getRootPane().setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 10));
|
||||
_formMap.addWindowListener (new WindowAdapter () {
|
||||
public void windowClosing (WindowEvent e) {
|
||||
e.getWindow ().dispose ();
|
||||
}
|
||||
});
|
||||
_formMap.setVisible(true);
|
||||
}
|
||||
}
|
7
AirFighter/src/IDrawningEngine.java
Normal file
7
AirFighter/src/IDrawningEngine.java
Normal file
@ -0,0 +1,7 @@
|
||||
import java.awt.*;
|
||||
|
||||
public interface IDrawningEngine {
|
||||
void SetCodeEngine(int code);
|
||||
void DrawEngine(Graphics g, int startX, int startY, Color _bodyColor);
|
||||
void Draw(Graphics g, int startX, int startY, Color _bodyColor);
|
||||
}
|
19
AirFighter/src/IDrawningObject.java
Normal file
19
AirFighter/src/IDrawningObject.java
Normal file
@ -0,0 +1,19 @@
|
||||
import java.awt.*;
|
||||
|
||||
public interface IDrawningObject {
|
||||
float Step();
|
||||
|
||||
void SetObject(int var1, int var2, int var3, int var4);
|
||||
|
||||
void MoveObject(Direction var1);
|
||||
|
||||
void DrawningObject(Graphics var1);
|
||||
|
||||
float GetLeftPosition();
|
||||
|
||||
float GetRightPosition();
|
||||
|
||||
float GetTopPosition();
|
||||
|
||||
float GetBottomPosition();
|
||||
}
|
29
AirFighter/src/ModelClassicEngine.java
Normal file
29
AirFighter/src/ModelClassicEngine.java
Normal file
@ -0,0 +1,29 @@
|
||||
import java.awt.*;
|
||||
// Класс отрисовки двигателей
|
||||
public class ModelClassicEngine implements IDrawningEngine{
|
||||
private Engine _engine;
|
||||
public void SetCodeEngine(int code){
|
||||
_engine = Engine.getByCode(code);
|
||||
}
|
||||
// Отрисовка двигателей
|
||||
public void DrawEngine(Graphics g, int startX, int startY, Color _bodyColor){
|
||||
g.setColor(_bodyColor);
|
||||
g.fillRect(startX, startY, 13, 5);
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawRect(startX, startY, 13, 5);
|
||||
}
|
||||
public void Draw(Graphics g, int startX, int startY, Color _bodyColor){
|
||||
if(_engine.getEngineCode() >= 2) {
|
||||
DrawEngine(g, startX + 30, startY + 15, _bodyColor);
|
||||
DrawEngine(g, startX + 30, startY + 50, _bodyColor);
|
||||
}
|
||||
if(_engine.getEngineCode() >= 4){
|
||||
DrawEngine(g, startX + 30, startY + 22, _bodyColor);
|
||||
DrawEngine(g, startX + 30, startY + 43, _bodyColor);
|
||||
}
|
||||
if(_engine.getEngineCode() >= 6){
|
||||
DrawEngine(g, startX + 30, startY + 8, _bodyColor);
|
||||
DrawEngine(g, startX + 30, startY + 57, _bodyColor);
|
||||
}
|
||||
}
|
||||
}
|
32
AirFighter/src/ModelJetEngine.java
Normal file
32
AirFighter/src/ModelJetEngine.java
Normal file
@ -0,0 +1,32 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class ModelJetEngine implements IDrawningEngine{
|
||||
private Engine _engine;
|
||||
public void SetCodeEngine(int code){
|
||||
_engine = Engine.getByCode(code);
|
||||
}
|
||||
// Отрисовка двигателя
|
||||
public void DrawEngine(Graphics g, int startX, int startY, Color _bodyColor){
|
||||
int[] pointX = new int[]{startX, startX + 5, startX + 15, startX + 15, startX + 5, startX, startX};
|
||||
int[] pointY = new int[]{startY + 1, startY, startY, startY + 5, startY + 5, startY + 4, startY + 1};
|
||||
g.setColor(_bodyColor);
|
||||
g.fillPolygon(pointX, pointY, 6);
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawPolygon(pointX, pointY, 7);
|
||||
}
|
||||
// Отрисовка двигателей
|
||||
public void Draw(Graphics g, int startX, int startY, Color _bodyColor){
|
||||
if(_engine.getEngineCode() >= 2) {
|
||||
DrawEngine(g, startX + 30, startY + 15, _bodyColor);
|
||||
DrawEngine(g, startX + 30, startY + 50, _bodyColor);
|
||||
}
|
||||
if(_engine.getEngineCode() >= 4){
|
||||
DrawEngine(g, startX + 30, startY + 22, _bodyColor);
|
||||
DrawEngine(g, startX + 30, startY + 43, _bodyColor);
|
||||
}
|
||||
if(_engine.getEngineCode() >= 6){
|
||||
DrawEngine(g, startX + 30, startY + 8, _bodyColor);
|
||||
DrawEngine(g, startX + 30, startY + 57, _bodyColor);
|
||||
}
|
||||
}
|
||||
}
|
31
AirFighter/src/ModelScrewEngine.java
Normal file
31
AirFighter/src/ModelScrewEngine.java
Normal file
@ -0,0 +1,31 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class ModelScrewEngine implements IDrawningEngine{
|
||||
private Engine _engine;
|
||||
public void SetCodeEngine(int code){
|
||||
_engine = Engine.getByCode(code);
|
||||
}
|
||||
public void DrawEngine(Graphics g, int startX, int startY, Color _bodyColor){
|
||||
g.setColor(_bodyColor);
|
||||
g.fillRect(startX, startY, 13, 5);
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawRect(startX, startY, 13, 5);
|
||||
g.drawLine(startX + 13, startY + 2, startX + 15, startY + 2);
|
||||
g.drawLine(startX + 15, startY, startX + 15, startY + 5);
|
||||
}
|
||||
// Отрисовка двигателей
|
||||
public void Draw(Graphics g, int startX, int startY, Color _bodyColor){
|
||||
if(_engine.getEngineCode() >= 2) {
|
||||
DrawEngine(g, startX + 30, startY + 15, _bodyColor);
|
||||
DrawEngine(g, startX + 30, startY + 50, _bodyColor);
|
||||
}
|
||||
if(_engine.getEngineCode() >= 4){
|
||||
DrawEngine(g, startX + 30, startY + 22, _bodyColor);
|
||||
DrawEngine(g, startX + 30, startY + 43, _bodyColor);
|
||||
}
|
||||
if(_engine.getEngineCode() >= 6){
|
||||
DrawEngine(g, startX + 30, startY + 8, _bodyColor);
|
||||
DrawEngine(g, startX + 30, startY + 57, _bodyColor);
|
||||
}
|
||||
}
|
||||
}
|
42
AirFighter/src/SimpleMap.java
Normal file
42
AirFighter/src/SimpleMap.java
Normal file
@ -0,0 +1,42 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class SimpleMap extends AbstractMap{
|
||||
// Цвет открытого участка
|
||||
private Color roadColor = new Color(153, 217, 234);
|
||||
// Цвет закрытого участка
|
||||
private Color barrierColor = Color.GRAY;
|
||||
@Override
|
||||
protected void GenerateMap() {
|
||||
_map = new int[100][100];
|
||||
_size_x = (float)_width / _map[0].length;
|
||||
_size_y = (float)_height / _map.length;
|
||||
int counter = 0;
|
||||
for (int i = 0; i < _map.length; ++i)
|
||||
{
|
||||
for (int j = 0; j < _map[0].length; ++j)
|
||||
{
|
||||
_map[i][j] = _freeRoad;
|
||||
}
|
||||
}
|
||||
while (counter < 50)
|
||||
{
|
||||
int x = (int)(Math.random() * 100);
|
||||
int y = (int)(Math.random() * 100);
|
||||
if (_map[x][y] == _freeRoad)
|
||||
{
|
||||
_map[x][y] = _barrier;
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
protected void DrawRoadPart(Graphics g, int i, int j) {
|
||||
g.setColor(roadColor);
|
||||
g.fillRect((int)(i * _size_x), (int)(j * _size_y), (int)((i + 1) * _size_x), (int)((j + 1) * _size_y));
|
||||
}
|
||||
@Override
|
||||
protected void DrawBarrierPart(Graphics g, int i, int j) {
|
||||
g.setColor(barrierColor);
|
||||
g.fillRect((int)(i * _size_x), (int)(j * _size_y), (int)((i + 1) * _size_x), (int)((j + 1) * _size_y));
|
||||
}
|
||||
}
|
49
AirFighter/src/StormMap.java
Normal file
49
AirFighter/src/StormMap.java
Normal file
@ -0,0 +1,49 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class StormMap extends AbstractMap{
|
||||
// Цвет открытого участка
|
||||
private Color roadColor = new Color(168, 168, 168);
|
||||
// Дополнительный цвет открытого участка
|
||||
private Color dopRoadColor = Color.LIGHT_GRAY;
|
||||
// Цвет закрытого участка
|
||||
private Color barrierColor = Color.BLACK;
|
||||
@Override
|
||||
protected void GenerateMap() {
|
||||
_map = new int[100][100];
|
||||
_size_x = (float)_width / _map[0].length;
|
||||
_size_y = (float)_height / _map.length;
|
||||
int counter = 0;
|
||||
for (int i = 0; i < _map.length; ++i)
|
||||
{
|
||||
for (int j = 0; j < _map[0].length; ++j)
|
||||
{
|
||||
_map[i][j] = _freeRoad;
|
||||
}
|
||||
}
|
||||
while (counter < 50)
|
||||
{
|
||||
int x = (int)(Math.random() * 100);
|
||||
int y = (int)(Math.random() * 100);
|
||||
if (_map[x][y] == _freeRoad)
|
||||
{
|
||||
_map[x][y] = _barrier;
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
protected void DrawRoadPart(Graphics g, int i, int j) {
|
||||
if((int)(Math.random() * 2) == 1){
|
||||
g.setColor(roadColor);
|
||||
g.fillRect((int)(i * _size_x), (int)(j * _size_y), (int)((i + 1) * _size_x), (int)((j + 1) * _size_y));
|
||||
}else {
|
||||
g.setColor(dopRoadColor);
|
||||
g.fillRect((int) (i * _size_x), (int) (j * _size_y), (int) ((i + 1) * _size_x), (int) ((j + 1) * _size_y));
|
||||
}
|
||||
}
|
||||
@Override
|
||||
protected void DrawBarrierPart(Graphics g, int i, int j) {
|
||||
g.setColor(barrierColor);
|
||||
g.fillRect((int) (i * _size_x), (int) (j * _size_y), (int) ((i + 1) * _size_x), (int) ((j + 1) * _size_y));
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user