Вторая лабораторная работа.
This commit is contained in:
parent
a879f47bfe
commit
e7c253b1c7
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);
|
||||||
|
}
|
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++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -9,6 +9,7 @@ package AirBomberPackage;
|
|||||||
* @author Андрей
|
* @author Андрей
|
||||||
*/
|
*/
|
||||||
public enum Direction {
|
public enum Direction {
|
||||||
|
NONE,
|
||||||
UP,
|
UP,
|
||||||
DOWN,
|
DOWN,
|
||||||
LEFT,
|
LEFT,
|
||||||
|
@ -10,23 +10,49 @@ import java.util.Random;
|
|||||||
* @author Андрей
|
* @author Андрей
|
||||||
*/
|
*/
|
||||||
public class DrawingAirBomber {
|
public class DrawingAirBomber {
|
||||||
private EntityAirBomber AirBomber;
|
protected EntityAirBomber AirBomber;
|
||||||
public DrawingEngines drawingEngines;
|
public IDrawingObjectDop drawingEngines;
|
||||||
public float _startPosX;
|
public int _startPosX;
|
||||||
public float _startPosY;
|
public int _startPosY;
|
||||||
private Integer _pictureWidth = null;
|
private Integer _pictureWidth = null;
|
||||||
private Integer _pictureHeight = null;
|
private Integer _pictureHeight = null;
|
||||||
private static final int _airBomberWidth = 110;
|
private int _airBomberWidth = 110;
|
||||||
private static final int _airBomberHeight = 100;
|
private int _airBomberHeight = 100;
|
||||||
|
|
||||||
public void Init(int speed, float weight, Color bodyColor, int numberOfEngines){
|
public DrawingAirBomber(int speed, float weight, Color bodyColor, int numberOfEngines, EnginesType enginesType){
|
||||||
AirBomber = new EntityAirBomber();
|
AirBomber = new EntityAirBomber(speed, weight, bodyColor);
|
||||||
drawingEngines = new DrawingEngines();
|
switch (enginesType) {
|
||||||
AirBomber.Init(speed, weight, bodyColor);
|
case RECTANGLE:
|
||||||
System.out.println(numberOfEngines + "");
|
drawingEngines = new DrawingEngines();
|
||||||
|
break;
|
||||||
|
case TRIANGLE:
|
||||||
|
drawingEngines = new DrawingEnginesTriangle();
|
||||||
|
break;
|
||||||
|
case OVAL:
|
||||||
|
drawingEngines = new DrawingEnginesOval();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new AssertionError();
|
||||||
|
}
|
||||||
drawingEngines.setNumberOfEngines(numberOfEngines);
|
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() {
|
public EntityAirBomber getAirBomber() {
|
||||||
return AirBomber;
|
return AirBomber;
|
||||||
}
|
}
|
||||||
@ -202,6 +228,16 @@ public class DrawingAirBomber {
|
|||||||
g.drawLine(_startPosXInt, _startPosYInt + 50, _startPosXInt + 5, _startPosYInt + 50);
|
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)
|
public void ChangeBorders(int width, int height)
|
||||||
{
|
{
|
||||||
_pictureWidth = width;
|
_pictureWidth = width;
|
||||||
|
@ -11,14 +11,14 @@ import java.awt.Color;
|
|||||||
*
|
*
|
||||||
* @author Андрей
|
* @author Андрей
|
||||||
*/
|
*/
|
||||||
public class DrawingEngines {
|
public class DrawingEngines implements IDrawingObjectDop {
|
||||||
private Engines engines = null;
|
private Engines engines = null;
|
||||||
private int numberOfEngines;
|
private int numberOfEngines;
|
||||||
|
@Override
|
||||||
public int getNumberOfEngines() {
|
public int getNumberOfEngines() {
|
||||||
return numberOfEngines;
|
return numberOfEngines;
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
public void setNumberOfEngines(int numberOfEngines) {
|
public void setNumberOfEngines(int numberOfEngines) {
|
||||||
if (numberOfEngines != 2 && numberOfEngines != 4 && numberOfEngines != 6) return;
|
if (numberOfEngines != 2 && numberOfEngines != 4 && numberOfEngines != 6) return;
|
||||||
this.numberOfEngines = numberOfEngines;
|
this.numberOfEngines = numberOfEngines;
|
||||||
@ -34,14 +34,14 @@ public class DrawingEngines {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
private void drawEngine(Graphics2D g, int startPosX, int startPosY, int yOffset, Color bodyColor){
|
public void drawEngine(Graphics2D g, int startPosX, int startPosY, int yOffset, Color bodyColor){
|
||||||
g.setColor(bodyColor);
|
g.setColor(bodyColor);
|
||||||
g.fillRect(startPosX + 45, startPosY + 40 + yOffset, 5, 5);
|
g.fillRect(startPosX + 45, startPosY + 40 + yOffset, 5, 5);
|
||||||
g.setColor(Color.BLACK);
|
g.setColor(Color.BLACK);
|
||||||
g.drawRect(startPosX + 45, startPosY + 40 + yOffset, 5, 5);
|
g.drawRect(startPosX + 45, startPosY + 40 + yOffset, 5, 5);
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
public void drawEngines(Graphics2D g, int startPosX, int startPosY, Color bodyColor){
|
public void drawEngines(Graphics2D g, int startPosX, int startPosY, Color bodyColor){
|
||||||
if (engines == null) return;
|
if (engines == null) return;
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
56
AirBomber/src/AirBomberPackage/DrawingObjectAirBomber.java
Normal file
56
AirBomber/src/AirBomberPackage/DrawingObjectAirBomber.java
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
* 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
@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/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
|
||||||
|
}
|
@ -31,9 +31,7 @@ public class EntityAirBomber {
|
|||||||
return BodyColor;
|
return BodyColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public EntityAirBomber(int speed, float weight, Color bodyColor){
|
||||||
|
|
||||||
public void Init(int speed, float weight, Color bodyColor){
|
|
||||||
Random rnd = new Random();
|
Random rnd = new Random();
|
||||||
Speed = speed <= 0 ? rnd.nextInt(50, 150) : speed;
|
Speed = speed <= 0 ? rnd.nextInt(50, 150) : speed;
|
||||||
Weight = weight <= 0 ? rnd.nextInt(40, 70) : weight;
|
Weight = weight <= 0 ? rnd.nextInt(40, 70) : weight;
|
||||||
|
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);
|
||||||
|
}
|
@ -41,10 +41,18 @@
|
|||||||
<Component id="jLabelEngines" min="-2" max="-2" attributes="0"/>
|
<Component id="jLabelEngines" min="-2" max="-2" attributes="0"/>
|
||||||
<EmptySpace max="-2" attributes="0"/>
|
<EmptySpace max="-2" attributes="0"/>
|
||||||
<Component id="jComboBoxEngines" min="-2" 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"/>
|
||||||
</Group>
|
</Group>
|
||||||
<Component id="createAirBomberButton" alignment="0" min="-2" max="-2" attributes="0"/>
|
|
||||||
</Group>
|
</Group>
|
||||||
<EmptySpace pref="369" max="32767" attributes="0"/>
|
<EmptySpace pref="157" max="32767" attributes="0"/>
|
||||||
<Group type="103" groupAlignment="1" attributes="0">
|
<Group type="103" groupAlignment="1" attributes="0">
|
||||||
<Component id="upButton" alignment="1" min="-2" pref="30" max="-2" attributes="0"/>
|
<Component id="upButton" alignment="1" min="-2" pref="30" max="-2" attributes="0"/>
|
||||||
<Group type="102" alignment="1" attributes="0">
|
<Group type="102" alignment="1" attributes="0">
|
||||||
@ -57,7 +65,10 @@
|
|||||||
<Component id="rightButton" min="-2" pref="30" max="-2" attributes="0"/>
|
<Component id="rightButton" min="-2" pref="30" max="-2" attributes="0"/>
|
||||||
<EmptySpace min="-2" pref="17" max="-2" attributes="0"/>
|
<EmptySpace min="-2" pref="17" max="-2" attributes="0"/>
|
||||||
</Group>
|
</Group>
|
||||||
<Component id="airBomberCanvas" alignment="0" max="32767" attributes="0"/>
|
<Group type="102" alignment="1" attributes="0">
|
||||||
|
<Component id="airBomberCanvas" max="32767" attributes="0"/>
|
||||||
|
<EmptySpace max="-2" attributes="0"/>
|
||||||
|
</Group>
|
||||||
</Group>
|
</Group>
|
||||||
</DimensionLayout>
|
</DimensionLayout>
|
||||||
<DimensionLayout dim="1">
|
<DimensionLayout dim="1">
|
||||||
@ -70,9 +81,14 @@
|
|||||||
<Group type="103" groupAlignment="3" attributes="0">
|
<Group type="103" groupAlignment="3" attributes="0">
|
||||||
<Component id="jLabelEngines" alignment="3" min="-2" pref="31" max="-2" 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="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>
|
</Group>
|
||||||
<EmptySpace max="-2" attributes="0"/>
|
<EmptySpace max="-2" attributes="0"/>
|
||||||
<Component id="createAirBomberButton" min="-2" pref="31" 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" max="32767" attributes="0"/>
|
||||||
|
</Group>
|
||||||
</Group>
|
</Group>
|
||||||
<Group type="102" alignment="1" attributes="0">
|
<Group type="102" alignment="1" attributes="0">
|
||||||
<Component id="upButton" min="-2" pref="31" max="-2" attributes="0"/>
|
<Component id="upButton" min="-2" pref="31" max="-2" attributes="0"/>
|
||||||
@ -219,5 +235,37 @@
|
|||||||
<AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="<String>"/>
|
<AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="<String>"/>
|
||||||
</AuxValues>
|
</AuxValues>
|
||||||
</Component>
|
</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>
|
||||||
</SubComponents>
|
</SubComponents>
|
||||||
</Form>
|
</Form>
|
||||||
|
@ -21,6 +21,7 @@ public class JFrameAirBomber extends javax.swing.JFrame {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private DrawingAirBomber _airBomber;
|
private DrawingAirBomber _airBomber;
|
||||||
|
private EnginesType enginesType = EnginesType.RECTANGLE;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method is called from within the constructor to initialize the form.
|
* This method is called from within the constructor to initialize the form.
|
||||||
@ -40,6 +41,9 @@ public class JFrameAirBomber extends javax.swing.JFrame {
|
|||||||
airBomberCanvas = new AirBomberPackage.CanvasMy();
|
airBomberCanvas = new AirBomberPackage.CanvasMy();
|
||||||
jLabelEngines = new javax.swing.JLabel();
|
jLabelEngines = new javax.swing.JLabel();
|
||||||
jComboBoxEngines = new javax.swing.JComboBox<>();
|
jComboBoxEngines = new javax.swing.JComboBox<>();
|
||||||
|
ModifyButton = new javax.swing.JButton();
|
||||||
|
jLabelEngines1 = new javax.swing.JLabel();
|
||||||
|
jComboBoxEnginesType = new javax.swing.JComboBox<>();
|
||||||
|
|
||||||
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
|
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
|
||||||
setTitle("Бомбардировщик");
|
setTitle("Бомбардировщик");
|
||||||
@ -113,6 +117,24 @@ public class JFrameAirBomber extends javax.swing.JFrame {
|
|||||||
|
|
||||||
jComboBoxEngines.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Два", "Четыре", "Шесть" }));
|
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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
|
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
|
||||||
getContentPane().setLayout(layout);
|
getContentPane().setLayout(layout);
|
||||||
layout.setHorizontalGroup(
|
layout.setHorizontalGroup(
|
||||||
@ -124,9 +146,16 @@ public class JFrameAirBomber extends javax.swing.JFrame {
|
|||||||
.addContainerGap()
|
.addContainerGap()
|
||||||
.addComponent(jLabelEngines)
|
.addComponent(jLabelEngines)
|
||||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||||
.addComponent(jComboBoxEngines, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
.addComponent(jComboBoxEngines, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||||
.addComponent(createAirBomberButton))
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 369, Short.MAX_VALUE)
|
.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)))
|
||||||
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 157, Short.MAX_VALUE)
|
||||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
|
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
|
||||||
.addComponent(upButton, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
|
.addComponent(upButton, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||||
.addGroup(layout.createSequentialGroup()
|
.addGroup(layout.createSequentialGroup()
|
||||||
@ -136,7 +165,9 @@ public class JFrameAirBomber extends javax.swing.JFrame {
|
|||||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||||
.addComponent(rightButton, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
|
.addComponent(rightButton, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||||
.addGap(17, 17, 17))
|
.addGap(17, 17, 17))
|
||||||
.addComponent(airBomberCanvas, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
.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.setVerticalGroup(
|
||||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||||
@ -147,9 +178,13 @@ public class JFrameAirBomber extends javax.swing.JFrame {
|
|||||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
||||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||||
.addComponent(jLabelEngines, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
|
.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(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)
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||||
.addComponent(createAirBomberButton, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE))
|
.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)))
|
||||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
||||||
.addComponent(upButton, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
|
.addComponent(upButton, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||||
@ -166,12 +201,7 @@ public class JFrameAirBomber extends javax.swing.JFrame {
|
|||||||
|
|
||||||
private void createAirBomberButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_createAirBomberButtonActionPerformed
|
private void createAirBomberButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_createAirBomberButtonActionPerformed
|
||||||
Random rnd = new Random();
|
Random rnd = new Random();
|
||||||
_airBomber = new DrawingAirBomber();
|
_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);
|
||||||
_airBomber.Init(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);
|
|
||||||
System.out.println(((jComboBoxEngines.getSelectedIndex() + 1) * 2) + "");
|
|
||||||
_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);
|
|
||||||
Draw();
|
Draw();
|
||||||
}//GEN-LAST:event_createAirBomberButtonActionPerformed
|
}//GEN-LAST:event_createAirBomberButtonActionPerformed
|
||||||
|
|
||||||
@ -201,6 +231,41 @@ public class JFrameAirBomber extends javax.swing.JFrame {
|
|||||||
_airBomber.ChangeBorders(airBomberCanvas.getWidth(), airBomberCanvas.getHeight());
|
_airBomber.ChangeBorders(airBomberCanvas.getWidth(), airBomberCanvas.getHeight());
|
||||||
}//GEN-LAST:event_airBomberCanvasComponentResized
|
}//GEN-LAST:event_airBomberCanvasComponentResized
|
||||||
|
|
||||||
|
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();
|
||||||
|
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 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(){
|
private void Draw(){
|
||||||
airBomberCanvas.repaint();
|
airBomberCanvas.repaint();
|
||||||
}
|
}
|
||||||
@ -235,17 +300,20 @@ public class JFrameAirBomber extends javax.swing.JFrame {
|
|||||||
/* Create and display the form */
|
/* Create and display the form */
|
||||||
java.awt.EventQueue.invokeLater(new Runnable() {
|
java.awt.EventQueue.invokeLater(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
new JFrameAirBomber().setVisible(true);
|
new JFrameMap().setVisible(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||||
|
private javax.swing.JButton ModifyButton;
|
||||||
private AirBomberPackage.CanvasMy airBomberCanvas;
|
private AirBomberPackage.CanvasMy airBomberCanvas;
|
||||||
private javax.swing.JButton createAirBomberButton;
|
private javax.swing.JButton createAirBomberButton;
|
||||||
private javax.swing.JButton downButton;
|
private javax.swing.JButton downButton;
|
||||||
private javax.swing.JComboBox<String> jComboBoxEngines;
|
private javax.swing.JComboBox<String> jComboBoxEngines;
|
||||||
|
private javax.swing.JComboBox<String> jComboBoxEnginesType;
|
||||||
private javax.swing.JLabel jLabelEngines;
|
private javax.swing.JLabel jLabelEngines;
|
||||||
|
private javax.swing.JLabel jLabelEngines1;
|
||||||
private javax.swing.JButton leftButton;
|
private javax.swing.JButton leftButton;
|
||||||
private javax.swing.JButton rightButton;
|
private javax.swing.JButton rightButton;
|
||||||
private javax.swing.JLabel statusLabel;
|
private javax.swing.JLabel statusLabel;
|
||||||
|
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
|
||||||
|
}
|
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++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
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++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user