Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
de6f7d3342 | ||
|
0d9c3714a7 | ||
|
e7c253b1c7 | ||
a879f47bfe |
120
AirBomber/src/AirBomberPackage/AbstractMap.java
Normal file
120
AirBomber/src/AirBomberPackage/AbstractMap.java
Normal file
@ -0,0 +1,120 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package AirBomberPackage;
|
||||
import java.util.Random;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
/**
|
||||
*
|
||||
* @author Андрей
|
||||
*/
|
||||
public abstract class AbstractMap {
|
||||
private IDrawingObject _drawningObject = null;
|
||||
protected int[][] _map = null;
|
||||
protected int _width;
|
||||
protected int _height;
|
||||
protected int _size_x;
|
||||
protected int _size_y;
|
||||
protected final Random _random = new Random();
|
||||
protected final int _freeRoad = 0;
|
||||
protected final int _barrier = 1;
|
||||
|
||||
public BufferedImage CreateMap(int width, int height, IDrawingObject drawningObject)
|
||||
{
|
||||
_width = width;
|
||||
_height = height;
|
||||
_drawningObject = drawningObject;
|
||||
GenerateMap();
|
||||
while (!SetObjectOnMap())
|
||||
{
|
||||
GenerateMap();
|
||||
}
|
||||
return DrawMapWithObject();
|
||||
}
|
||||
public BufferedImage MoveObject(Direction direction)
|
||||
{
|
||||
if (_drawningObject == null) return DrawMapWithObject();
|
||||
boolean canMove = true;
|
||||
switch (direction)
|
||||
{
|
||||
case LEFT:
|
||||
if (!checkForBarriers(0, -1 * _drawningObject.getStep(), -1 * _drawningObject.getStep(), 0)) canMove = false;
|
||||
break;
|
||||
case RIGHT:
|
||||
if (!checkForBarriers(0, _drawningObject.getStep(), _drawningObject.getStep(), 0)) canMove = false;
|
||||
break;
|
||||
case UP:
|
||||
if (!checkForBarriers(-1 * _drawningObject.getStep(), 0, 0, -1 * _drawningObject.getStep())) canMove = false;
|
||||
break;
|
||||
case DOWN:
|
||||
if (!checkForBarriers(_drawningObject.getStep(), 0, 0, _drawningObject.getStep())) canMove = false;
|
||||
break;
|
||||
}
|
||||
if (canMove)
|
||||
{
|
||||
_drawningObject.MoveObject(direction);
|
||||
}
|
||||
return DrawMapWithObject();
|
||||
}
|
||||
private boolean SetObjectOnMap()
|
||||
{
|
||||
if (_drawningObject == null || _map == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
int x = _random.nextInt(0, 10);
|
||||
int y = _random.nextInt(0, 10);
|
||||
_drawningObject.SetObject(x, y, _width, _height);
|
||||
if (!checkForBarriers(0,0,0,0)) return false;
|
||||
return true;
|
||||
}
|
||||
private BufferedImage DrawMapWithObject()
|
||||
{
|
||||
BufferedImage bmp = new BufferedImage(_width, _height, BufferedImage.TYPE_INT_ARGB);
|
||||
if (_drawningObject == null || _map == null)
|
||||
{
|
||||
return bmp;
|
||||
}
|
||||
Graphics2D gr = bmp.createGraphics();
|
||||
for (int i = 0; i < _map.length; ++i)
|
||||
{
|
||||
for (int j = 0; j < _map[i].length; ++j)
|
||||
{
|
||||
if (_map[i][j] == _freeRoad)
|
||||
{
|
||||
DrawRoadPart(gr, i, j);
|
||||
}
|
||||
else if (_map[i][j] == _barrier)
|
||||
{
|
||||
DrawBarrierPart(gr, i, j);
|
||||
}
|
||||
}
|
||||
}
|
||||
_drawningObject.DrawingObject(gr);
|
||||
return bmp;
|
||||
}
|
||||
|
||||
private boolean checkForBarriers(float topOffset, float rightOffset, float leftOffset, float bottomOffset)
|
||||
{
|
||||
float[] position = _drawningObject.GetCurrentPosition();
|
||||
int top = (int)((position[1] + topOffset) / _size_y);
|
||||
int right = (int)((position[2] + rightOffset) / _size_x);
|
||||
int left = (int)((position[0] + leftOffset) / _size_x);
|
||||
int bottom = (int)((position[3] + bottomOffset) / _size_y);
|
||||
if (top < 0 || left < 0 || right >= _map[0].length || bottom >= _map.length) return false;
|
||||
for (int i = top; i <= bottom; i++)
|
||||
{
|
||||
for (int j = left; j <= right; j++)
|
||||
{
|
||||
if (_map[j][i] == 1) return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
protected abstract void GenerateMap();
|
||||
protected abstract void DrawRoadPart(Graphics g, int i, int j);
|
||||
protected abstract void DrawBarrierPart(Graphics g, int i, int j);
|
||||
}
|
31
AirBomber/src/AirBomberPackage/CanvasMy.java
Normal file
31
AirBomber/src/AirBomberPackage/CanvasMy.java
Normal file
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package AirBomberPackage;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Андрей
|
||||
*/
|
||||
public class CanvasMy extends JComponent {
|
||||
public CanvasMy(){
|
||||
super();
|
||||
}
|
||||
|
||||
private DrawingAirBomber _airBomber = null;
|
||||
|
||||
public void setAirBomber(DrawingAirBomber _airBomber) {
|
||||
this._airBomber = _airBomber;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paintComponent(Graphics g){
|
||||
super.paintComponent(g);
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
if (_airBomber != null) _airBomber.DrawTransport(g2d);
|
||||
}
|
||||
}
|
82
AirBomber/src/AirBomberPackage/CityMap.java
Normal file
82
AirBomber/src/AirBomberPackage/CityMap.java
Normal file
@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package AirBomberPackage;
|
||||
import java.awt.*;
|
||||
/**
|
||||
*
|
||||
* @author Андрей
|
||||
*/
|
||||
public class CityMap extends AbstractMap {
|
||||
/// <summary>
|
||||
/// Цвет участка закрытого
|
||||
/// </summary>
|
||||
private final Color barrierColor = Color.GRAY;
|
||||
/// <summary>
|
||||
/// Цвет участка открытого
|
||||
/// </summary>
|
||||
private final Color roadColor = Color.CYAN;
|
||||
@Override
|
||||
protected void DrawBarrierPart(Graphics g, int i, int j)
|
||||
{
|
||||
g.setColor(barrierColor);
|
||||
g.fillRect(i * _size_x, j * _size_y, _size_x, _size_y);
|
||||
g.setColor(Color.BLACK);
|
||||
}
|
||||
@Override
|
||||
protected void DrawRoadPart(Graphics g, int i, int j)
|
||||
{
|
||||
g.setColor(roadColor);
|
||||
g.fillRect(i * _size_x, j * _size_y, _size_x, _size_y);
|
||||
g.setColor(Color.BLACK);
|
||||
}
|
||||
@Override
|
||||
protected void GenerateMap()
|
||||
{
|
||||
_map = new int[100][100];
|
||||
_size_x = _width / _map.length;
|
||||
_size_y = _height / _map[0].length;
|
||||
int buildingCounter = 0;
|
||||
for (int i = 0; i < _map.length; ++i)
|
||||
{
|
||||
for (int j = 0; j < _map[0].length; ++j)
|
||||
{
|
||||
_map[i][j] = _freeRoad;
|
||||
}
|
||||
}
|
||||
while (buildingCounter < 10)
|
||||
{
|
||||
int x = _random.nextInt(0, 89);
|
||||
int y = _random.nextInt(0, 89);
|
||||
int buildingWidth = _random.nextInt(2, 10);
|
||||
int buildingHeight = _random.nextInt(2, 10);
|
||||
if (x + buildingWidth >= _map.length) x = _random.nextInt(_map.length - buildingWidth - 1, _map.length);
|
||||
if (y + buildingHeight >= _map[0].length) y = _random.nextInt(_map[0].length - buildingHeight - 1, _map[0].length);
|
||||
|
||||
boolean isFreeSpace = true;
|
||||
for (int i = x; i < x + buildingWidth; i++)
|
||||
{
|
||||
for (int j = y; j < y + buildingHeight; j++)
|
||||
{
|
||||
if (_map[i][j] != _freeRoad)
|
||||
{
|
||||
isFreeSpace = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isFreeSpace)
|
||||
{
|
||||
for (int i = x; i < x + buildingWidth; i++)
|
||||
{
|
||||
for (int j = y; j < y + buildingHeight; j++)
|
||||
{
|
||||
_map[i][j] = _barrier;
|
||||
}
|
||||
}
|
||||
buildingCounter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
17
AirBomber/src/AirBomberPackage/Direction.java
Normal file
17
AirBomber/src/AirBomberPackage/Direction.java
Normal file
@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package AirBomberPackage;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Андрей
|
||||
*/
|
||||
public enum Direction {
|
||||
NONE,
|
||||
UP,
|
||||
DOWN,
|
||||
LEFT,
|
||||
RIGHT
|
||||
}
|
260
AirBomber/src/AirBomberPackage/DrawingAirBomber.java
Normal file
260
AirBomber/src/AirBomberPackage/DrawingAirBomber.java
Normal file
@ -0,0 +1,260 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package AirBomberPackage;
|
||||
import java.awt.*;
|
||||
import java.util.Random;
|
||||
/**
|
||||
*
|
||||
* @author Андрей
|
||||
*/
|
||||
public class DrawingAirBomber {
|
||||
protected EntityAirBomber AirBomber;
|
||||
public IDrawingObjectDop drawingEngines;
|
||||
public int _startPosX;
|
||||
public int _startPosY;
|
||||
private Integer _pictureWidth = null;
|
||||
private Integer _pictureHeight = null;
|
||||
private int _airBomberWidth = 110;
|
||||
private int _airBomberHeight = 100;
|
||||
|
||||
public DrawingAirBomber(int speed, float weight, Color bodyColor, int numberOfEngines, EnginesType enginesType){
|
||||
AirBomber = new EntityAirBomber(speed, weight, bodyColor);
|
||||
switch (enginesType) {
|
||||
case RECTANGLE:
|
||||
drawingEngines = new DrawingEngines();
|
||||
break;
|
||||
case TRIANGLE:
|
||||
drawingEngines = new DrawingEnginesTriangle();
|
||||
break;
|
||||
case OVAL:
|
||||
drawingEngines = new DrawingEnginesOval();
|
||||
break;
|
||||
default:
|
||||
throw new AssertionError();
|
||||
}
|
||||
drawingEngines.setNumberOfEngines(numberOfEngines);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес бомбардировщика</param>
|
||||
/// <param name="bodyColor">Цвет корпуса</param>
|
||||
/// <param name="carWidth">Ширина отрисовки бомбардировщика</param>
|
||||
/// <param name="carHeight">Высота отрисовки бомбардировщика</param>
|
||||
protected DrawingAirBomber(int speed, float weight, Color bodyColor, int numberOfEngines, EnginesType enginesType, int airBomberWidth, int airBomberHeight)
|
||||
{
|
||||
this(speed, weight, bodyColor, numberOfEngines, enginesType);
|
||||
this._airBomberWidth = airBomberWidth;
|
||||
this._airBomberHeight = airBomberHeight;
|
||||
}
|
||||
|
||||
|
||||
public EntityAirBomber getAirBomber() {
|
||||
return AirBomber;
|
||||
}
|
||||
|
||||
public void SetPosition(int x, int y, int width, int height){
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
if (_pictureWidth == null || _pictureHeight == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Random rd = new Random();
|
||||
_startPosX = x + _airBomberWidth >= _pictureWidth ? rd.nextInt(0, _pictureWidth - 1 - _airBomberWidth) : x;
|
||||
_startPosY = y + _airBomberHeight >= _pictureHeight ? rd.nextInt(0, _pictureHeight - 1 - _airBomberHeight) : y;
|
||||
}
|
||||
|
||||
public void MoveTransport(Direction direction)
|
||||
{
|
||||
if (_pictureWidth == null || _pictureHeight == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
switch (direction)
|
||||
{
|
||||
// вправо
|
||||
case RIGHT:
|
||||
if (_startPosX + _airBomberWidth + AirBomber.Step < _pictureWidth)
|
||||
{
|
||||
_startPosX += AirBomber.Step;
|
||||
}
|
||||
break;
|
||||
//влево
|
||||
case LEFT:
|
||||
if (_startPosX - AirBomber.Step > 0)
|
||||
{
|
||||
_startPosX -= AirBomber.Step;
|
||||
}
|
||||
break;
|
||||
//вверх
|
||||
case UP:
|
||||
if (_startPosY - AirBomber.Step > 0)
|
||||
{
|
||||
_startPosY -= AirBomber.Step;
|
||||
}
|
||||
break;
|
||||
//вниз
|
||||
case DOWN:
|
||||
if (_startPosY + _airBomberHeight + AirBomber.Step < _pictureHeight)
|
||||
{
|
||||
_startPosY += AirBomber.Step;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void DrawTransport(Graphics2D g)
|
||||
{
|
||||
if (_startPosX < 0 || _startPosY < 0
|
||||
|| _pictureHeight == null || _pictureWidth == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int _startPosXInt = (int)_startPosX;
|
||||
int _startPosYInt = (int)_startPosY;
|
||||
|
||||
//отрисовка двигателей
|
||||
drawingEngines.drawEngines(g, _startPosXInt, _startPosYInt, AirBomber.getBodyColor());
|
||||
|
||||
//отрисовка кабины
|
||||
int[] cabinX =
|
||||
{
|
||||
_startPosXInt + 5,
|
||||
_startPosXInt + 20,
|
||||
_startPosXInt + 20
|
||||
};
|
||||
|
||||
int[] cabinY =
|
||||
{
|
||||
_startPosYInt + 50,
|
||||
_startPosYInt + 40,
|
||||
_startPosYInt + 60
|
||||
};
|
||||
|
||||
g.fillPolygon(cabinX, cabinY, cabinX.length);
|
||||
g.setColor(AirBomber.getBodyColor());
|
||||
//отрисовка корпуса
|
||||
g.fillRect(_startPosXInt + 20, _startPosYInt + 40, 90, 20);
|
||||
|
||||
//отрисовка правого крыла
|
||||
int[] rightWingX =
|
||||
{
|
||||
_startPosXInt + 50,
|
||||
_startPosXInt + 50,
|
||||
_startPosXInt + 60,
|
||||
_startPosXInt + 70
|
||||
};
|
||||
|
||||
int[] rightWingY =
|
||||
{
|
||||
_startPosYInt + 40,
|
||||
_startPosYInt,
|
||||
_startPosYInt,
|
||||
_startPosYInt + 40
|
||||
};
|
||||
|
||||
g.fillPolygon(rightWingX, rightWingY, rightWingX.length);
|
||||
|
||||
//отрисовка левого крыла
|
||||
int[] leftWingX =
|
||||
{
|
||||
_startPosXInt + 50,
|
||||
_startPosXInt + 50,
|
||||
_startPosXInt + 60,
|
||||
_startPosXInt + 70
|
||||
};
|
||||
|
||||
int[] leftWingY =
|
||||
{
|
||||
_startPosYInt + 60,
|
||||
_startPosYInt + 100,
|
||||
_startPosYInt + 100,
|
||||
_startPosYInt + 60
|
||||
};
|
||||
|
||||
g.fillPolygon(leftWingX, leftWingY, leftWingX.length);
|
||||
|
||||
//отрисовка хвоста (справа)
|
||||
int[] rightTailX =
|
||||
{
|
||||
_startPosXInt + 95,
|
||||
_startPosXInt + 95,
|
||||
_startPosXInt + 110,
|
||||
_startPosXInt + 110
|
||||
};
|
||||
|
||||
int[] rightTailY =
|
||||
{
|
||||
_startPosYInt + 40,
|
||||
_startPosYInt + 30,
|
||||
_startPosYInt + 15,
|
||||
_startPosYInt + 40
|
||||
};
|
||||
|
||||
g.fillPolygon(rightTailX, rightTailY, rightTailX.length);
|
||||
|
||||
//отрисовка хвоста (слева)
|
||||
int[] leftTailX =
|
||||
{
|
||||
_startPosXInt + 95,
|
||||
_startPosXInt + 95,
|
||||
_startPosXInt + 110,
|
||||
_startPosXInt + 110
|
||||
};
|
||||
|
||||
int[] leftTailY =
|
||||
{
|
||||
_startPosYInt + 60,
|
||||
_startPosYInt + 70,
|
||||
_startPosYInt + 85,
|
||||
_startPosYInt + 60
|
||||
};
|
||||
|
||||
g.fillPolygon(leftTailX, leftTailY, leftTailX.length);
|
||||
|
||||
g.setColor(Color.BLACK);
|
||||
|
||||
g.drawRect(_startPosXInt + 20, _startPosYInt + 40, 90, 20);
|
||||
g.drawPolygon(rightWingX, rightWingY, rightWingX.length);
|
||||
g.drawPolygon(leftWingX, leftWingY, leftWingX.length);
|
||||
g.drawPolygon(rightTailX, rightTailY, rightTailX.length);
|
||||
g.drawPolygon(leftTailX, leftTailY, leftTailX.length);
|
||||
g.drawLine(_startPosXInt, _startPosYInt + 50, _startPosXInt + 5, _startPosYInt + 50);
|
||||
}
|
||||
|
||||
public float [] GetCurrentPosition()
|
||||
{
|
||||
float[] pos = new float[4];
|
||||
pos[0] = _startPosX;
|
||||
pos[1] = _startPosY;
|
||||
pos[2] = _startPosX + _airBomberWidth;
|
||||
pos[3] = _startPosY + _airBomberHeight;
|
||||
return pos;
|
||||
}
|
||||
|
||||
public void ChangeBorders(int width, int height)
|
||||
{
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
if (_pictureWidth <= _airBomberWidth || _pictureHeight <= _airBomberHeight)
|
||||
{
|
||||
_pictureWidth = null;
|
||||
_pictureHeight = null;
|
||||
return;
|
||||
}
|
||||
if (_startPosX + _airBomberWidth > _pictureWidth)
|
||||
{
|
||||
_startPosX = _pictureWidth - _airBomberWidth;
|
||||
}
|
||||
if (_startPosY + _airBomberHeight > _pictureHeight)
|
||||
{
|
||||
_startPosY = _pictureHeight - _airBomberHeight;
|
||||
}
|
||||
}
|
||||
}
|
61
AirBomber/src/AirBomberPackage/DrawingEngines.java
Normal file
61
AirBomber/src/AirBomberPackage/DrawingEngines.java
Normal file
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package AirBomberPackage;
|
||||
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Color;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Андрей
|
||||
*/
|
||||
public class DrawingEngines implements IDrawingObjectDop {
|
||||
private Engines engines = null;
|
||||
private int numberOfEngines;
|
||||
@Override
|
||||
public int getNumberOfEngines() {
|
||||
return numberOfEngines;
|
||||
}
|
||||
@Override
|
||||
public void setNumberOfEngines(int numberOfEngines) {
|
||||
if (numberOfEngines != 2 && numberOfEngines != 4 && numberOfEngines != 6) return;
|
||||
this.numberOfEngines = numberOfEngines;
|
||||
switch (this.numberOfEngines) {
|
||||
case 2:
|
||||
engines = Engines.TWO;
|
||||
break;
|
||||
case 4:
|
||||
engines = Engines.FOUR;
|
||||
break;
|
||||
case 6:
|
||||
engines = Engines.SIX;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void drawEngine(Graphics2D g, int startPosX, int startPosY, int yOffset, Color bodyColor){
|
||||
g.setColor(bodyColor);
|
||||
g.fillRect(startPosX + 45, startPosY + 40 + yOffset, 5, 5);
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawRect(startPosX + 45, startPosY + 40 + yOffset, 5, 5);
|
||||
}
|
||||
@Override
|
||||
public void drawEngines(Graphics2D g, int startPosX, int startPosY, Color bodyColor){
|
||||
if (engines == null) return;
|
||||
|
||||
switch (engines) {
|
||||
case SIX:
|
||||
drawEngine(g, startPosX, startPosY, -5 - 5 - 20, bodyColor);
|
||||
drawEngine(g, startPosX, startPosY, 20 + 5 + 20, bodyColor);
|
||||
case FOUR:
|
||||
drawEngine(g, startPosX, startPosY, -5 - 5 - 10, bodyColor);
|
||||
drawEngine(g, startPosX, startPosY, 20 + 5 + 10, bodyColor);
|
||||
case TWO:
|
||||
drawEngine(g, startPosX, startPosY, -5 - 5, bodyColor);
|
||||
drawEngine(g, startPosX, startPosY, 20 + 5, bodyColor);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
64
AirBomber/src/AirBomberPackage/DrawingEnginesOval.java
Normal file
64
AirBomber/src/AirBomberPackage/DrawingEnginesOval.java
Normal file
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package AirBomberPackage;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Андрей
|
||||
*/
|
||||
public class DrawingEnginesOval implements IDrawingObjectDop {
|
||||
private Engines engines = null;
|
||||
private int numberOfEngines;
|
||||
@Override
|
||||
public int getNumberOfEngines() {
|
||||
return numberOfEngines;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNumberOfEngines(int numberOfEngines) {
|
||||
if (numberOfEngines != 2 && numberOfEngines != 4 && numberOfEngines != 6) return;
|
||||
this.numberOfEngines = numberOfEngines;
|
||||
switch (this.numberOfEngines) {
|
||||
case 2:
|
||||
engines = Engines.TWO;
|
||||
break;
|
||||
case 4:
|
||||
engines = Engines.FOUR;
|
||||
break;
|
||||
case 6:
|
||||
engines = Engines.SIX;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawEngine(Graphics2D g, int startPosX, int startPosY, int yOffset, Color bodyColor) {
|
||||
g.setColor(bodyColor);
|
||||
g.fillOval(startPosX + 45, startPosY + 40 + yOffset, 5, 5);
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawOval(startPosX + 45, startPosY + 40 + yOffset, 5, 5);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawEngines(Graphics2D g, int startPosX, int startPosY, Color bodyColor) {
|
||||
if (engines == null) return;
|
||||
|
||||
switch (engines) {
|
||||
case SIX:
|
||||
drawEngine(g, startPosX, startPosY, -5 - 5 - 20, bodyColor);
|
||||
drawEngine(g, startPosX, startPosY, 20 + 5 + 20, bodyColor);
|
||||
case FOUR:
|
||||
drawEngine(g, startPosX, startPosY, -5 - 5 - 10, bodyColor);
|
||||
drawEngine(g, startPosX, startPosY, 20 + 5 + 10, bodyColor);
|
||||
case TWO:
|
||||
drawEngine(g, startPosX, startPosY, -5 - 5, bodyColor);
|
||||
drawEngine(g, startPosX, startPosY, 20 + 5, bodyColor);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
74
AirBomber/src/AirBomberPackage/DrawingEnginesTriangle.java
Normal file
74
AirBomber/src/AirBomberPackage/DrawingEnginesTriangle.java
Normal file
@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package AirBomberPackage;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Андрей
|
||||
*/
|
||||
public class DrawingEnginesTriangle implements IDrawingObjectDop {
|
||||
private Engines engines = null;
|
||||
private int numberOfEngines;
|
||||
@Override
|
||||
public int getNumberOfEngines() {
|
||||
return numberOfEngines;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNumberOfEngines(int numberOfEngines) {
|
||||
if (numberOfEngines != 2 && numberOfEngines != 4 && numberOfEngines != 6) return;
|
||||
this.numberOfEngines = numberOfEngines;
|
||||
switch (this.numberOfEngines) {
|
||||
case 2:
|
||||
engines = Engines.TWO;
|
||||
break;
|
||||
case 4:
|
||||
engines = Engines.FOUR;
|
||||
break;
|
||||
case 6:
|
||||
engines = Engines.SIX;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawEngine(Graphics2D g, int startPosX, int startPosY, int yOffset, Color bodyColor) {
|
||||
g.setColor(bodyColor);
|
||||
int[] engineX = {
|
||||
startPosX + 45,
|
||||
startPosX + 50,
|
||||
startPosX + 50,
|
||||
};
|
||||
int[] engineY = {
|
||||
startPosY + 42 + yOffset,
|
||||
startPosY + 38 + yOffset,
|
||||
startPosY + 46 + yOffset,
|
||||
};
|
||||
g.fillPolygon(engineX, engineY, engineX.length);
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawPolygon(engineX, engineY, engineX.length);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawEngines(Graphics2D g, int startPosX, int startPosY, Color bodyColor) {
|
||||
if (engines == null) return;
|
||||
|
||||
switch (engines) {
|
||||
case SIX:
|
||||
drawEngine(g, startPosX, startPosY, -5 - 5 - 20, bodyColor);
|
||||
drawEngine(g, startPosX, startPosY, 20 + 5 + 20, bodyColor);
|
||||
case FOUR:
|
||||
drawEngine(g, startPosX, startPosY, -5 - 5 - 10, bodyColor);
|
||||
drawEngine(g, startPosX, startPosY, 20 + 5 + 10, bodyColor);
|
||||
case TWO:
|
||||
drawEngine(g, startPosX, startPosY, -5 - 5, bodyColor);
|
||||
drawEngine(g, startPosX, startPosY, 20 + 5, bodyColor);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
68
AirBomber/src/AirBomberPackage/DrawingHeavyAirBomber.java
Normal file
68
AirBomber/src/AirBomberPackage/DrawingHeavyAirBomber.java
Normal file
@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package AirBomberPackage;
|
||||
import java.awt.*;
|
||||
/**
|
||||
*
|
||||
* @author Андрей
|
||||
*/
|
||||
public class DrawingHeavyAirBomber extends DrawingAirBomber {
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес автомобиля</param>
|
||||
/// <param name="bodyColor">Цвет кузова</param>
|
||||
/// <param name="dopColor">Дополнительный цвет</param>
|
||||
/// <param name="bodyKit">Признак наличия обвеса</param>
|
||||
/// <param name="wing">Признак наличия антикрыла</param>
|
||||
/// <param name="sportLine">Признак наличия гоночной полосы</param>
|
||||
public DrawingHeavyAirBomber(int speed, float weight, Color bodyColor, int numberOfEngines, EnginesType enginesType, Color dopColor, boolean bodyKit, boolean wing, boolean sportLine)
|
||||
{
|
||||
super(speed, weight, bodyColor, numberOfEngines, enginesType, 110, 100);
|
||||
AirBomber = new EntityHeavyAirBomber(speed, weight, bodyColor, dopColor, bodyKit, wing, sportLine);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void DrawTransport(Graphics2D g)
|
||||
{
|
||||
if (!(AirBomber instanceof EntityHeavyAirBomber heavyAirBomber))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (heavyAirBomber.getBombs())
|
||||
{
|
||||
g.setColor(heavyAirBomber.getDopColor());
|
||||
g.fillOval(_startPosX + 45, _startPosY, 20, 10);
|
||||
g.fillOval(_startPosX + 45, _startPosY + 90, 20, 10);
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawOval(_startPosX + 45, _startPosY, 20, 10);
|
||||
g.drawOval(_startPosX + 45, _startPosY + 90, 20, 10);
|
||||
|
||||
}
|
||||
|
||||
super.DrawTransport(g);
|
||||
|
||||
if (heavyAirBomber.getTailLine())
|
||||
{
|
||||
g.setColor(heavyAirBomber.getDopColor());
|
||||
g.fillRect(_startPosX + 95, _startPosY + 30, 15, 5);
|
||||
g.fillRect(_startPosX + 95, _startPosY + 65, 15, 5);
|
||||
g.setColor(Color.BLACK);
|
||||
}
|
||||
|
||||
if (heavyAirBomber.getFuelTank())
|
||||
{
|
||||
g.setColor(heavyAirBomber.getDopColor());
|
||||
g.fillOval(_startPosX + 23, _startPosY + 42, 25, 15);
|
||||
g.fillOval(_startPosX + 53, _startPosY + 42, 25, 15);
|
||||
g.fillOval(_startPosX + 83, _startPosY + 42, 25, 15);
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawOval(_startPosX + 23, _startPosY + 42, 25, 15);
|
||||
g.drawOval(_startPosX + 53, _startPosY + 42, 25, 15);
|
||||
g.drawOval(_startPosX + 83, _startPosY + 42, 25, 15);
|
||||
}
|
||||
}
|
||||
}
|
60
AirBomber/src/AirBomberPackage/DrawingObjectAirBomber.java
Normal file
60
AirBomber/src/AirBomberPackage/DrawingObjectAirBomber.java
Normal file
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package AirBomberPackage;
|
||||
import java.awt.*;
|
||||
/**
|
||||
*
|
||||
* @author Андрей
|
||||
*/
|
||||
public class DrawingObjectAirBomber implements IDrawingObject {
|
||||
private DrawingAirBomber _airBomber = null;
|
||||
|
||||
public DrawingObjectAirBomber(DrawingAirBomber airBomber)
|
||||
{
|
||||
_airBomber = airBomber;
|
||||
Step = _airBomber.AirBomber.Step;
|
||||
}
|
||||
|
||||
public float Step;
|
||||
@Override
|
||||
public float getStep(){
|
||||
return Step;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float[] GetCurrentPosition()
|
||||
{
|
||||
if (_airBomber == null) return null;
|
||||
return _airBomber.GetCurrentPosition();
|
||||
}
|
||||
@Override
|
||||
public void MoveObject(Direction direction)
|
||||
{
|
||||
_airBomber.MoveTransport(direction);
|
||||
}
|
||||
@Override
|
||||
public void SetObject(int x, int y, int width, int height)
|
||||
{
|
||||
_airBomber.SetPosition(x, y, width, height);
|
||||
}
|
||||
|
||||
public DrawingAirBomber getAirBomber(){
|
||||
return _airBomber;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void DrawingObject(Graphics2D g)
|
||||
{
|
||||
if (_airBomber == null) return;
|
||||
if (_airBomber instanceof DrawingHeavyAirBomber heavyAirBomber)
|
||||
{
|
||||
heavyAirBomber.DrawTransport(g);
|
||||
}
|
||||
else
|
||||
{
|
||||
_airBomber.DrawTransport(g);
|
||||
}
|
||||
}
|
||||
}
|
15
AirBomber/src/AirBomberPackage/Engines.java
Normal file
15
AirBomber/src/AirBomberPackage/Engines.java
Normal file
@ -0,0 +1,15 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package AirBomberPackage;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Андрей
|
||||
*/
|
||||
public enum Engines {
|
||||
TWO,
|
||||
FOUR,
|
||||
SIX
|
||||
}
|
15
AirBomber/src/AirBomberPackage/EnginesType.java
Normal file
15
AirBomber/src/AirBomberPackage/EnginesType.java
Normal file
@ -0,0 +1,15 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package AirBomberPackage;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Андрей
|
||||
*/
|
||||
public enum EnginesType {
|
||||
RECTANGLE,
|
||||
TRIANGLE,
|
||||
OVAL
|
||||
}
|
41
AirBomber/src/AirBomberPackage/EntityAirBomber.java
Normal file
41
AirBomber/src/AirBomberPackage/EntityAirBomber.java
Normal file
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package AirBomberPackage;
|
||||
import java.awt.Color;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Андрей
|
||||
*/
|
||||
public class EntityAirBomber {
|
||||
private int Speed;
|
||||
|
||||
private float Weight;
|
||||
|
||||
private Color BodyColor;
|
||||
|
||||
public float Step;
|
||||
|
||||
public int getSpeed() {
|
||||
return Speed;
|
||||
}
|
||||
|
||||
public float getWeight() {
|
||||
return Weight;
|
||||
}
|
||||
|
||||
public Color getBodyColor() {
|
||||
return BodyColor;
|
||||
}
|
||||
|
||||
public EntityAirBomber(int speed, float weight, Color bodyColor){
|
||||
Random rnd = new Random();
|
||||
Speed = speed <= 0 ? rnd.nextInt(50, 150) : speed;
|
||||
Weight = weight <= 0 ? rnd.nextInt(40, 70) : weight;
|
||||
Step = Speed * 100 / Weight;
|
||||
BodyColor = bodyColor;
|
||||
}
|
||||
}
|
63
AirBomber/src/AirBomberPackage/EntityHeavyAirBomber.java
Normal file
63
AirBomber/src/AirBomberPackage/EntityHeavyAirBomber.java
Normal file
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package AirBomberPackage;
|
||||
import java.awt.*;
|
||||
/**
|
||||
*
|
||||
* @author Андрей
|
||||
*/
|
||||
public class EntityHeavyAirBomber extends EntityAirBomber {
|
||||
/// <summary>
|
||||
/// Дополнительный цвет
|
||||
/// </summary>
|
||||
private Color DopColor;
|
||||
/// <summary>
|
||||
/// Признак наличия бомб
|
||||
/// </summary>
|
||||
private boolean bombs;
|
||||
/// <summary>
|
||||
/// Признак наличия топливных баков
|
||||
/// </summary>
|
||||
private boolean fuelTank;
|
||||
/// <summary>
|
||||
/// Признак наличия полосы на хвосте
|
||||
/// </summary>
|
||||
private boolean tailLine;
|
||||
|
||||
public Color getDopColor() {
|
||||
return DopColor;
|
||||
}
|
||||
|
||||
public boolean getBombs(){
|
||||
return bombs;
|
||||
}
|
||||
|
||||
public boolean getFuelTank(){
|
||||
return fuelTank;
|
||||
}
|
||||
|
||||
public boolean getTailLine(){
|
||||
return tailLine;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес бомбардировщика</param>
|
||||
/// <param name="bodyColor">Цвет корпуса</param>
|
||||
/// <param name="dopColor">Дополнительный цвет</param>
|
||||
/// <param name="bombs">Признак наличия обвеса</param>
|
||||
/// <param name="fuelTank">Признак наличия антикрыла</param>
|
||||
/// <param name="tailLine">Признак наличия гоночной полосы</param>
|
||||
public EntityHeavyAirBomber(int speed, float weight, Color bodyColor, Color dopColor, boolean bombs, boolean fuelTank, boolean tailLine)
|
||||
{
|
||||
super(speed, weight, bodyColor);
|
||||
DopColor = dopColor;
|
||||
this.bombs = bombs;
|
||||
this.fuelTank = fuelTank;
|
||||
this.tailLine = tailLine;
|
||||
}
|
||||
}
|
40
AirBomber/src/AirBomberPackage/IDrawingObject.java
Normal file
40
AirBomber/src/AirBomberPackage/IDrawingObject.java
Normal file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Interface.java to edit this template
|
||||
*/
|
||||
package AirBomberPackage;
|
||||
import java.awt.*;
|
||||
/**
|
||||
*
|
||||
* @author Андрей
|
||||
*/
|
||||
public interface IDrawingObject {
|
||||
/// <summary>
|
||||
/// Шаг перемещения объекта
|
||||
/// </summary>
|
||||
public float getStep();
|
||||
/// <summary>
|
||||
/// Установка позиции объекта
|
||||
/// </summary>
|
||||
/// <param name="x">Координата X</param>
|
||||
/// <param name="y">Координата Y</param>
|
||||
/// <param name="width">Ширина полотна</param>
|
||||
/// <param name="height">Высота полотна</param>
|
||||
void SetObject(int x, int y, int width, int height);
|
||||
/// <summary>
|
||||
/// Изменение направления пермещения объекта
|
||||
/// </summary>
|
||||
/// <param name="direction">Направление</param>
|
||||
/// <returns></returns>
|
||||
void MoveObject(Direction direction);
|
||||
/// <summary>
|
||||
/// Отрисовка объекта
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
void DrawingObject(Graphics2D g);
|
||||
/// <summary>
|
||||
/// Получение текущей позиции объекта
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
float[] GetCurrentPosition();
|
||||
}
|
18
AirBomber/src/AirBomberPackage/IDrawingObjectDop.java
Normal file
18
AirBomber/src/AirBomberPackage/IDrawingObjectDop.java
Normal file
@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Interface.java to edit this template
|
||||
*/
|
||||
package AirBomberPackage;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Андрей
|
||||
*/
|
||||
public interface IDrawingObjectDop {
|
||||
public int getNumberOfEngines();
|
||||
void setNumberOfEngines(int numberOfEngines);
|
||||
void drawEngine(Graphics2D g, int startPosX, int startPosY, int yOffset, Color bodyColor);
|
||||
void drawEngines(Graphics2D g, int startPosX, int startPosY, Color bodyColor);
|
||||
}
|
@ -1,8 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
|
||||
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JDialogFormInfo">
|
||||
<Properties>
|
||||
<Property name="defaultCloseOperation" type="int" value="3"/>
|
||||
<Property name="defaultCloseOperation" type="int" value="2"/>
|
||||
<Property name="title" type="java.lang.String" value="Бомбардировщик"/>
|
||||
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
|
||||
<Font name="Arial" size="10" style="0"/>
|
||||
</Property>
|
||||
<Property name="size" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[700, 400]"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<SyntheticProperties>
|
||||
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
|
||||
@ -23,13 +30,250 @@
|
||||
<Layout>
|
||||
<DimensionLayout dim="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<EmptySpace min="0" pref="400" max="32767" attributes="0"/>
|
||||
<Component id="statusLabel" alignment="0" max="32767" attributes="0"/>
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" attributes="0">
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="jLabelEngines" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="jComboBoxEngines" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="jLabelEngines1" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="jComboBoxEnginesType" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<Component id="createAirBomberButton" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace type="separate" max="-2" attributes="0"/>
|
||||
<Component id="ModifyButton" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace type="separate" max="-2" attributes="0"/>
|
||||
<Component id="buttonSelect" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
<EmptySpace pref="157" max="32767" attributes="0"/>
|
||||
<Group type="103" groupAlignment="1" attributes="0">
|
||||
<Component id="upButton" alignment="1" min="-2" pref="30" max="-2" attributes="0"/>
|
||||
<Group type="102" alignment="1" attributes="0">
|
||||
<Component id="leftButton" min="-2" pref="30" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="downButton" min="-2" pref="30" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="rightButton" min="-2" pref="30" max="-2" attributes="0"/>
|
||||
<EmptySpace min="-2" pref="17" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<Group type="102" alignment="1" attributes="0">
|
||||
<Component id="airBomberCanvas" max="32767" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
<DimensionLayout dim="1">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<EmptySpace min="0" pref="300" max="32767" attributes="0"/>
|
||||
<Group type="102" alignment="1" attributes="0">
|
||||
<Component id="airBomberCanvas" pref="298" max="32767" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="1" attributes="0">
|
||||
<Group type="103" groupAlignment="3" attributes="0">
|
||||
<Component id="jLabelEngines" alignment="3" min="-2" pref="31" max="-2" attributes="0"/>
|
||||
<Component id="jComboBoxEngines" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="jLabelEngines1" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="jComboBoxEnginesType" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" max="-2" attributes="0">
|
||||
<Component id="createAirBomberButton" max="32767" attributes="0"/>
|
||||
<Component id="buttonSelect" alignment="0" pref="31" max="32767" attributes="0"/>
|
||||
<Component id="ModifyButton" alignment="0" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
<Group type="102" alignment="1" attributes="0">
|
||||
<Component id="upButton" min="-2" pref="31" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="3" attributes="0">
|
||||
<Component id="leftButton" alignment="3" min="-2" pref="31" max="-2" attributes="0"/>
|
||||
<Component id="downButton" alignment="3" min="-2" pref="31" max="-2" attributes="0"/>
|
||||
<Component id="rightButton" alignment="3" min="-2" pref="31" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="statusLabel" min="-2" pref="22" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
</Layout>
|
||||
<SubComponents>
|
||||
<Component class="javax.swing.JButton" name="createAirBomberButton">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Создать"/>
|
||||
<Property name="name" type="java.lang.String" value="createAirBomberButton" noResource="true"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="createAirBomberButtonActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="leftButton">
|
||||
<Properties>
|
||||
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
|
||||
<Image iconType="3" name="/AirBomberPackage/arrowLeft.png"/>
|
||||
</Property>
|
||||
<Property name="margin" type="java.awt.Insets" editor="org.netbeans.beaninfo.editors.InsetsEditor">
|
||||
<Insets value="[0, 0, 0, 0]"/>
|
||||
</Property>
|
||||
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[30, 30]"/>
|
||||
</Property>
|
||||
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[30, 30]"/>
|
||||
</Property>
|
||||
<Property name="name" type="java.lang.String" value="buttonLeft" noResource="true"/>
|
||||
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[30, 30]"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="moveButtonActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="downButton">
|
||||
<Properties>
|
||||
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
|
||||
<Image iconType="3" name="/AirBomberPackage/arrowDown.png"/>
|
||||
</Property>
|
||||
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[30, 30]"/>
|
||||
</Property>
|
||||
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[30, 30]"/>
|
||||
</Property>
|
||||
<Property name="name" type="java.lang.String" value="buttonDown" noResource="true"/>
|
||||
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[30, 30]"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="moveButtonActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="rightButton">
|
||||
<Properties>
|
||||
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
|
||||
<Image iconType="3" name="/AirBomberPackage/arrowRight.png"/>
|
||||
</Property>
|
||||
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[30, 30]"/>
|
||||
</Property>
|
||||
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[30, 30]"/>
|
||||
</Property>
|
||||
<Property name="name" type="java.lang.String" value="buttonRight" noResource="true"/>
|
||||
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[30, 30]"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="moveButtonActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="upButton">
|
||||
<Properties>
|
||||
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
|
||||
<Image iconType="3" name="/AirBomberPackage/arrowUp.png"/>
|
||||
</Property>
|
||||
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[30, 30]"/>
|
||||
</Property>
|
||||
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[30, 30]"/>
|
||||
</Property>
|
||||
<Property name="name" type="java.lang.String" value="buttonUp" noResource="true"/>
|
||||
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[30, 30]"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="moveButtonActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JLabel" name="statusLabel">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Скорость: Вес: Цвет: Двигатели:"/>
|
||||
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[0, 0]"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Container class="AirBomberPackage.CanvasMy" name="airBomberCanvas">
|
||||
<Events>
|
||||
<EventHandler event="componentResized" listener="java.awt.event.ComponentListener" parameters="java.awt.event.ComponentEvent" handler="airBomberCanvasComponentResized"/>
|
||||
</Events>
|
||||
|
||||
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout">
|
||||
<Property name="useNullLayout" type="boolean" value="true"/>
|
||||
</Layout>
|
||||
</Container>
|
||||
<Component class="javax.swing.JLabel" name="jLabelEngines">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Количество двигателей: "/>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component class="javax.swing.JComboBox" name="jComboBoxEngines">
|
||||
<Properties>
|
||||
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
|
||||
<StringArray count="3">
|
||||
<StringItem index="0" value="Два"/>
|
||||
<StringItem index="1" value="Четыре"/>
|
||||
<StringItem index="2" value="Шесть"/>
|
||||
</StringArray>
|
||||
</Property>
|
||||
</Properties>
|
||||
<AuxValues>
|
||||
<AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="<String>"/>
|
||||
</AuxValues>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="ModifyButton">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Модификация"/>
|
||||
<Property name="toolTipText" type="java.lang.String" value=""/>
|
||||
<Property name="name" type="java.lang.String" value="modifyButton" noResource="true"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="ModifyButtonActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JLabel" name="jLabelEngines1">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Тип двигателей: "/>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component class="javax.swing.JComboBox" name="jComboBoxEnginesType">
|
||||
<Properties>
|
||||
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
|
||||
<StringArray count="3">
|
||||
<StringItem index="0" value="Квадратный"/>
|
||||
<StringItem index="1" value="Треугольный"/>
|
||||
<StringItem index="2" value="Круглый"/>
|
||||
</StringArray>
|
||||
</Property>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="itemStateChanged" listener="java.awt.event.ItemListener" parameters="java.awt.event.ItemEvent" handler="jComboBoxEnginesTypeItemStateChanged"/>
|
||||
</Events>
|
||||
<AuxValues>
|
||||
<AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="<String>"/>
|
||||
</AuxValues>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="buttonSelect">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Выбрать"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="buttonSelectActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
</SubComponents>
|
||||
</Form>
|
||||
|
@ -3,20 +3,36 @@
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/JFrame.java to edit this template
|
||||
*/
|
||||
package AirBomberPackage;
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Андрей
|
||||
*/
|
||||
public class JFrameAirBomber extends javax.swing.JFrame {
|
||||
public class JFrameAirBomber extends javax.swing.JDialog {
|
||||
|
||||
/**
|
||||
* Creates new form JFrameAirBomber
|
||||
*/
|
||||
public JFrameAirBomber() {
|
||||
public JFrameAirBomber(JFrame parent) {
|
||||
super(parent, "Бомбардировщик", true);
|
||||
initComponents();
|
||||
}
|
||||
|
||||
public JFrameAirBomber(JFrame parent, DrawingObjectAirBomber airBomber) {
|
||||
super(parent, "Бомбардировщик", true);
|
||||
initComponents();
|
||||
_airBomber = airBomber.getAirBomber();
|
||||
SetData();
|
||||
Draw();
|
||||
}
|
||||
|
||||
private DrawingAirBomber _airBomber;
|
||||
private EnginesType enginesType = EnginesType.RECTANGLE;
|
||||
private DrawingAirBomber _airBomberResult;
|
||||
|
||||
/**
|
||||
* This method is called from within the constructor to initialize the form.
|
||||
* WARNING: Do NOT modify this code. The content of this method is always
|
||||
@ -26,22 +42,268 @@ public class JFrameAirBomber extends javax.swing.JFrame {
|
||||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
||||
private void initComponents() {
|
||||
|
||||
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
|
||||
createAirBomberButton = new javax.swing.JButton();
|
||||
leftButton = new javax.swing.JButton();
|
||||
downButton = new javax.swing.JButton();
|
||||
rightButton = new javax.swing.JButton();
|
||||
upButton = new javax.swing.JButton();
|
||||
statusLabel = new javax.swing.JLabel();
|
||||
airBomberCanvas = new AirBomberPackage.CanvasMy();
|
||||
jLabelEngines = new javax.swing.JLabel();
|
||||
jComboBoxEngines = new javax.swing.JComboBox<>();
|
||||
ModifyButton = new javax.swing.JButton();
|
||||
jLabelEngines1 = new javax.swing.JLabel();
|
||||
jComboBoxEnginesType = new javax.swing.JComboBox<>();
|
||||
buttonSelect = new javax.swing.JButton();
|
||||
|
||||
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
|
||||
setTitle("Бомбардировщик");
|
||||
setFont(new java.awt.Font("Arial", 0, 10)); // NOI18N
|
||||
setSize(new java.awt.Dimension(700, 400));
|
||||
|
||||
createAirBomberButton.setText("Создать");
|
||||
createAirBomberButton.setName("createAirBomberButton"); // NOI18N
|
||||
createAirBomberButton.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
createAirBomberButtonActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
leftButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/AirBomberPackage/arrowLeft.png"))); // NOI18N
|
||||
leftButton.setMargin(new java.awt.Insets(0, 0, 0, 0));
|
||||
leftButton.setMaximumSize(new java.awt.Dimension(30, 30));
|
||||
leftButton.setMinimumSize(new java.awt.Dimension(30, 30));
|
||||
leftButton.setName("buttonLeft"); // NOI18N
|
||||
leftButton.setPreferredSize(new java.awt.Dimension(30, 30));
|
||||
leftButton.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
moveButtonActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
downButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/AirBomberPackage/arrowDown.png"))); // NOI18N
|
||||
downButton.setMaximumSize(new java.awt.Dimension(30, 30));
|
||||
downButton.setMinimumSize(new java.awt.Dimension(30, 30));
|
||||
downButton.setName("buttonDown"); // NOI18N
|
||||
downButton.setPreferredSize(new java.awt.Dimension(30, 30));
|
||||
downButton.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
moveButtonActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
rightButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/AirBomberPackage/arrowRight.png"))); // NOI18N
|
||||
rightButton.setMaximumSize(new java.awt.Dimension(30, 30));
|
||||
rightButton.setMinimumSize(new java.awt.Dimension(30, 30));
|
||||
rightButton.setName("buttonRight"); // NOI18N
|
||||
rightButton.setPreferredSize(new java.awt.Dimension(30, 30));
|
||||
rightButton.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
moveButtonActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
upButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/AirBomberPackage/arrowUp.png"))); // NOI18N
|
||||
upButton.setMaximumSize(new java.awt.Dimension(30, 30));
|
||||
upButton.setMinimumSize(new java.awt.Dimension(30, 30));
|
||||
upButton.setName("buttonUp"); // NOI18N
|
||||
upButton.setPreferredSize(new java.awt.Dimension(30, 30));
|
||||
upButton.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
moveButtonActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
statusLabel.setText("Скорость: Вес: Цвет: Двигатели:");
|
||||
statusLabel.setMinimumSize(new java.awt.Dimension(0, 0));
|
||||
|
||||
airBomberCanvas.addComponentListener(new java.awt.event.ComponentAdapter() {
|
||||
public void componentResized(java.awt.event.ComponentEvent evt) {
|
||||
airBomberCanvasComponentResized(evt);
|
||||
}
|
||||
});
|
||||
|
||||
jLabelEngines.setText("Количество двигателей: ");
|
||||
|
||||
jComboBoxEngines.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Два", "Четыре", "Шесть" }));
|
||||
|
||||
ModifyButton.setText("Модификация");
|
||||
ModifyButton.setToolTipText("");
|
||||
ModifyButton.setName("modifyButton"); // NOI18N
|
||||
ModifyButton.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
ModifyButtonActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
jLabelEngines1.setText("Тип двигателей: ");
|
||||
|
||||
jComboBoxEnginesType.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Квадратный", "Треугольный", "Круглый" }));
|
||||
jComboBoxEnginesType.addItemListener(new java.awt.event.ItemListener() {
|
||||
public void itemStateChanged(java.awt.event.ItemEvent evt) {
|
||||
jComboBoxEnginesTypeItemStateChanged(evt);
|
||||
}
|
||||
});
|
||||
|
||||
buttonSelect.setText("Выбрать");
|
||||
buttonSelect.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
buttonSelectActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
|
||||
getContentPane().setLayout(layout);
|
||||
layout.setHorizontalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGap(0, 400, Short.MAX_VALUE)
|
||||
.addComponent(statusLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.addComponent(jLabelEngines)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(jComboBoxEngines, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(jLabelEngines1)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(jComboBoxEnginesType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addComponent(createAirBomberButton)
|
||||
.addGap(18, 18, 18)
|
||||
.addComponent(ModifyButton)
|
||||
.addGap(18, 18, 18)
|
||||
.addComponent(buttonSelect)))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 157, Short.MAX_VALUE)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
|
||||
.addComponent(upButton, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addComponent(leftButton, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(downButton, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(rightButton, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addGap(17, 17, 17))
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
||||
.addComponent(airBomberCanvas, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addContainerGap())
|
||||
);
|
||||
layout.setVerticalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGap(0, 300, Short.MAX_VALUE)
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
||||
.addComponent(airBomberCanvas, javax.swing.GroupLayout.DEFAULT_SIZE, 298, Short.MAX_VALUE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(jLabelEngines, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(jComboBoxEngines, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(jLabelEngines1)
|
||||
.addComponent(jComboBoxEnginesType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
|
||||
.addComponent(createAirBomberButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(buttonSelect, javax.swing.GroupLayout.DEFAULT_SIZE, 31, Short.MAX_VALUE)
|
||||
.addComponent(ModifyButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
||||
.addComponent(upButton, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(leftButton, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(downButton, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(rightButton, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE))))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(statusLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
);
|
||||
|
||||
pack();
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
|
||||
private void createAirBomberButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_createAirBomberButtonActionPerformed
|
||||
Random rnd = new Random();
|
||||
Color chosenColor = JColorChooser.showDialog(this, "Вибирете цвет", Color.BLACK);
|
||||
_airBomber = new DrawingAirBomber(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000), chosenColor, (jComboBoxEngines.getSelectedIndex() + 1) * 2, enginesType);
|
||||
SetData();
|
||||
Draw();
|
||||
}//GEN-LAST:event_createAirBomberButtonActionPerformed
|
||||
|
||||
private void moveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_moveButtonActionPerformed
|
||||
if (_airBomber == null) return;
|
||||
String name = ((JButton) evt.getSource()).getName();
|
||||
switch (name)
|
||||
{
|
||||
case "buttonUp":
|
||||
_airBomber.MoveTransport(Direction.UP);
|
||||
break;
|
||||
case "buttonDown":
|
||||
_airBomber.MoveTransport(Direction.DOWN);
|
||||
break;
|
||||
case "buttonLeft":
|
||||
_airBomber.MoveTransport(Direction.LEFT);
|
||||
break;
|
||||
case "buttonRight":
|
||||
_airBomber.MoveTransport(Direction.RIGHT);
|
||||
break;
|
||||
}
|
||||
Draw();
|
||||
}//GEN-LAST:event_moveButtonActionPerformed
|
||||
|
||||
private void airBomberCanvasComponentResized(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_airBomberCanvasComponentResized
|
||||
if (_airBomber == null) return;
|
||||
_airBomber.ChangeBorders(airBomberCanvas.getWidth(), airBomberCanvas.getHeight());
|
||||
}//GEN-LAST:event_airBomberCanvasComponentResized
|
||||
|
||||
private void ModifyButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ModifyButtonActionPerformed
|
||||
Random rnd = new Random();
|
||||
Color chosenColor = JColorChooser.showDialog(this, "Вибирете цвет", Color.BLACK);
|
||||
Color chosenDopColor = JColorChooser.showDialog(this, "Вибирете цвет", Color.BLACK);
|
||||
_airBomber = new DrawingHeavyAirBomber(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000),
|
||||
chosenColor,
|
||||
(jComboBoxEngines.getSelectedIndex() + 1) * 2,
|
||||
enginesType,
|
||||
chosenDopColor,
|
||||
rnd.nextBoolean(), rnd.nextBoolean(), rnd.nextBoolean());
|
||||
SetData();
|
||||
Draw();
|
||||
}//GEN-LAST:event_ModifyButtonActionPerformed
|
||||
|
||||
private void jComboBoxEnginesTypeItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jComboBoxEnginesTypeItemStateChanged
|
||||
switch (jComboBoxEnginesType.getSelectedIndex())
|
||||
{
|
||||
case 0:
|
||||
enginesType = EnginesType.RECTANGLE;
|
||||
break;
|
||||
case 1:
|
||||
enginesType = EnginesType.TRIANGLE;
|
||||
break;
|
||||
case 2:
|
||||
enginesType = EnginesType.OVAL;
|
||||
break;
|
||||
}
|
||||
}//GEN-LAST:event_jComboBoxEnginesTypeItemStateChanged
|
||||
|
||||
private void buttonSelectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonSelectActionPerformed
|
||||
_airBomberResult = _airBomber;
|
||||
dispose();
|
||||
}//GEN-LAST:event_buttonSelectActionPerformed
|
||||
|
||||
private void SetData()
|
||||
{
|
||||
Random rnd = new Random();
|
||||
_airBomber.SetPosition(rnd.nextInt(10, 100), rnd.nextInt(10, 100), airBomberCanvas.getWidth(), airBomberCanvas.getHeight());
|
||||
statusLabel.setText("Скорость: " + _airBomber.getAirBomber().getSpeed() + " Вес: " + (int) _airBomber.getAirBomber().getWeight() + " Цвет: " + _airBomber.getAirBomber().getBodyColor() + " Двигатели: " + _airBomber.drawingEngines.getNumberOfEngines());
|
||||
airBomberCanvas.setAirBomber(_airBomber);
|
||||
}
|
||||
|
||||
private void Draw(){
|
||||
airBomberCanvas.repaint();
|
||||
}
|
||||
|
||||
public DrawingAirBomber run(){
|
||||
setVisible(true);
|
||||
return _airBomberResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param args the command line arguments
|
||||
*/
|
||||
@ -72,11 +334,24 @@ public class JFrameAirBomber extends javax.swing.JFrame {
|
||||
/* Create and display the form */
|
||||
java.awt.EventQueue.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
new JFrameAirBomber().setVisible(true);
|
||||
new JFrameMapWithSetAirBombers().setVisible(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private javax.swing.JButton ModifyButton;
|
||||
private AirBomberPackage.CanvasMy airBomberCanvas;
|
||||
private javax.swing.JButton buttonSelect;
|
||||
private javax.swing.JButton createAirBomberButton;
|
||||
private javax.swing.JButton downButton;
|
||||
private javax.swing.JComboBox<String> jComboBoxEngines;
|
||||
private javax.swing.JComboBox<String> jComboBoxEnginesType;
|
||||
private javax.swing.JLabel jLabelEngines;
|
||||
private javax.swing.JLabel jLabelEngines1;
|
||||
private javax.swing.JButton leftButton;
|
||||
private javax.swing.JButton rightButton;
|
||||
private javax.swing.JLabel statusLabel;
|
||||
private javax.swing.JButton upButton;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
}
|
||||
|
171
AirBomber/src/AirBomberPackage/JFrameDopGenerics.form
Normal file
171
AirBomber/src/AirBomberPackage/JFrameDopGenerics.form
Normal file
@ -0,0 +1,171 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
|
||||
<Properties>
|
||||
<Property name="defaultCloseOperation" type="int" value="3"/>
|
||||
<Property name="title" type="java.lang.String" value="Бомбардировщик"/>
|
||||
</Properties>
|
||||
<SyntheticProperties>
|
||||
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
|
||||
<SyntheticProperty name="generateCenter" type="boolean" value="false"/>
|
||||
</SyntheticProperties>
|
||||
<AuxValues>
|
||||
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
|
||||
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
|
||||
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
|
||||
</AuxValues>
|
||||
|
||||
<Layout>
|
||||
<DimensionLayout dim="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="createAirBomberButton" pref="569" max="32767" attributes="0"/>
|
||||
<EmptySpace min="-2" pref="18" max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="1" attributes="0">
|
||||
<Component id="upButton" alignment="1" min="-2" pref="30" max="-2" attributes="0"/>
|
||||
<Group type="102" alignment="1" attributes="0">
|
||||
<Component id="leftButton" min="-2" pref="30" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="downButton" min="-2" pref="30" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="rightButton" min="-2" pref="30" max="-2" attributes="0"/>
|
||||
<EmptySpace min="-2" pref="17" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<Group type="102" attributes="0">
|
||||
<Component id="airBomberCanvas" max="32767" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
<DimensionLayout dim="1">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="1" attributes="0">
|
||||
<Component id="airBomberCanvas" pref="327" max="32767" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="createAirBomberButton" min="-2" pref="68" max="-2" attributes="0"/>
|
||||
<Group type="102" attributes="0">
|
||||
<Component id="upButton" min="-2" pref="31" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="3" attributes="0">
|
||||
<Component id="leftButton" alignment="3" min="-2" pref="31" max="-2" attributes="0"/>
|
||||
<Component id="downButton" alignment="3" min="-2" pref="31" max="-2" attributes="0"/>
|
||||
<Component id="rightButton" alignment="3" min="-2" pref="31" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
</Layout>
|
||||
<SubComponents>
|
||||
<Component class="javax.swing.JButton" name="createAirBomberButton">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Создать"/>
|
||||
<Property name="name" type="java.lang.String" value="createAirBomberButton" noResource="true"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="createAirBomberButtonActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="leftButton">
|
||||
<Properties>
|
||||
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
|
||||
<Image iconType="3" name="/AirBomberPackage/arrowLeft.png"/>
|
||||
</Property>
|
||||
<Property name="margin" type="java.awt.Insets" editor="org.netbeans.beaninfo.editors.InsetsEditor">
|
||||
<Insets value="[0, 0, 0, 0]"/>
|
||||
</Property>
|
||||
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[30, 30]"/>
|
||||
</Property>
|
||||
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[30, 30]"/>
|
||||
</Property>
|
||||
<Property name="name" type="java.lang.String" value="buttonLeft" noResource="true"/>
|
||||
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[30, 30]"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="moveButtonActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="downButton">
|
||||
<Properties>
|
||||
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
|
||||
<Image iconType="3" name="/AirBomberPackage/arrowDown.png"/>
|
||||
</Property>
|
||||
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[30, 30]"/>
|
||||
</Property>
|
||||
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[30, 30]"/>
|
||||
</Property>
|
||||
<Property name="name" type="java.lang.String" value="buttonDown" noResource="true"/>
|
||||
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[30, 30]"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="moveButtonActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="rightButton">
|
||||
<Properties>
|
||||
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
|
||||
<Image iconType="3" name="/AirBomberPackage/arrowRight.png"/>
|
||||
</Property>
|
||||
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[30, 30]"/>
|
||||
</Property>
|
||||
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[30, 30]"/>
|
||||
</Property>
|
||||
<Property name="name" type="java.lang.String" value="buttonRight" noResource="true"/>
|
||||
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[30, 30]"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="moveButtonActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="upButton">
|
||||
<Properties>
|
||||
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
|
||||
<Image iconType="3" name="/AirBomberPackage/arrowUp.png"/>
|
||||
</Property>
|
||||
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[30, 30]"/>
|
||||
</Property>
|
||||
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[30, 30]"/>
|
||||
</Property>
|
||||
<Property name="name" type="java.lang.String" value="buttonUp" noResource="true"/>
|
||||
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[30, 30]"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="moveButtonActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Container class="AirBomberPackage.CanvasMy" name="airBomberCanvas">
|
||||
|
||||
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout">
|
||||
<Property name="useNullLayout" type="boolean" value="true"/>
|
||||
</Layout>
|
||||
</Container>
|
||||
</SubComponents>
|
||||
</Form>
|
261
AirBomber/src/AirBomberPackage/JFrameDopGenerics.java
Normal file
261
AirBomber/src/AirBomberPackage/JFrameDopGenerics.java
Normal file
@ -0,0 +1,261 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/JFrame.java to edit this template
|
||||
*/
|
||||
package AirBomberPackage;
|
||||
|
||||
import java.util.Random;
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Андрей
|
||||
*/
|
||||
public class JFrameDopGenerics extends javax.swing.JFrame {
|
||||
|
||||
/**
|
||||
* Creates new form JFrameDopGenerics
|
||||
*/
|
||||
public JFrameDopGenerics() {
|
||||
initComponents();
|
||||
int numOfDecals = 2;
|
||||
airBomberGenerator = new SetAirBombersGenericDop<>(numOfDecals);
|
||||
Random rnd = new Random(System.currentTimeMillis());
|
||||
for (int i = 0; i < numOfDecals; i++){
|
||||
EntityAirBomber airBomber;
|
||||
int rndNum = rnd.nextInt(0, 100);
|
||||
if (rndNum % 2 == 0){
|
||||
//создаём обычный бомбардировщик
|
||||
airBomber = new EntityAirBomber(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000), new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256)));
|
||||
}
|
||||
else{
|
||||
//создаём тяжелый бомбардировщик
|
||||
airBomber = new EntityHeavyAirBomber(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000),
|
||||
new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256)),
|
||||
new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256)),
|
||||
rnd.nextBoolean(),
|
||||
rnd.nextBoolean(),
|
||||
rnd.nextBoolean());
|
||||
}
|
||||
airBomberGenerator.add(airBomber);
|
||||
}
|
||||
|
||||
for (int i = 0; i < numOfDecals; i++){
|
||||
int rndNum = rnd.nextInt(0, 500);
|
||||
IDrawingObjectDop engines = null;
|
||||
if (rndNum % 3 == 0){
|
||||
//создаем квадратные двигатели
|
||||
engines = new DrawingEngines();
|
||||
}
|
||||
else if (rndNum % 3 == 1){
|
||||
//создаём треугольные двигатели
|
||||
engines = new DrawingEnginesTriangle();
|
||||
}
|
||||
else {
|
||||
//создаём круглые двигатели
|
||||
engines = new DrawingEnginesOval();
|
||||
}
|
||||
engines.setNumberOfEngines(rnd.nextInt(1,4) * 2);
|
||||
airBomberGenerator.add(engines);
|
||||
}
|
||||
}
|
||||
|
||||
private DrawingAirBomber _airBomber;
|
||||
private SetAirBombersGenericDop<EntityAirBomber, IDrawingObjectDop> airBomberGenerator;
|
||||
|
||||
/**
|
||||
* This method is called from within the constructor to initialize the form.
|
||||
* WARNING: Do NOT modify this code. The content of this method is always
|
||||
* regenerated by the Form Editor.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
||||
private void initComponents() {
|
||||
|
||||
createAirBomberButton = new javax.swing.JButton();
|
||||
leftButton = new javax.swing.JButton();
|
||||
downButton = new javax.swing.JButton();
|
||||
rightButton = new javax.swing.JButton();
|
||||
upButton = new javax.swing.JButton();
|
||||
airBomberCanvas = new AirBomberPackage.CanvasMy();
|
||||
|
||||
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
|
||||
setTitle("Бомбардировщик");
|
||||
|
||||
createAirBomberButton.setText("Создать");
|
||||
createAirBomberButton.setName("createAirBomberButton"); // NOI18N
|
||||
createAirBomberButton.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
createAirBomberButtonActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
leftButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/AirBomberPackage/arrowLeft.png"))); // NOI18N
|
||||
leftButton.setMargin(new java.awt.Insets(0, 0, 0, 0));
|
||||
leftButton.setMaximumSize(new java.awt.Dimension(30, 30));
|
||||
leftButton.setMinimumSize(new java.awt.Dimension(30, 30));
|
||||
leftButton.setName("buttonLeft"); // NOI18N
|
||||
leftButton.setPreferredSize(new java.awt.Dimension(30, 30));
|
||||
leftButton.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
moveButtonActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
downButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/AirBomberPackage/arrowDown.png"))); // NOI18N
|
||||
downButton.setMaximumSize(new java.awt.Dimension(30, 30));
|
||||
downButton.setMinimumSize(new java.awt.Dimension(30, 30));
|
||||
downButton.setName("buttonDown"); // NOI18N
|
||||
downButton.setPreferredSize(new java.awt.Dimension(30, 30));
|
||||
downButton.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
moveButtonActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
rightButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/AirBomberPackage/arrowRight.png"))); // NOI18N
|
||||
rightButton.setMaximumSize(new java.awt.Dimension(30, 30));
|
||||
rightButton.setMinimumSize(new java.awt.Dimension(30, 30));
|
||||
rightButton.setName("buttonRight"); // NOI18N
|
||||
rightButton.setPreferredSize(new java.awt.Dimension(30, 30));
|
||||
rightButton.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
moveButtonActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
upButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/AirBomberPackage/arrowUp.png"))); // NOI18N
|
||||
upButton.setMaximumSize(new java.awt.Dimension(30, 30));
|
||||
upButton.setMinimumSize(new java.awt.Dimension(30, 30));
|
||||
upButton.setName("buttonUp"); // NOI18N
|
||||
upButton.setPreferredSize(new java.awt.Dimension(30, 30));
|
||||
upButton.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
moveButtonActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
|
||||
getContentPane().setLayout(layout);
|
||||
layout.setHorizontalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.addComponent(createAirBomberButton, javax.swing.GroupLayout.DEFAULT_SIZE, 569, Short.MAX_VALUE)
|
||||
.addGap(18, 18, 18)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
|
||||
.addComponent(upButton, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addComponent(leftButton, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(downButton, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(rightButton, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addGap(17, 17, 17))
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addComponent(airBomberCanvas, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addContainerGap())
|
||||
);
|
||||
layout.setVerticalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
||||
.addComponent(airBomberCanvas, javax.swing.GroupLayout.DEFAULT_SIZE, 327, Short.MAX_VALUE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(createAirBomberButton, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addComponent(upButton, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(leftButton, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(downButton, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(rightButton, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE))))
|
||||
.addContainerGap())
|
||||
);
|
||||
|
||||
pack();
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
|
||||
private void createAirBomberButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_createAirBomberButtonActionPerformed
|
||||
_airBomber = airBomberGenerator.buildAirBomber();
|
||||
SetData();
|
||||
Draw();
|
||||
}//GEN-LAST:event_createAirBomberButtonActionPerformed
|
||||
|
||||
private void moveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_moveButtonActionPerformed
|
||||
if (_airBomber == null) return;
|
||||
String name = ((JButton) evt.getSource()).getName();
|
||||
switch (name)
|
||||
{
|
||||
case "buttonUp":
|
||||
_airBomber.MoveTransport(Direction.UP);
|
||||
break;
|
||||
case "buttonDown":
|
||||
_airBomber.MoveTransport(Direction.DOWN);
|
||||
break;
|
||||
case "buttonLeft":
|
||||
_airBomber.MoveTransport(Direction.LEFT);
|
||||
break;
|
||||
case "buttonRight":
|
||||
_airBomber.MoveTransport(Direction.RIGHT);
|
||||
break;
|
||||
}
|
||||
Draw();
|
||||
}//GEN-LAST:event_moveButtonActionPerformed
|
||||
|
||||
private void SetData()
|
||||
{
|
||||
Random rnd = new Random();
|
||||
_airBomber.SetPosition(rnd.nextInt(10, 100), rnd.nextInt(10, 100), airBomberCanvas.getWidth(), airBomberCanvas.getHeight());
|
||||
airBomberCanvas.setAirBomber(_airBomber);
|
||||
}
|
||||
|
||||
private void Draw(){
|
||||
airBomberCanvas.repaint();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param args the command line arguments
|
||||
*/
|
||||
public static void main(String args[]) {
|
||||
/* Set the Nimbus look and feel */
|
||||
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
|
||||
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
|
||||
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
|
||||
*/
|
||||
try {
|
||||
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
|
||||
if ("Nimbus".equals(info.getName())) {
|
||||
javax.swing.UIManager.setLookAndFeel(info.getClassName());
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (ClassNotFoundException ex) {
|
||||
java.util.logging.Logger.getLogger(JFrameDopGenerics.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||
} catch (InstantiationException ex) {
|
||||
java.util.logging.Logger.getLogger(JFrameDopGenerics.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||
} catch (IllegalAccessException ex) {
|
||||
java.util.logging.Logger.getLogger(JFrameDopGenerics.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
|
||||
java.util.logging.Logger.getLogger(JFrameDopGenerics.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||
}
|
||||
//</editor-fold>
|
||||
|
||||
/* Create and display the form */
|
||||
java.awt.EventQueue.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
new JFrameDopGenerics().setVisible(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private AirBomberPackage.CanvasMy airBomberCanvas;
|
||||
private javax.swing.JButton createAirBomberButton;
|
||||
private javax.swing.JButton downButton;
|
||||
private javax.swing.JButton leftButton;
|
||||
private javax.swing.JButton rightButton;
|
||||
private javax.swing.JButton upButton;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
}
|
289
AirBomber/src/AirBomberPackage/JFrameMap.form
Normal file
289
AirBomber/src/AirBomberPackage/JFrameMap.form
Normal file
@ -0,0 +1,289 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
|
||||
<Properties>
|
||||
<Property name="defaultCloseOperation" type="int" value="3"/>
|
||||
<Property name="title" type="java.lang.String" value="Бомбардировщик"/>
|
||||
<Property name="alwaysOnTop" type="boolean" value="true"/>
|
||||
<Property name="name" type="java.lang.String" value="FrameMap" noResource="true"/>
|
||||
<Property name="size" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[700, 400]"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<SyntheticProperties>
|
||||
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
|
||||
<SyntheticProperty name="generateCenter" type="boolean" value="false"/>
|
||||
</SyntheticProperties>
|
||||
<AuxValues>
|
||||
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
|
||||
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
|
||||
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
|
||||
</AuxValues>
|
||||
|
||||
<Layout>
|
||||
<DimensionLayout dim="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="statusLabel" alignment="0" max="32767" attributes="0"/>
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="jLabelEngines" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="jComboBoxEngines" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="jLabelEngines1" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="jComboBoxEnginesType" min="-2" pref="107" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<Component id="createAirBomberButton" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace type="unrelated" max="-2" attributes="0"/>
|
||||
<Component id="ModifyButton" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace type="unrelated" max="-2" attributes="0"/>
|
||||
<Component id="jComboBoxMap" min="-2" pref="127" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
<EmptySpace pref="146" max="32767" attributes="0"/>
|
||||
<Group type="103" groupAlignment="1" attributes="0">
|
||||
<Component id="upButton" alignment="1" min="-2" pref="30" max="-2" attributes="0"/>
|
||||
<Group type="102" alignment="1" attributes="0">
|
||||
<Component id="leftButton" min="-2" pref="30" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="downButton" min="-2" pref="30" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="rightButton" min="-2" pref="30" max="-2" attributes="0"/>
|
||||
<EmptySpace min="-2" pref="17" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<Group type="102" alignment="1" attributes="0">
|
||||
<Component id="airBomberCanvas" pref="694" max="32767" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
<DimensionLayout dim="1">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="1" attributes="0">
|
||||
<Component id="airBomberCanvas" pref="298" max="32767" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="1" attributes="0">
|
||||
<Group type="103" groupAlignment="3" attributes="0">
|
||||
<Component id="jLabelEngines" alignment="3" min="-2" pref="31" max="-2" attributes="0"/>
|
||||
<Component id="jComboBoxEngines" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="jLabelEngines1" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="jComboBoxEnginesType" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" max="-2" attributes="0">
|
||||
<Component id="createAirBomberButton" pref="31" max="32767" attributes="0"/>
|
||||
<Component id="ModifyButton" alignment="0" max="32767" attributes="0"/>
|
||||
<Component id="jComboBoxMap" alignment="0" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
<Group type="102" alignment="1" attributes="0">
|
||||
<Component id="upButton" min="-2" pref="31" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="3" attributes="0">
|
||||
<Component id="leftButton" alignment="3" min="-2" pref="31" max="-2" attributes="0"/>
|
||||
<Component id="downButton" alignment="3" min="-2" pref="31" max="-2" attributes="0"/>
|
||||
<Component id="rightButton" alignment="3" min="-2" pref="31" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="statusLabel" min="-2" pref="22" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
</Layout>
|
||||
<SubComponents>
|
||||
<Container class="AirBomberPackage.CanvasMy" name="airBomberCanvas">
|
||||
<Properties>
|
||||
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[700, 300]"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
|
||||
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout">
|
||||
<Property name="useNullLayout" type="boolean" value="true"/>
|
||||
</Layout>
|
||||
</Container>
|
||||
<Component class="javax.swing.JLabel" name="jLabelEngines">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Количество двигателей: "/>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component class="javax.swing.JComboBox" name="jComboBoxEngines">
|
||||
<Properties>
|
||||
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
|
||||
<StringArray count="3">
|
||||
<StringItem index="0" value="Два"/>
|
||||
<StringItem index="1" value="Четыре"/>
|
||||
<StringItem index="2" value="Шесть"/>
|
||||
</StringArray>
|
||||
</Property>
|
||||
</Properties>
|
||||
<AuxValues>
|
||||
<AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="<String>"/>
|
||||
</AuxValues>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="createAirBomberButton">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Создать"/>
|
||||
<Property name="name" type="java.lang.String" value="createAirBomberButton" noResource="true"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="createAirBomberButtonActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JLabel" name="statusLabel">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Скорость: Вес: Цвет: Двигатели:"/>
|
||||
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[0, 0]"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="leftButton">
|
||||
<Properties>
|
||||
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
|
||||
<Image iconType="3" name="/AirBomberPackage/arrowLeft.png"/>
|
||||
</Property>
|
||||
<Property name="margin" type="java.awt.Insets" editor="org.netbeans.beaninfo.editors.InsetsEditor">
|
||||
<Insets value="[0, 0, 0, 0]"/>
|
||||
</Property>
|
||||
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[30, 30]"/>
|
||||
</Property>
|
||||
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[30, 30]"/>
|
||||
</Property>
|
||||
<Property name="name" type="java.lang.String" value="buttonLeft" noResource="true"/>
|
||||
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[30, 30]"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="moveButtonActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="downButton">
|
||||
<Properties>
|
||||
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
|
||||
<Image iconType="3" name="/AirBomberPackage/arrowDown.png"/>
|
||||
</Property>
|
||||
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[30, 30]"/>
|
||||
</Property>
|
||||
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[30, 30]"/>
|
||||
</Property>
|
||||
<Property name="name" type="java.lang.String" value="buttonDown" noResource="true"/>
|
||||
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[30, 30]"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="moveButtonActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="rightButton">
|
||||
<Properties>
|
||||
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
|
||||
<Image iconType="3" name="/AirBomberPackage/arrowRight.png"/>
|
||||
</Property>
|
||||
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[30, 30]"/>
|
||||
</Property>
|
||||
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[30, 30]"/>
|
||||
</Property>
|
||||
<Property name="name" type="java.lang.String" value="buttonRight" noResource="true"/>
|
||||
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[30, 30]"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="moveButtonActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="upButton">
|
||||
<Properties>
|
||||
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
|
||||
<Image iconType="3" name="/AirBomberPackage/arrowUp.png"/>
|
||||
</Property>
|
||||
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[30, 30]"/>
|
||||
</Property>
|
||||
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[30, 30]"/>
|
||||
</Property>
|
||||
<Property name="name" type="java.lang.String" value="buttonUp" noResource="true"/>
|
||||
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[30, 30]"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="moveButtonActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="ModifyButton">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Модификация"/>
|
||||
<Property name="toolTipText" type="java.lang.String" value=""/>
|
||||
<Property name="name" type="java.lang.String" value="modifyButton" noResource="true"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="ModifyButtonActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JComboBox" name="jComboBoxMap">
|
||||
<Properties>
|
||||
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
|
||||
<StringArray count="3">
|
||||
<StringItem index="0" value="Простая карта"/>
|
||||
<StringItem index="1" value="Линейная карта"/>
|
||||
<StringItem index="2" value="Городская карта"/>
|
||||
</StringArray>
|
||||
</Property>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="itemStateChanged" listener="java.awt.event.ItemListener" parameters="java.awt.event.ItemEvent" handler="jComboBoxMapItemStateChanged"/>
|
||||
</Events>
|
||||
<AuxValues>
|
||||
<AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="<String>"/>
|
||||
</AuxValues>
|
||||
</Component>
|
||||
<Component class="javax.swing.JComboBox" name="jComboBoxEnginesType">
|
||||
<Properties>
|
||||
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
|
||||
<StringArray count="3">
|
||||
<StringItem index="0" value="Квадратный"/>
|
||||
<StringItem index="1" value="Треугольный"/>
|
||||
<StringItem index="2" value="Круглый"/>
|
||||
</StringArray>
|
||||
</Property>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="itemStateChanged" listener="java.awt.event.ItemListener" parameters="java.awt.event.ItemEvent" handler="jComboBoxEnginesTypeItemStateChanged"/>
|
||||
</Events>
|
||||
<AuxValues>
|
||||
<AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="<String>"/>
|
||||
</AuxValues>
|
||||
</Component>
|
||||
<Component class="javax.swing.JLabel" name="jLabelEngines1">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Тип двигателей: "/>
|
||||
</Properties>
|
||||
</Component>
|
||||
</SubComponents>
|
||||
</Form>
|
337
AirBomber/src/AirBomberPackage/JFrameMap.java
Normal file
337
AirBomber/src/AirBomberPackage/JFrameMap.java
Normal file
@ -0,0 +1,337 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/JFrame.java to edit this template
|
||||
*/
|
||||
package AirBomberPackage;
|
||||
import java.util.*;
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
/**
|
||||
*
|
||||
* @author Андрей
|
||||
*/
|
||||
public class JFrameMap extends javax.swing.JFrame {
|
||||
|
||||
/**
|
||||
* Creates new form JFrameMap
|
||||
*/
|
||||
public JFrameMap() {
|
||||
initComponents();
|
||||
}
|
||||
|
||||
private DrawingAirBomber _airBomber;
|
||||
private AbstractMap _abstractMap = new SimpleMap();
|
||||
private EnginesType enginesType = EnginesType.RECTANGLE;
|
||||
|
||||
/**
|
||||
* This method is called from within the constructor to initialize the form.
|
||||
* WARNING: Do NOT modify this code. The content of this method is always
|
||||
* regenerated by the Form Editor.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
||||
private void initComponents() {
|
||||
|
||||
airBomberCanvas = new AirBomberPackage.CanvasMy();
|
||||
jLabelEngines = new javax.swing.JLabel();
|
||||
jComboBoxEngines = new javax.swing.JComboBox<>();
|
||||
createAirBomberButton = new javax.swing.JButton();
|
||||
statusLabel = new javax.swing.JLabel();
|
||||
leftButton = new javax.swing.JButton();
|
||||
downButton = new javax.swing.JButton();
|
||||
rightButton = new javax.swing.JButton();
|
||||
upButton = new javax.swing.JButton();
|
||||
ModifyButton = new javax.swing.JButton();
|
||||
jComboBoxMap = new javax.swing.JComboBox<>();
|
||||
jComboBoxEnginesType = new javax.swing.JComboBox<>();
|
||||
jLabelEngines1 = new javax.swing.JLabel();
|
||||
|
||||
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
|
||||
setTitle("Бомбардировщик");
|
||||
setAlwaysOnTop(true);
|
||||
setName("FrameMap"); // NOI18N
|
||||
setSize(new java.awt.Dimension(700, 400));
|
||||
|
||||
airBomberCanvas.setPreferredSize(new java.awt.Dimension(700, 300));
|
||||
|
||||
jLabelEngines.setText("Количество двигателей: ");
|
||||
|
||||
jComboBoxEngines.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Два", "Четыре", "Шесть" }));
|
||||
|
||||
createAirBomberButton.setText("Создать");
|
||||
createAirBomberButton.setName("createAirBomberButton"); // NOI18N
|
||||
createAirBomberButton.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
createAirBomberButtonActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
statusLabel.setText("Скорость: Вес: Цвет: Двигатели:");
|
||||
statusLabel.setMinimumSize(new java.awt.Dimension(0, 0));
|
||||
|
||||
leftButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/AirBomberPackage/arrowLeft.png"))); // NOI18N
|
||||
leftButton.setMargin(new java.awt.Insets(0, 0, 0, 0));
|
||||
leftButton.setMaximumSize(new java.awt.Dimension(30, 30));
|
||||
leftButton.setMinimumSize(new java.awt.Dimension(30, 30));
|
||||
leftButton.setName("buttonLeft"); // NOI18N
|
||||
leftButton.setPreferredSize(new java.awt.Dimension(30, 30));
|
||||
leftButton.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
moveButtonActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
downButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/AirBomberPackage/arrowDown.png"))); // NOI18N
|
||||
downButton.setMaximumSize(new java.awt.Dimension(30, 30));
|
||||
downButton.setMinimumSize(new java.awt.Dimension(30, 30));
|
||||
downButton.setName("buttonDown"); // NOI18N
|
||||
downButton.setPreferredSize(new java.awt.Dimension(30, 30));
|
||||
downButton.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
moveButtonActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
rightButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/AirBomberPackage/arrowRight.png"))); // NOI18N
|
||||
rightButton.setMaximumSize(new java.awt.Dimension(30, 30));
|
||||
rightButton.setMinimumSize(new java.awt.Dimension(30, 30));
|
||||
rightButton.setName("buttonRight"); // NOI18N
|
||||
rightButton.setPreferredSize(new java.awt.Dimension(30, 30));
|
||||
rightButton.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
moveButtonActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
upButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/AirBomberPackage/arrowUp.png"))); // NOI18N
|
||||
upButton.setMaximumSize(new java.awt.Dimension(30, 30));
|
||||
upButton.setMinimumSize(new java.awt.Dimension(30, 30));
|
||||
upButton.setName("buttonUp"); // NOI18N
|
||||
upButton.setPreferredSize(new java.awt.Dimension(30, 30));
|
||||
upButton.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
moveButtonActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
ModifyButton.setText("Модификация");
|
||||
ModifyButton.setToolTipText("");
|
||||
ModifyButton.setName("modifyButton"); // NOI18N
|
||||
ModifyButton.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
ModifyButtonActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
jComboBoxMap.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Простая карта", "Линейная карта", "Городская карта" }));
|
||||
jComboBoxMap.addItemListener(new java.awt.event.ItemListener() {
|
||||
public void itemStateChanged(java.awt.event.ItemEvent evt) {
|
||||
jComboBoxMapItemStateChanged(evt);
|
||||
}
|
||||
});
|
||||
|
||||
jComboBoxEnginesType.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Квадратный", "Треугольный", "Круглый" }));
|
||||
jComboBoxEnginesType.addItemListener(new java.awt.event.ItemListener() {
|
||||
public void itemStateChanged(java.awt.event.ItemEvent evt) {
|
||||
jComboBoxEnginesTypeItemStateChanged(evt);
|
||||
}
|
||||
});
|
||||
|
||||
jLabelEngines1.setText("Тип двигателей: ");
|
||||
|
||||
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
|
||||
getContentPane().setLayout(layout);
|
||||
layout.setHorizontalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(statusLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.addComponent(jLabelEngines)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(jComboBoxEngines, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(jLabelEngines1)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(jComboBoxEnginesType, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addComponent(createAirBomberButton)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
|
||||
.addComponent(ModifyButton)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
|
||||
.addComponent(jComboBoxMap, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE)))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 146, Short.MAX_VALUE)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
|
||||
.addComponent(upButton, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addComponent(leftButton, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(downButton, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(rightButton, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addGap(17, 17, 17))
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
||||
.addComponent(airBomberCanvas, javax.swing.GroupLayout.DEFAULT_SIZE, 694, Short.MAX_VALUE)
|
||||
.addContainerGap())
|
||||
);
|
||||
layout.setVerticalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
||||
.addComponent(airBomberCanvas, javax.swing.GroupLayout.DEFAULT_SIZE, 298, Short.MAX_VALUE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(jLabelEngines, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(jComboBoxEngines, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(jLabelEngines1)
|
||||
.addComponent(jComboBoxEnginesType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
|
||||
.addComponent(createAirBomberButton, javax.swing.GroupLayout.DEFAULT_SIZE, 31, Short.MAX_VALUE)
|
||||
.addComponent(ModifyButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(jComboBoxMap)))
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
||||
.addComponent(upButton, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(leftButton, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(downButton, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(rightButton, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE))))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(statusLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
);
|
||||
|
||||
pack();
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
|
||||
private void createAirBomberButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_createAirBomberButtonActionPerformed
|
||||
Random rnd = new Random();
|
||||
_airBomber = new DrawingAirBomber(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000), new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256)), (jComboBoxEngines.getSelectedIndex() + 1) * 2, enginesType);
|
||||
SetData(_airBomber);
|
||||
}//GEN-LAST:event_createAirBomberButtonActionPerformed
|
||||
|
||||
private void moveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_moveButtonActionPerformed
|
||||
if (_airBomber == null) return;
|
||||
String name = ((JButton) evt.getSource()).getName();
|
||||
Direction dir = Direction.NONE;
|
||||
switch (name)
|
||||
{
|
||||
case "buttonUp":
|
||||
dir = Direction.UP;
|
||||
break;
|
||||
case "buttonDown":
|
||||
dir = Direction.DOWN;
|
||||
break;
|
||||
case "buttonLeft":
|
||||
dir = Direction.LEFT;
|
||||
break;
|
||||
case "buttonRight":
|
||||
dir = Direction.RIGHT;
|
||||
break;
|
||||
}
|
||||
airBomberCanvas.getGraphics().drawImage(_abstractMap.MoveObject(dir), 0, 0, null);
|
||||
}//GEN-LAST:event_moveButtonActionPerformed
|
||||
|
||||
private void ModifyButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ModifyButtonActionPerformed
|
||||
Random rnd = new Random();
|
||||
_airBomber = new DrawingHeavyAirBomber(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000),
|
||||
new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256)),
|
||||
(jComboBoxEngines.getSelectedIndex() + 1) * 2,
|
||||
enginesType,
|
||||
new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256)),
|
||||
rnd.nextBoolean(), rnd.nextBoolean(), rnd.nextBoolean());
|
||||
SetData(_airBomber);
|
||||
}//GEN-LAST:event_ModifyButtonActionPerformed
|
||||
|
||||
private void jComboBoxMapItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jComboBoxMapItemStateChanged
|
||||
switch (jComboBoxMap.getSelectedIndex())
|
||||
{
|
||||
case 0:
|
||||
_abstractMap = new SimpleMap();
|
||||
break;
|
||||
case 1:
|
||||
_abstractMap = new LineMap();
|
||||
break;
|
||||
case 2:
|
||||
_abstractMap = new CityMap();
|
||||
break;
|
||||
}
|
||||
}//GEN-LAST:event_jComboBoxMapItemStateChanged
|
||||
|
||||
private void jComboBoxEnginesTypeItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jComboBoxEnginesTypeItemStateChanged
|
||||
switch (jComboBoxEnginesType.getSelectedIndex())
|
||||
{
|
||||
case 0:
|
||||
enginesType = EnginesType.RECTANGLE;
|
||||
break;
|
||||
case 1:
|
||||
enginesType = EnginesType.TRIANGLE;
|
||||
break;
|
||||
case 2:
|
||||
enginesType = EnginesType.OVAL;
|
||||
break;
|
||||
}
|
||||
}//GEN-LAST:event_jComboBoxEnginesTypeItemStateChanged
|
||||
|
||||
private void SetData(DrawingAirBomber airBomber)
|
||||
{
|
||||
Random rnd = new Random();
|
||||
_airBomber.SetPosition(rnd.nextInt(10, 100), rnd.nextInt(10, 100), airBomberCanvas.getWidth(), airBomberCanvas.getHeight());
|
||||
statusLabel.setText("Скорость: " + _airBomber.getAirBomber().getSpeed() + " Вес: " + (int) _airBomber.getAirBomber().getWeight() + " Цвет: " + _airBomber.getAirBomber().getBodyColor() + " Двигатели: " + _airBomber.drawingEngines.getNumberOfEngines());
|
||||
airBomberCanvas.setAirBomber(_airBomber);
|
||||
airBomberCanvas.getGraphics().drawImage(_abstractMap.CreateMap(airBomberCanvas.getWidth() + 6, airBomberCanvas.getHeight() + 3, new DrawingObjectAirBomber(airBomber)), 0,0,null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param args the command line arguments
|
||||
*/
|
||||
public static void main(String args[]) {
|
||||
/* Set the Nimbus look and feel */
|
||||
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
|
||||
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
|
||||
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
|
||||
*/
|
||||
try {
|
||||
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
|
||||
if ("Nimbus".equals(info.getName())) {
|
||||
javax.swing.UIManager.setLookAndFeel(info.getClassName());
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (ClassNotFoundException ex) {
|
||||
java.util.logging.Logger.getLogger(JFrameMap.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||
} catch (InstantiationException ex) {
|
||||
java.util.logging.Logger.getLogger(JFrameMap.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||
} catch (IllegalAccessException ex) {
|
||||
java.util.logging.Logger.getLogger(JFrameMap.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
|
||||
java.util.logging.Logger.getLogger(JFrameMap.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||
}
|
||||
//</editor-fold>
|
||||
|
||||
/* Create and display the form */
|
||||
java.awt.EventQueue.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
new JFrameMap().setVisible(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private javax.swing.JButton ModifyButton;
|
||||
private AirBomberPackage.CanvasMy airBomberCanvas;
|
||||
private javax.swing.JButton createAirBomberButton;
|
||||
private javax.swing.JButton downButton;
|
||||
private javax.swing.JComboBox<String> jComboBoxEngines;
|
||||
private javax.swing.JComboBox<String> jComboBoxEnginesType;
|
||||
private javax.swing.JComboBox<String> jComboBoxMap;
|
||||
private javax.swing.JLabel jLabelEngines;
|
||||
private javax.swing.JLabel jLabelEngines1;
|
||||
private javax.swing.JButton leftButton;
|
||||
private javax.swing.JButton rightButton;
|
||||
private javax.swing.JLabel statusLabel;
|
||||
private javax.swing.JButton upButton;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
}
|
315
AirBomber/src/AirBomberPackage/JFrameMapWithSetAirBombers.form
Normal file
315
AirBomber/src/AirBomberPackage/JFrameMapWithSetAirBombers.form
Normal file
@ -0,0 +1,315 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<Form version="1.5" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
|
||||
<Properties>
|
||||
<Property name="defaultCloseOperation" type="int" value="3"/>
|
||||
</Properties>
|
||||
<SyntheticProperties>
|
||||
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
|
||||
<SyntheticProperty name="generateCenter" type="boolean" value="false"/>
|
||||
</SyntheticProperties>
|
||||
<AuxValues>
|
||||
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
|
||||
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
|
||||
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
|
||||
</AuxValues>
|
||||
|
||||
<Layout>
|
||||
<DimensionLayout dim="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<Component id="airBomberCanvas" min="-2" pref="664" max="-2" attributes="0"/>
|
||||
<EmptySpace pref="59" max="32767" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="1" attributes="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="103" alignment="0" groupAlignment="1" attributes="0">
|
||||
<Component id="buttonDeleteMap" min="-2" pref="188" max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" max="-2" attributes="0">
|
||||
<Component id="buttonAddAirBomber" max="32767" attributes="0"/>
|
||||
<Component id="maskedTextBoxPosition" max="32767" attributes="0"/>
|
||||
<Component id="buttonRemoveAirBomber" max="32767" attributes="0"/>
|
||||
<Component id="buttonShowStorage" max="32767" attributes="0"/>
|
||||
<Component id="buttonShowOnMap" alignment="1" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
<Component id="jScrollPane1" alignment="1" min="-2" pref="188" max="-2" attributes="0"/>
|
||||
<Component id="buttonAddMap" alignment="1" min="-2" pref="188" max="-2" attributes="0"/>
|
||||
<Component id="comboBoxSelectorMap" alignment="1" min="-2" pref="188" max="-2" attributes="0"/>
|
||||
<Component id="textBoxNewMapName" alignment="1" min="-2" pref="188" max="-2" attributes="0"/>
|
||||
<Component id="buttonShowDeleted" alignment="1" min="-2" pref="188" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<Group type="103" alignment="0" groupAlignment="1" attributes="0">
|
||||
<Component id="jLabel2" min="-2" pref="75" max="-2" attributes="0"/>
|
||||
<Component id="jLabel1" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
<EmptySpace min="-2" pref="23" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<Group type="102" alignment="1" attributes="0">
|
||||
<Component id="leftButton" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="upButton" alignment="0" min="-2" max="-2" attributes="0"/>
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<Component id="downButton" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="rightButton" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
<EmptySpace min="-2" pref="62" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
<DimensionLayout dim="1">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="airBomberCanvas" alignment="0" max="32767" attributes="0"/>
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<EmptySpace min="-2" pref="15" max="-2" attributes="0"/>
|
||||
<Component id="jLabel1" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="jLabel2" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="textBoxNewMapName" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="comboBoxSelectorMap" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="buttonAddMap" min="-2" pref="35" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="jScrollPane1" min="-2" pref="78" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="buttonDeleteMap" min="-2" pref="34" max="-2" attributes="0"/>
|
||||
<EmptySpace pref="45" max="32767" attributes="0"/>
|
||||
<Component id="buttonShowDeleted" min="-2" pref="36" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="buttonAddAirBomber" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="maskedTextBoxPosition" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="buttonRemoveAirBomber" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="buttonShowStorage" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="buttonShowOnMap" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="upButton" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="1" attributes="0">
|
||||
<Component id="downButton" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="leftButton" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="rightButton" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
</Layout>
|
||||
<SubComponents>
|
||||
<Container class="AirBomberPackage.CanvasMy" name="airBomberCanvas">
|
||||
|
||||
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout">
|
||||
<Property name="useNullLayout" type="boolean" value="true"/>
|
||||
</Layout>
|
||||
</Container>
|
||||
<Component class="javax.swing.JComboBox" name="comboBoxSelectorMap">
|
||||
<Properties>
|
||||
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
|
||||
<StringArray count="0"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<AuxValues>
|
||||
<AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="<String>"/>
|
||||
</AuxValues>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="buttonAddAirBomber">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Добавить бомбардировщик"/>
|
||||
<Property name="toolTipText" type="java.lang.String" value=""/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="buttonAddAirBomberActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JFormattedTextField" name="maskedTextBoxPosition">
|
||||
<Properties>
|
||||
<Property name="formatterFactory" type="javax.swing.JFormattedTextField$AbstractFormatterFactory" editor="org.netbeans.modules.form.editors.AbstractFormatterFactoryEditor" preCode="try {" postCode="} catch (java.text.ParseException ex) {
ex.printStackTrace();
}">
|
||||
<Format format="##" subtype="-1" type="5"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="buttonRemoveAirBomber">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Удалить бомбардировщик"/>
|
||||
<Property name="toolTipText" type="java.lang.String" value=""/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="buttonRemoveAirBomberActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="buttonShowStorage">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Посмотреть хранилище"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="buttonShowStorageActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="buttonShowOnMap">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Посмотреть карту"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="buttonShowOnMapActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="leftButton">
|
||||
<Properties>
|
||||
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
|
||||
<Image iconType="3" name="/AirBomberPackage/arrowLeft.png"/>
|
||||
</Property>
|
||||
<Property name="margin" type="java.awt.Insets" editor="org.netbeans.beaninfo.editors.InsetsEditor">
|
||||
<Insets value="[0, 0, 0, 0]"/>
|
||||
</Property>
|
||||
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[30, 30]"/>
|
||||
</Property>
|
||||
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[30, 30]"/>
|
||||
</Property>
|
||||
<Property name="name" type="java.lang.String" value="buttonLeft" noResource="true"/>
|
||||
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[30, 30]"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="moveButtonActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="downButton">
|
||||
<Properties>
|
||||
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
|
||||
<Image iconType="3" name="/AirBomberPackage/arrowDown.png"/>
|
||||
</Property>
|
||||
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[30, 30]"/>
|
||||
</Property>
|
||||
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[30, 30]"/>
|
||||
</Property>
|
||||
<Property name="name" type="java.lang.String" value="buttonDown" noResource="true"/>
|
||||
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[30, 30]"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="moveButtonActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="rightButton">
|
||||
<Properties>
|
||||
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
|
||||
<Image iconType="3" name="/AirBomberPackage/arrowRight.png"/>
|
||||
</Property>
|
||||
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[30, 30]"/>
|
||||
</Property>
|
||||
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[30, 30]"/>
|
||||
</Property>
|
||||
<Property name="name" type="java.lang.String" value="buttonRight" noResource="true"/>
|
||||
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[30, 30]"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="moveButtonActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="upButton">
|
||||
<Properties>
|
||||
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
|
||||
<Image iconType="3" name="/AirBomberPackage/arrowUp.png"/>
|
||||
</Property>
|
||||
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[30, 30]"/>
|
||||
</Property>
|
||||
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[30, 30]"/>
|
||||
</Property>
|
||||
<Property name="name" type="java.lang.String" value="buttonUp" noResource="true"/>
|
||||
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[30, 30]"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="moveButtonActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JLabel" name="jLabel1">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Инструменты"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component class="javax.swing.JLabel" name="jLabel2">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Карты"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component class="javax.swing.JTextField" name="textBoxNewMapName">
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="buttonAddMap">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Добавить карту"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="buttonAddMapActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Container class="javax.swing.JScrollPane" name="jScrollPane1">
|
||||
<AuxValues>
|
||||
<AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
|
||||
</AuxValues>
|
||||
|
||||
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
|
||||
<SubComponents>
|
||||
<Component class="javax.swing.JList" name="listBoxMaps">
|
||||
<Properties>
|
||||
<Property name="model" type="javax.swing.ListModel" editor="org.netbeans.modules.form.editors2.ListModelEditor">
|
||||
<StringArray count="0"/>
|
||||
</Property>
|
||||
<Property name="selectionMode" type="int" value="0"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="valueChanged" listener="javax.swing.event.ListSelectionListener" parameters="javax.swing.event.ListSelectionEvent" handler="listBoxMapsValueChanged"/>
|
||||
</Events>
|
||||
<AuxValues>
|
||||
<AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="<String>"/>
|
||||
</AuxValues>
|
||||
</Component>
|
||||
</SubComponents>
|
||||
</Container>
|
||||
<Component class="javax.swing.JButton" name="buttonDeleteMap">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Удалить карту"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="buttonDeleteMapActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="buttonShowDeleted">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Показать удалённый"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="buttonShowDeletedActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
</SubComponents>
|
||||
</Form>
|
464
AirBomber/src/AirBomberPackage/JFrameMapWithSetAirBombers.java
Normal file
464
AirBomber/src/AirBomberPackage/JFrameMapWithSetAirBombers.java
Normal file
@ -0,0 +1,464 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/JFrame.java to edit this template
|
||||
*/
|
||||
package AirBomberPackage;
|
||||
import java.awt.*;
|
||||
import javax.swing.DefaultListModel;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import javax.swing.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Андрей
|
||||
*/
|
||||
public class JFrameMapWithSetAirBombers extends javax.swing.JFrame {
|
||||
|
||||
/**
|
||||
* Creates new form JFrameMapWithSetAirBombers
|
||||
*/
|
||||
public JFrameMapWithSetAirBombers() {
|
||||
initComponents();
|
||||
_mapsDict.put("Простая карта", new SimpleMap());
|
||||
_mapsDict.put("Городская карта", new CityMap());
|
||||
_mapsDict.put("Линейная карта", new LineMap());
|
||||
_mapsCollection = new MapsCollection(airBomberCanvas.getWidth(),airBomberCanvas.getHeight());
|
||||
DefaultComboBoxModel defaultcombModel = new DefaultComboBoxModel();
|
||||
comboBoxSelectorMap.setModel(defaultcombModel);
|
||||
for (var elem : _mapsDict.keySet()){
|
||||
comboBoxSelectorMap.addItem(elem);
|
||||
}
|
||||
comboBoxSelectorMap.setSelectedIndex(-1);
|
||||
}
|
||||
private HashMap<String, AbstractMap> _mapsDict = new HashMap<>();
|
||||
|
||||
private MapsCollection _mapsCollection;
|
||||
|
||||
private LinkedList<DrawingObjectAirBomber> deletedAirBombers = new LinkedList<>();
|
||||
|
||||
/**
|
||||
* This method is called from within the constructor to initialize the form.
|
||||
* WARNING: Do NOT modify this code. The content of this method is always
|
||||
* regenerated by the Form Editor.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
||||
private void initComponents() {
|
||||
|
||||
airBomberCanvas = new AirBomberPackage.CanvasMy();
|
||||
comboBoxSelectorMap = new javax.swing.JComboBox<>();
|
||||
buttonAddAirBomber = new javax.swing.JButton();
|
||||
maskedTextBoxPosition = new javax.swing.JFormattedTextField();
|
||||
buttonRemoveAirBomber = new javax.swing.JButton();
|
||||
buttonShowStorage = new javax.swing.JButton();
|
||||
buttonShowOnMap = new javax.swing.JButton();
|
||||
leftButton = new javax.swing.JButton();
|
||||
downButton = new javax.swing.JButton();
|
||||
rightButton = new javax.swing.JButton();
|
||||
upButton = new javax.swing.JButton();
|
||||
jLabel1 = new javax.swing.JLabel();
|
||||
jLabel2 = new javax.swing.JLabel();
|
||||
textBoxNewMapName = new javax.swing.JTextField();
|
||||
buttonAddMap = new javax.swing.JButton();
|
||||
jScrollPane1 = new javax.swing.JScrollPane();
|
||||
listBoxMaps = new javax.swing.JList<>();
|
||||
buttonDeleteMap = new javax.swing.JButton();
|
||||
buttonShowDeleted = new javax.swing.JButton();
|
||||
|
||||
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
|
||||
|
||||
buttonAddAirBomber.setText("Добавить бомбардировщик");
|
||||
buttonAddAirBomber.setToolTipText("");
|
||||
buttonAddAirBomber.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
buttonAddAirBomberActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
maskedTextBoxPosition.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##")));
|
||||
} catch (java.text.ParseException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
buttonRemoveAirBomber.setText("Удалить бомбардировщик");
|
||||
buttonRemoveAirBomber.setToolTipText("");
|
||||
buttonRemoveAirBomber.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
buttonRemoveAirBomberActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
buttonShowStorage.setText("Посмотреть хранилище");
|
||||
buttonShowStorage.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
buttonShowStorageActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
buttonShowOnMap.setText("Посмотреть карту");
|
||||
buttonShowOnMap.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
buttonShowOnMapActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
leftButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/AirBomberPackage/arrowLeft.png"))); // NOI18N
|
||||
leftButton.setMargin(new java.awt.Insets(0, 0, 0, 0));
|
||||
leftButton.setMaximumSize(new java.awt.Dimension(30, 30));
|
||||
leftButton.setMinimumSize(new java.awt.Dimension(30, 30));
|
||||
leftButton.setName("buttonLeft"); // NOI18N
|
||||
leftButton.setPreferredSize(new java.awt.Dimension(30, 30));
|
||||
leftButton.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
moveButtonActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
downButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/AirBomberPackage/arrowDown.png"))); // NOI18N
|
||||
downButton.setMaximumSize(new java.awt.Dimension(30, 30));
|
||||
downButton.setMinimumSize(new java.awt.Dimension(30, 30));
|
||||
downButton.setName("buttonDown"); // NOI18N
|
||||
downButton.setPreferredSize(new java.awt.Dimension(30, 30));
|
||||
downButton.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
moveButtonActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
rightButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/AirBomberPackage/arrowRight.png"))); // NOI18N
|
||||
rightButton.setMaximumSize(new java.awt.Dimension(30, 30));
|
||||
rightButton.setMinimumSize(new java.awt.Dimension(30, 30));
|
||||
rightButton.setName("buttonRight"); // NOI18N
|
||||
rightButton.setPreferredSize(new java.awt.Dimension(30, 30));
|
||||
rightButton.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
moveButtonActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
upButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/AirBomberPackage/arrowUp.png"))); // NOI18N
|
||||
upButton.setMaximumSize(new java.awt.Dimension(30, 30));
|
||||
upButton.setMinimumSize(new java.awt.Dimension(30, 30));
|
||||
upButton.setName("buttonUp"); // NOI18N
|
||||
upButton.setPreferredSize(new java.awt.Dimension(30, 30));
|
||||
upButton.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
moveButtonActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
jLabel1.setText("Инструменты");
|
||||
|
||||
jLabel2.setText("Карты");
|
||||
|
||||
buttonAddMap.setText("Добавить карту");
|
||||
buttonAddMap.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
buttonAddMapActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
listBoxMaps.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
|
||||
listBoxMaps.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
|
||||
public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
|
||||
listBoxMapsValueChanged(evt);
|
||||
}
|
||||
});
|
||||
jScrollPane1.setViewportView(listBoxMaps);
|
||||
|
||||
buttonDeleteMap.setText("Удалить карту");
|
||||
buttonDeleteMap.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
buttonDeleteMapActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
buttonShowDeleted.setText("Показать удалённый");
|
||||
buttonShowDeleted.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
buttonShowDeletedActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
|
||||
getContentPane().setLayout(layout);
|
||||
layout.setHorizontalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addComponent(airBomberCanvas, javax.swing.GroupLayout.PREFERRED_SIZE, 664, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 59, Short.MAX_VALUE)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
|
||||
.addComponent(buttonDeleteMap, javax.swing.GroupLayout.PREFERRED_SIZE, 188, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
|
||||
.addComponent(buttonAddAirBomber, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(maskedTextBoxPosition)
|
||||
.addComponent(buttonRemoveAirBomber, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(buttonShowStorage, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(buttonShowOnMap, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
|
||||
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 188, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(buttonAddMap, javax.swing.GroupLayout.PREFERRED_SIZE, 188, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(comboBoxSelectorMap, javax.swing.GroupLayout.PREFERRED_SIZE, 188, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(textBoxNewMapName, javax.swing.GroupLayout.PREFERRED_SIZE, 188, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(buttonShowDeleted, javax.swing.GroupLayout.PREFERRED_SIZE, 188, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
|
||||
.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(jLabel1)))
|
||||
.addGap(23, 23, 23))
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
||||
.addComponent(leftButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(upButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addComponent(downButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(rightButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
|
||||
.addGap(62, 62, 62))))
|
||||
);
|
||||
layout.setVerticalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(airBomberCanvas, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addGap(15, 15, 15)
|
||||
.addComponent(jLabel1)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(jLabel2)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(textBoxNewMapName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(comboBoxSelectorMap, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(buttonAddMap, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(buttonDeleteMap, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 45, Short.MAX_VALUE)
|
||||
.addComponent(buttonShowDeleted, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(buttonAddAirBomber)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(maskedTextBoxPosition, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(buttonRemoveAirBomber)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(buttonShowStorage)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(buttonShowOnMap)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(upButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
|
||||
.addComponent(downButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(leftButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(rightButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addContainerGap())
|
||||
);
|
||||
|
||||
pack();
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
|
||||
private void moveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_moveButtonActionPerformed
|
||||
String name = ((JButton) evt.getSource()).getName();
|
||||
Direction dir = Direction.NONE;
|
||||
switch (name)
|
||||
{
|
||||
case "buttonUp":
|
||||
dir = Direction.UP;
|
||||
break;
|
||||
case "buttonDown":
|
||||
dir = Direction.DOWN;
|
||||
break;
|
||||
case "buttonLeft":
|
||||
dir = Direction.LEFT;
|
||||
break;
|
||||
case "buttonRight":
|
||||
dir = Direction.RIGHT;
|
||||
break;
|
||||
}
|
||||
airBomberCanvas.getGraphics().drawImage(_mapsCollection.Get(listBoxMaps.getSelectedValue()).MoveObject(dir), 0, 0, null);
|
||||
}//GEN-LAST:event_moveButtonActionPerformed
|
||||
|
||||
private void buttonAddAirBomberActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonAddAirBomberActionPerformed
|
||||
if (listBoxMaps.getSelectedIndex() == -1){
|
||||
return;
|
||||
}
|
||||
JFrameAirBomber form = new JFrameAirBomber(this);
|
||||
DrawingAirBomber selectedAirBomber = form.run();
|
||||
if (selectedAirBomber != null)
|
||||
{
|
||||
DrawingObjectAirBomber objectAirBomber = new DrawingObjectAirBomber(selectedAirBomber);
|
||||
if (_mapsCollection.Get(listBoxMaps.getSelectedValue()).add(objectAirBomber) != -1)
|
||||
{
|
||||
JOptionPane.showMessageDialog(this, "Объект добавлен");
|
||||
airBomberCanvas.getGraphics().drawImage(_mapsCollection.Get(listBoxMaps.getSelectedValue()).ShowSet(), 0, 0, null);
|
||||
}
|
||||
else
|
||||
{
|
||||
JOptionPane.showMessageDialog(this, "Не удалось добавить объект");
|
||||
}
|
||||
}
|
||||
}//GEN-LAST:event_buttonAddAirBomberActionPerformed
|
||||
|
||||
private void buttonRemoveAirBomberActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonRemoveAirBomberActionPerformed
|
||||
if (listBoxMaps.getSelectedIndex() == -1){
|
||||
return;
|
||||
}
|
||||
if (maskedTextBoxPosition.getText().isBlank() || maskedTextBoxPosition.getText().isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
var res = JOptionPane.showConfirmDialog((Component) this, (Object) "Удалить объект?", "Удаление", JOptionPane.OK_CANCEL_OPTION);
|
||||
if (res == JOptionPane.CANCEL_OPTION)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int pos = Integer.parseInt(maskedTextBoxPosition.getText());
|
||||
DrawingObjectAirBomber deletedAirBomber = _mapsCollection.Get(listBoxMaps.getSelectedValue()).remove(pos);
|
||||
if (deletedAirBomber != null)
|
||||
{
|
||||
deletedAirBombers.add(deletedAirBomber);
|
||||
JOptionPane.showMessageDialog(null,"Объект удален");
|
||||
airBomberCanvas.getGraphics().drawImage(_mapsCollection.Get(listBoxMaps.getSelectedValue()).ShowSet(), 0, 0, null);
|
||||
}
|
||||
else
|
||||
{
|
||||
JOptionPane.showMessageDialog(null,"Не удалось удалить объект!");
|
||||
}
|
||||
}//GEN-LAST:event_buttonRemoveAirBomberActionPerformed
|
||||
|
||||
private void buttonShowStorageActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonShowStorageActionPerformed
|
||||
if (listBoxMaps.getSelectedIndex() == -1){
|
||||
return;
|
||||
}
|
||||
airBomberCanvas.getGraphics().drawImage(_mapsCollection.Get(listBoxMaps.getSelectedValue()).ShowSet(), 0, 0, null);
|
||||
}//GEN-LAST:event_buttonShowStorageActionPerformed
|
||||
|
||||
private void buttonShowOnMapActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonShowOnMapActionPerformed
|
||||
if (listBoxMaps.getSelectedIndex() == -1){
|
||||
return;
|
||||
}
|
||||
airBomberCanvas.getGraphics().drawImage(_mapsCollection.Get(listBoxMaps.getSelectedValue()).ShowOnMap(), 0, 0, null);
|
||||
}//GEN-LAST:event_buttonShowOnMapActionPerformed
|
||||
|
||||
private void buttonAddMapActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonAddMapActionPerformed
|
||||
if (comboBoxSelectorMap.getSelectedIndex() == -1 || textBoxNewMapName.getText().isBlank()){
|
||||
JOptionPane.showMessageDialog(this, "Не все данные заполнены!");
|
||||
return;
|
||||
}
|
||||
if (!_mapsDict.containsKey((String) comboBoxSelectorMap.getSelectedItem())){
|
||||
JOptionPane.showMessageDialog(this, "Нет такой карты!");
|
||||
return;
|
||||
}
|
||||
_mapsCollection.AddMap(textBoxNewMapName.getText(), _mapsDict.get((String) comboBoxSelectorMap.getSelectedItem()));
|
||||
ReloadMaps();
|
||||
}//GEN-LAST:event_buttonAddMapActionPerformed
|
||||
|
||||
private void buttonDeleteMapActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonDeleteMapActionPerformed
|
||||
if (listBoxMaps.getSelectedIndex() == -1){
|
||||
return;
|
||||
}
|
||||
if (JOptionPane.showConfirmDialog(this, (Object) ("Удалить карту " + listBoxMaps.getSelectedValue() + "?") , "Удаление", JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION){
|
||||
_mapsCollection.DelMap(listBoxMaps.getSelectedValue());
|
||||
ReloadMaps();
|
||||
}
|
||||
}//GEN-LAST:event_buttonDeleteMapActionPerformed
|
||||
|
||||
private void buttonShowDeletedActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonShowDeletedActionPerformed
|
||||
if (deletedAirBombers.isEmpty()){
|
||||
return;
|
||||
}
|
||||
JFrameAirBomber form = new JFrameAirBomber(this, deletedAirBombers.poll());
|
||||
form.run();
|
||||
}//GEN-LAST:event_buttonShowDeletedActionPerformed
|
||||
|
||||
private void listBoxMapsValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_listBoxMapsValueChanged
|
||||
if (listBoxMaps.getSelectedIndex() == -1){
|
||||
return;
|
||||
}
|
||||
airBomberCanvas.getGraphics().drawImage(_mapsCollection.Get(listBoxMaps.getSelectedValue()).ShowSet(), 0, 0, null);
|
||||
}//GEN-LAST:event_listBoxMapsValueChanged
|
||||
|
||||
private void ReloadMaps()
|
||||
{
|
||||
int index = listBoxMaps.getSelectedIndex();
|
||||
|
||||
DefaultListModel listBoxMapsModel = new DefaultListModel();
|
||||
listBoxMapsModel.clear();
|
||||
for (int i = 0; i < _mapsCollection.getKeys().size(); i++)
|
||||
{
|
||||
listBoxMapsModel.addElement(_mapsCollection.getKeys().get(i));
|
||||
}
|
||||
listBoxMaps.setModel(listBoxMapsModel);
|
||||
if (listBoxMapsModel.size() > 0 && (index == -1 || index >= listBoxMapsModel.size()))
|
||||
{
|
||||
listBoxMaps.setSelectedIndex(0);
|
||||
}
|
||||
else if (listBoxMapsModel.size() > 0 && index > -1 && index < listBoxMapsModel.size())
|
||||
{
|
||||
listBoxMaps.setSelectedIndex(index);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param args the command line arguments
|
||||
*/
|
||||
public static void main(String args[]) {
|
||||
/* Set the Nimbus look and feel */
|
||||
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
|
||||
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
|
||||
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
|
||||
*/
|
||||
try {
|
||||
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
|
||||
if ("Nimbus".equals(info.getName())) {
|
||||
javax.swing.UIManager.setLookAndFeel(info.getClassName());
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (ClassNotFoundException ex) {
|
||||
java.util.logging.Logger.getLogger(JFrameMapWithSetAirBombers.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||
} catch (InstantiationException ex) {
|
||||
java.util.logging.Logger.getLogger(JFrameMapWithSetAirBombers.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||
} catch (IllegalAccessException ex) {
|
||||
java.util.logging.Logger.getLogger(JFrameMapWithSetAirBombers.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
|
||||
java.util.logging.Logger.getLogger(JFrameMapWithSetAirBombers.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||
}
|
||||
//</editor-fold>
|
||||
|
||||
/* Create and display the form */
|
||||
java.awt.EventQueue.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
new JFrameMapWithSetAirBombers().setVisible(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private AirBomberPackage.CanvasMy airBomberCanvas;
|
||||
private javax.swing.JButton buttonAddAirBomber;
|
||||
private javax.swing.JButton buttonAddMap;
|
||||
private javax.swing.JButton buttonDeleteMap;
|
||||
private javax.swing.JButton buttonRemoveAirBomber;
|
||||
private javax.swing.JButton buttonShowDeleted;
|
||||
private javax.swing.JButton buttonShowOnMap;
|
||||
private javax.swing.JButton buttonShowStorage;
|
||||
private javax.swing.JComboBox<String> comboBoxSelectorMap;
|
||||
private javax.swing.JButton downButton;
|
||||
private javax.swing.JLabel jLabel1;
|
||||
private javax.swing.JLabel jLabel2;
|
||||
private javax.swing.JScrollPane jScrollPane1;
|
||||
private javax.swing.JButton leftButton;
|
||||
private javax.swing.JList<String> listBoxMaps;
|
||||
private javax.swing.JFormattedTextField maskedTextBoxPosition;
|
||||
private javax.swing.JButton rightButton;
|
||||
private javax.swing.JTextField textBoxNewMapName;
|
||||
private javax.swing.JButton upButton;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
}
|
103
AirBomber/src/AirBomberPackage/LineMap.java
Normal file
103
AirBomber/src/AirBomberPackage/LineMap.java
Normal file
@ -0,0 +1,103 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package AirBomberPackage;
|
||||
import java.awt.*;
|
||||
/**
|
||||
*
|
||||
* @author Андрей
|
||||
*/
|
||||
public class LineMap extends AbstractMap {
|
||||
/// <summary>
|
||||
/// Цвет участка закрытого
|
||||
/// </summary>
|
||||
private final Color barrierColor = Color.BLACK;
|
||||
/// <summary>
|
||||
/// Цвет участка открытого
|
||||
/// </summary>
|
||||
private final Color roadColor = Color.CYAN;
|
||||
|
||||
@Override
|
||||
protected void DrawBarrierPart(Graphics g, int i, int j)
|
||||
{
|
||||
g.setColor(barrierColor);
|
||||
g.fillRect(i * _size_x, j * _size_y, _size_x, _size_y);
|
||||
g.setColor(Color.BLACK);
|
||||
}
|
||||
@Override
|
||||
protected void DrawRoadPart(Graphics g, int i, int j)
|
||||
{
|
||||
g.setColor(roadColor);
|
||||
g.fillRect(i * _size_x, j * _size_y, _size_x, _size_y);
|
||||
g.setColor(Color.BLACK);
|
||||
}
|
||||
@Override
|
||||
protected void GenerateMap()
|
||||
{
|
||||
_map = new int[100][100];
|
||||
_size_x = _width / _map.length;
|
||||
_size_y = _height / _map[0].length;
|
||||
int lineCounter = 0;
|
||||
int numOfLines = _random.nextInt(1, 4);
|
||||
for (int i = 0; i < _map.length; ++i)
|
||||
{
|
||||
for (int j = 0; j < _map[0].length; ++j)
|
||||
{
|
||||
_map[i][j] = _freeRoad;
|
||||
}
|
||||
}
|
||||
while (lineCounter < numOfLines)
|
||||
{
|
||||
int randomInt = _random.nextInt(0, 1000);
|
||||
boolean vertical = false;
|
||||
if (randomInt % 2 == 0) vertical = true;
|
||||
if (vertical)
|
||||
{
|
||||
int x = _random.nextInt(0, 89);
|
||||
int lineWidth = _random.nextInt(2, 5);
|
||||
if (x + lineWidth >= _map.length) x = _random.nextInt(_map.length - lineWidth - 1, _map.length);
|
||||
|
||||
boolean isFreeSpace = true;
|
||||
for (int i = x; i < x + lineWidth; i++)
|
||||
{
|
||||
if (_map[i][0] != _freeRoad) isFreeSpace = false;
|
||||
}
|
||||
if (isFreeSpace)
|
||||
{
|
||||
for (int i = x; i < x + lineWidth; i++)
|
||||
{
|
||||
for (int j = 0; j < _map.length; j++)
|
||||
{
|
||||
_map[i][j] = _barrier;
|
||||
}
|
||||
}
|
||||
lineCounter++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int y = _random.nextInt(0, 89);
|
||||
int lineHeigth = _random.nextInt(2, 5);
|
||||
if (y + lineHeigth >= _map[0].length) y = _random.nextInt(_map[0].length - lineHeigth - 1, _map[0].length);
|
||||
|
||||
boolean isFreeSpace = true;
|
||||
for (int j = y; j < y + lineHeigth; j++)
|
||||
{
|
||||
if (_map[0][j] != _freeRoad) isFreeSpace = false;
|
||||
}
|
||||
if (isFreeSpace)
|
||||
{
|
||||
for (int j = y; j < y + lineHeigth; j++)
|
||||
{
|
||||
for (int i = 0; i < _map[0].length; i++)
|
||||
{
|
||||
_map[i][j] = _barrier;
|
||||
}
|
||||
}
|
||||
lineCounter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
127
AirBomber/src/AirBomberPackage/MapWithSetAirBombersGeneric.java
Normal file
127
AirBomber/src/AirBomberPackage/MapWithSetAirBombersGeneric.java
Normal file
@ -0,0 +1,127 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package AirBomberPackage;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
/**
|
||||
*
|
||||
* @author Андрей
|
||||
*/
|
||||
public class MapWithSetAirBombersGeneric <T extends IDrawingObject, U extends AbstractMap> {
|
||||
private int _pictureWidth;
|
||||
private int _pictureHeight;
|
||||
private int _placeSizeWidth = 110;
|
||||
private int _placeSizeHeight = 100;
|
||||
private SetAirBombersGeneric<T> _setAirBombers;
|
||||
private U _map;
|
||||
public MapWithSetAirBombersGeneric(int picWidth, int picHeight, U map)
|
||||
{
|
||||
int width = picWidth / _placeSizeWidth;
|
||||
int height = picHeight / _placeSizeHeight;
|
||||
_setAirBombers = new SetAirBombersGeneric<T>(width * height);
|
||||
_pictureWidth = picWidth;
|
||||
_pictureHeight = picHeight;
|
||||
_map = map;
|
||||
}
|
||||
|
||||
public SetAirBombersGeneric<T> getSetAirBombers(){
|
||||
return _setAirBombers;
|
||||
}
|
||||
|
||||
public int add(T airBomber){
|
||||
return _setAirBombers.Insert(airBomber);
|
||||
}
|
||||
|
||||
public T remove(int position){
|
||||
return _setAirBombers.Remove(position);
|
||||
}
|
||||
|
||||
public BufferedImage ShowSet()
|
||||
{
|
||||
BufferedImage bmp = new BufferedImage(_pictureWidth, _pictureHeight, BufferedImage.TYPE_INT_ARGB);
|
||||
Graphics2D gr = bmp.createGraphics();
|
||||
DrawBackground(gr);
|
||||
DrawAirBombers(gr);
|
||||
return bmp;
|
||||
}
|
||||
|
||||
public BufferedImage ShowOnMap()
|
||||
{
|
||||
Shaking();
|
||||
for (int i = 0; i < _setAirBombers.getCount(); i++)
|
||||
{
|
||||
var airBomber = _setAirBombers.Get(i);
|
||||
if (airBomber != null)
|
||||
{
|
||||
return _map.CreateMap(700, 700, airBomber);
|
||||
}
|
||||
}
|
||||
return new BufferedImage(_pictureWidth, _pictureHeight, BufferedImage.TYPE_INT_ARGB);
|
||||
}
|
||||
|
||||
public BufferedImage MoveObject(Direction direction)
|
||||
{
|
||||
if (_map != null)
|
||||
{
|
||||
return _map.MoveObject(direction);
|
||||
}
|
||||
return new BufferedImage(_pictureWidth, _pictureHeight, BufferedImage.TYPE_INT_ARGB);
|
||||
}
|
||||
|
||||
private void Shaking()
|
||||
{
|
||||
int j = _setAirBombers.getCount() - 1;
|
||||
for (int i = 0; i < _setAirBombers.getCount(); i++)
|
||||
{
|
||||
if (_setAirBombers.Get(i) == null)
|
||||
{
|
||||
for (; j > i; j--)
|
||||
{
|
||||
var car = _setAirBombers.Get(j);
|
||||
if (car != null)
|
||||
{
|
||||
_setAirBombers.Insert(car, i);
|
||||
_setAirBombers.Remove(j);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (j <= i)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawBackground(Graphics2D g)
|
||||
{
|
||||
g.setColor(Color.GRAY);
|
||||
g.fillRect(0, 0, _pictureWidth, _pictureHeight);
|
||||
g.setColor(Color.WHITE);
|
||||
g.setStroke(new BasicStroke(3));
|
||||
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
|
||||
{
|
||||
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
|
||||
{//линия рамзетки места
|
||||
g.drawLine(i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight);
|
||||
}
|
||||
g.drawLine(i * _placeSizeWidth, 0, i * _placeSizeWidth, (_pictureHeight / _placeSizeHeight) * _placeSizeHeight);
|
||||
}
|
||||
g.setStroke(new BasicStroke(1));
|
||||
g.setColor(Color.BLACK);
|
||||
}
|
||||
|
||||
private void DrawAirBombers(Graphics2D g)
|
||||
{
|
||||
int numOfObjectsInRow = _pictureWidth / _placeSizeWidth;
|
||||
for (int i = 0; i < _setAirBombers.getCount(); i++)
|
||||
{
|
||||
if (_setAirBombers.Get(i) != null){
|
||||
_setAirBombers.Get(i).SetObject((numOfObjectsInRow - (i % numOfObjectsInRow) - 1) * _placeSizeWidth, (i / numOfObjectsInRow) * _placeSizeHeight, _pictureWidth, _pictureHeight);
|
||||
_setAirBombers.Get(i).DrawingObject(g);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
79
AirBomber/src/AirBomberPackage/MapsCollection.java
Normal file
79
AirBomber/src/AirBomberPackage/MapsCollection.java
Normal file
@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package AirBomberPackage;
|
||||
import java.util.HashMap;
|
||||
import java.util.ArrayList;
|
||||
/**
|
||||
*
|
||||
* @author Андрей
|
||||
*/
|
||||
public class MapsCollection {
|
||||
/// <summary>
|
||||
/// Словарь (хранилище) с картами
|
||||
/// </summary>
|
||||
HashMap<String, MapWithSetAirBombersGeneric<DrawingObjectAirBomber, AbstractMap>> _mapStorages;
|
||||
/// <summary>
|
||||
/// Возвращение списка названий карт
|
||||
/// </summary>
|
||||
public ArrayList<String> getKeys(){
|
||||
ArrayList<String> keys = new ArrayList<>(_mapStorages.keySet());
|
||||
return keys;
|
||||
}
|
||||
/// <summary>
|
||||
/// Ширина окна отрисовки
|
||||
/// </summary>
|
||||
private int _pictureWidth;
|
||||
/// <summary>
|
||||
/// Высота окна отрисовки
|
||||
/// </summary>
|
||||
private int _pictureHeight;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="pictureWidth"></param>
|
||||
/// <param name="pictureHeight"></param>
|
||||
public MapsCollection(int pictureWidth, int pictureHeight)
|
||||
{
|
||||
_mapStorages = new HashMap<String, MapWithSetAirBombersGeneric<DrawingObjectAirBomber, AbstractMap>>();
|
||||
_pictureWidth = pictureWidth;
|
||||
_pictureHeight = pictureHeight;
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление карты
|
||||
/// </summary>
|
||||
/// <param name="name">Название карты</param>
|
||||
/// <param name="map">Карта</param>
|
||||
public boolean AddMap(String name, AbstractMap map)
|
||||
{
|
||||
if (_mapStorages.containsKey(name))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
_mapStorages.put(name, new MapWithSetAirBombersGeneric<DrawingObjectAirBomber, AbstractMap>(_pictureWidth, _pictureHeight, map));
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление карты
|
||||
/// </summary>
|
||||
/// <param name="name">Название карты</param>
|
||||
public void DelMap(String name)
|
||||
{
|
||||
if (_mapStorages.containsKey(name))
|
||||
{
|
||||
_mapStorages.remove(name);
|
||||
}
|
||||
}
|
||||
|
||||
public MapWithSetAirBombersGeneric<DrawingObjectAirBomber, AbstractMap> Get(String ind){
|
||||
if (_mapStorages.containsKey(ind)) return _mapStorages.get(ind);
|
||||
else return null;
|
||||
}
|
||||
|
||||
public DrawingObjectAirBomber Get(String ind, int index){
|
||||
if (!_mapStorages.containsKey(ind)) return null;
|
||||
MapWithSetAirBombersGeneric<DrawingObjectAirBomber, AbstractMap> map = _mapStorages.get(ind);
|
||||
return map.getSetAirBombers().Get(index);
|
||||
}
|
||||
}
|
95
AirBomber/src/AirBomberPackage/SetAirBombersGeneric.java
Normal file
95
AirBomber/src/AirBomberPackage/SetAirBombersGeneric.java
Normal file
@ -0,0 +1,95 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package AirBomberPackage;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Андрей
|
||||
*/
|
||||
public class SetAirBombersGeneric<T> {
|
||||
/// <summary>
|
||||
/// Массив объектов, которые храним
|
||||
/// </summary>
|
||||
private ArrayList<T> _places;
|
||||
/// <summary>
|
||||
/// Количество объектов в массиве
|
||||
/// </summary>
|
||||
private int _maxCount;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="count"></param>
|
||||
public SetAirBombersGeneric(int count)
|
||||
{
|
||||
_places = new ArrayList<T>(count);
|
||||
_maxCount = count;
|
||||
}
|
||||
|
||||
public int getCount(){
|
||||
return _places.size();
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор
|
||||
/// </summary>
|
||||
/// <param name="airBomber">Добавляемый автомобиль</param>
|
||||
/// <returns></returns>
|
||||
public int Insert(T airBomber)
|
||||
{
|
||||
return Insert(airBomber, 0);
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор на конкретную позицию
|
||||
/// </summary>
|
||||
/// <param name="airBomber">Добавляемый автомобиль</param>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns></returns>
|
||||
public int Insert(T airBomber, int position)
|
||||
{
|
||||
if (position < 0 || position >= _maxCount)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
_places.add(position, airBomber);
|
||||
return position;
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление объекта из набора с конкретной позиции
|
||||
/// </summary>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public T Remove(int position)
|
||||
{
|
||||
if (position <0 || position >= _maxCount)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
T removedObject = _places.get(position);
|
||||
_places.remove(position);
|
||||
return removedObject;
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение объекта из набора по позиции
|
||||
/// </summary>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public T Get(int position)
|
||||
{
|
||||
if (position >= _maxCount || position < 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return _places.get(position);
|
||||
}
|
||||
|
||||
public void Set(int position, T value){
|
||||
if (position >= _maxCount || position < 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_places.set(position, value);
|
||||
}
|
||||
}
|
99
AirBomber/src/AirBomberPackage/SetAirBombersGenericDop.java
Normal file
99
AirBomber/src/AirBomberPackage/SetAirBombersGenericDop.java
Normal file
@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package AirBomberPackage;
|
||||
import java.util.Random;
|
||||
/**
|
||||
*
|
||||
* @author Андрей
|
||||
*/
|
||||
public class SetAirBombersGenericDop<T extends EntityAirBomber, U extends IDrawingObjectDop> {
|
||||
private Object[] _bases;
|
||||
private Object[] _engines;
|
||||
private int Count;
|
||||
|
||||
public SetAirBombersGenericDop(int count){
|
||||
_bases = new Object[count];
|
||||
_engines = new Object[count];
|
||||
Count = count;
|
||||
}
|
||||
|
||||
public int add(T base){
|
||||
return add(base, 0);
|
||||
}
|
||||
|
||||
public int add(T base, int position){
|
||||
if (position >= _bases.length)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if (_bases[position] != null)
|
||||
{
|
||||
int indexNull = -1;
|
||||
for (int i = position; i < _bases.length; i++)
|
||||
{
|
||||
if (_bases[i] == null)
|
||||
{
|
||||
indexNull = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (indexNull == -1) return -1;
|
||||
for (int i = indexNull; i > position; i--)
|
||||
{
|
||||
T tmp = (T) _bases[i];
|
||||
_bases[i] = _bases[i - 1];
|
||||
_bases[i - 1] = tmp;
|
||||
}
|
||||
}
|
||||
_bases[position] = base;
|
||||
return position;
|
||||
}
|
||||
|
||||
public int add(U engine){
|
||||
return add(engine, 0);
|
||||
}
|
||||
|
||||
public int add(U engine, int position){
|
||||
if (position >= _engines.length)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if (_engines[position] != null)
|
||||
{
|
||||
int indexNull = -1;
|
||||
for (int i = position; i < _engines.length; i++)
|
||||
{
|
||||
if (_engines[i] == null)
|
||||
{
|
||||
indexNull = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (indexNull == -1) return -1;
|
||||
for (int i = indexNull; i > position; i--)
|
||||
{
|
||||
U tmp = (U) _engines[i];
|
||||
_engines[i] = _engines[i - 1];
|
||||
_engines[i - 1] = tmp;
|
||||
}
|
||||
}
|
||||
_engines[position] = engine;
|
||||
return position;
|
||||
}
|
||||
|
||||
|
||||
public DrawingAirBomber buildAirBomber(){
|
||||
Random rnd = new Random();
|
||||
int baseIndex = rnd.nextInt(0, _bases.length);
|
||||
int engineIndex = rnd.nextInt(0, _engines.length);
|
||||
EnginesType enginesType;
|
||||
T selectedBase = (T) _bases[baseIndex];
|
||||
U selectedEngines = (U) _engines[engineIndex];
|
||||
if (selectedEngines instanceof DrawingEngines) enginesType = EnginesType.RECTANGLE;
|
||||
else if (selectedEngines instanceof DrawingEnginesTriangle) enginesType = EnginesType.TRIANGLE;
|
||||
else enginesType = EnginesType.OVAL;
|
||||
return new DrawingAirBomber(selectedBase.getSpeed(), selectedBase.getWeight(), selectedBase.getBodyColor(), selectedEngines.getNumberOfEngines(), enginesType);
|
||||
}
|
||||
}
|
60
AirBomber/src/AirBomberPackage/SimpleMap.java
Normal file
60
AirBomber/src/AirBomberPackage/SimpleMap.java
Normal file
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package AirBomberPackage;
|
||||
import java.awt.*;
|
||||
/**
|
||||
*
|
||||
* @author Андрей
|
||||
*/
|
||||
public class SimpleMap extends AbstractMap {
|
||||
/// <summary>
|
||||
/// Цвет участка закрытого
|
||||
/// </summary>
|
||||
private final Color barrierColor = Color.BLACK;
|
||||
/// <summary>
|
||||
/// Цвет участка открытого
|
||||
/// </summary>
|
||||
private final Color roadColor = Color.GRAY;
|
||||
|
||||
@Override
|
||||
protected void DrawBarrierPart(Graphics g, int i, int j)
|
||||
{
|
||||
g.setColor(barrierColor);
|
||||
g.fillRect(i * _size_x, j * _size_y, _size_x, _size_y);
|
||||
g.setColor(Color.BLACK);
|
||||
}
|
||||
@Override
|
||||
protected void DrawRoadPart(Graphics g, int i, int j)
|
||||
{
|
||||
g.setColor(roadColor);
|
||||
g.fillRect(i * _size_x, j * _size_y, _size_x, _size_y);
|
||||
g.setColor(Color.BLACK);
|
||||
}
|
||||
@Override
|
||||
protected void GenerateMap()
|
||||
{
|
||||
_map = new int[100][100];
|
||||
_size_x = _width / _map.length;
|
||||
_size_y = _height / _map[0].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 = _random.nextInt(0, 100);
|
||||
int y = _random.nextInt(0, 100);
|
||||
if (_map[x][y] == _freeRoad)
|
||||
{
|
||||
_map[x][y] = _barrier;
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
BIN
AirBomber/src/AirBomberPackage/arrowDown.png
Normal file
BIN
AirBomber/src/AirBomberPackage/arrowDown.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 565 B |
BIN
AirBomber/src/AirBomberPackage/arrowLeft.png
Normal file
BIN
AirBomber/src/AirBomberPackage/arrowLeft.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 612 B |
BIN
AirBomber/src/AirBomberPackage/arrowRight.png
Normal file
BIN
AirBomber/src/AirBomberPackage/arrowRight.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 619 B |
BIN
AirBomber/src/AirBomberPackage/arrowUp.png
Normal file
BIN
AirBomber/src/AirBomberPackage/arrowUp.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 546 B |
Loading…
Reference in New Issue
Block a user