Compare commits

..

2 Commits

26 changed files with 2295 additions and 5 deletions

View 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);
}

View 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);
}
}

View 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++;
}
}
}
}

View 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
}

View 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;
}
}
}

View 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;
}
}
}

View 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;
}
}
}

View 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;
}
}
}

View 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);
}
}
}

View 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);
}
}
}

View 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
}

View 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
}

View 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;
}
}

View 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;
}
}

View 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();
}

View 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);
}

View File

@ -3,6 +3,16 @@
<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.JFrameFormInfo">
<Properties> <Properties>
<Property name="defaultCloseOperation" type="int" value="3"/> <Property name="defaultCloseOperation" type="int" value="3"/>
<Property name="title" type="java.lang.String" value="&#x411;&#x43e;&#x43c;&#x431;&#x430;&#x440;&#x434;&#x438;&#x440;&#x43e;&#x432;&#x449;&#x438;&#x43a;"/>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Arial" size="10" style="0"/>
</Property>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[700, 400]"/>
</Property>
<Property name="size" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[700, 400]"/>
</Property>
</Properties> </Properties>
<SyntheticProperties> <SyntheticProperties>
<SyntheticProperty name="formSizePolicy" type="int" value="1"/> <SyntheticProperty name="formSizePolicy" type="int" value="1"/>
@ -23,13 +33,239 @@
<Layout> <Layout>
<DimensionLayout dim="0"> <DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="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"/>
</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> </Group>
</DimensionLayout> </DimensionLayout>
<DimensionLayout dim="1"> <DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0"> <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" pref="31" max="32767" attributes="0"/>
<Component id="ModifyButton" 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> </Group>
</DimensionLayout> </DimensionLayout>
</Layout> </Layout>
<SubComponents>
<Component class="javax.swing.JButton" name="createAirBomberButton">
<Properties>
<Property name="text" type="java.lang.String" value="&#x421;&#x43e;&#x437;&#x434;&#x430;&#x442;&#x44c;"/>
<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="&#x421;&#x43a;&#x43e;&#x440;&#x43e;&#x441;&#x442;&#x44c;: &#x412;&#x435;&#x441;: &#x426;&#x432;&#x435;&#x442;: &#x414;&#x432;&#x438;&#x433;&#x430;&#x442;&#x435;&#x43b;&#x438;:"/>
<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="&#x41a;&#x43e;&#x43b;&#x438;&#x447;&#x435;&#x441;&#x442;&#x432;&#x43e; &#x434;&#x432;&#x438;&#x433;&#x430;&#x442;&#x435;&#x43b;&#x435;&#x439;: "/>
</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="&#x414;&#x432;&#x430;"/>
<StringItem index="1" value="&#x427;&#x435;&#x442;&#x44b;&#x440;&#x435;"/>
<StringItem index="2" value="&#x428;&#x435;&#x441;&#x442;&#x44c;"/>
</StringArray>
</Property>
</Properties>
<AuxValues>
<AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="&lt;String&gt;"/>
</AuxValues>
</Component>
<Component class="javax.swing.JButton" name="ModifyButton">
<Properties>
<Property name="text" type="java.lang.String" value="&#x41c;&#x43e;&#x434;&#x438;&#x444;&#x438;&#x43a;&#x430;&#x446;&#x438;&#x44f;"/>
<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="&#x422;&#x438;&#x43f; &#x434;&#x432;&#x438;&#x433;&#x430;&#x442;&#x435;&#x43b;&#x435;&#x439;: "/>
</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="&#x41a;&#x432;&#x430;&#x434;&#x440;&#x430;&#x442;&#x43d;&#x44b;&#x439;"/>
<StringItem index="1" value="&#x422;&#x440;&#x435;&#x443;&#x433;&#x43e;&#x43b;&#x44c;&#x43d;&#x44b;&#x439;"/>
<StringItem index="2" value="&#x41a;&#x440;&#x443;&#x433;&#x43b;&#x44b;&#x439;"/>
</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="&lt;String&gt;"/>
</AuxValues>
</Component>
</SubComponents>
</Form> </Form>

View File

@ -3,6 +3,9 @@
* Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/JFrame.java to edit this template * Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/JFrame.java to edit this template
*/ */
package AirBomberPackage; package AirBomberPackage;
import java.awt.*;
import javax.swing.*;
import java.util.Random;
/** /**
* *
@ -16,6 +19,9 @@ public class JFrameAirBomber extends javax.swing.JFrame {
public JFrameAirBomber() { public JFrameAirBomber() {
initComponents(); initComponents();
} }
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.
@ -26,22 +32,244 @@ public class JFrameAirBomber extends javax.swing.JFrame {
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void 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();
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<>();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Бомбардировщик");
setFont(new java.awt.Font("Arial", 0, 10)); // NOI18N
setPreferredSize(new java.awt.Dimension(700, 400));
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);
}
});
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(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 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)))
.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.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 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, 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(); pack();
}// </editor-fold>//GEN-END:initComponents }// </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);
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();
_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(){
airBomberCanvas.repaint();
}
/** /**
* @param args the command line arguments * @param args the command line arguments
*/ */
@ -72,11 +300,23 @@ 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 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 // End of variables declaration//GEN-END:variables
} }

View 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="&#x411;&#x43e;&#x43c;&#x431;&#x430;&#x440;&#x434;&#x438;&#x440;&#x43e;&#x432;&#x449;&#x438;&#x43a;"/>
<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="&#x41a;&#x43e;&#x43b;&#x438;&#x447;&#x435;&#x441;&#x442;&#x432;&#x43e; &#x434;&#x432;&#x438;&#x433;&#x430;&#x442;&#x435;&#x43b;&#x435;&#x439;: "/>
</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="&#x414;&#x432;&#x430;"/>
<StringItem index="1" value="&#x427;&#x435;&#x442;&#x44b;&#x440;&#x435;"/>
<StringItem index="2" value="&#x428;&#x435;&#x441;&#x442;&#x44c;"/>
</StringArray>
</Property>
</Properties>
<AuxValues>
<AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="&lt;String&gt;"/>
</AuxValues>
</Component>
<Component class="javax.swing.JButton" name="createAirBomberButton">
<Properties>
<Property name="text" type="java.lang.String" value="&#x421;&#x43e;&#x437;&#x434;&#x430;&#x442;&#x44c;"/>
<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="&#x421;&#x43a;&#x43e;&#x440;&#x43e;&#x441;&#x442;&#x44c;: &#x412;&#x435;&#x441;: &#x426;&#x432;&#x435;&#x442;: &#x414;&#x432;&#x438;&#x433;&#x430;&#x442;&#x435;&#x43b;&#x438;:"/>
<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="&#x41c;&#x43e;&#x434;&#x438;&#x444;&#x438;&#x43a;&#x430;&#x446;&#x438;&#x44f;"/>
<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="&#x41f;&#x440;&#x43e;&#x441;&#x442;&#x430;&#x44f; &#x43a;&#x430;&#x440;&#x442;&#x430;"/>
<StringItem index="1" value="&#x41b;&#x438;&#x43d;&#x435;&#x439;&#x43d;&#x430;&#x44f; &#x43a;&#x430;&#x440;&#x442;&#x430;"/>
<StringItem index="2" value="&#x413;&#x43e;&#x440;&#x43e;&#x434;&#x441;&#x43a;&#x430;&#x44f; &#x43a;&#x430;&#x440;&#x442;&#x430;"/>
</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="&lt;String&gt;"/>
</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="&#x41a;&#x432;&#x430;&#x434;&#x440;&#x430;&#x442;&#x43d;&#x44b;&#x439;"/>
<StringItem index="1" value="&#x422;&#x440;&#x435;&#x443;&#x433;&#x43e;&#x43b;&#x44c;&#x43d;&#x44b;&#x439;"/>
<StringItem index="2" value="&#x41a;&#x440;&#x443;&#x433;&#x43b;&#x44b;&#x439;"/>
</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="&lt;String&gt;"/>
</AuxValues>
</Component>
<Component class="javax.swing.JLabel" name="jLabelEngines1">
<Properties>
<Property name="text" type="java.lang.String" value="&#x422;&#x438;&#x43f; &#x434;&#x432;&#x438;&#x433;&#x430;&#x442;&#x435;&#x43b;&#x435;&#x439;: "/>
</Properties>
</Component>
</SubComponents>
</Form>

View 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
}

View 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++;
}
}
}
}
}

View 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++;
}
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 565 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 612 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 619 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 546 B