Compare commits
20 Commits
master
...
cd2b9474d4
Author | SHA1 | Date | |
---|---|---|---|
cd2b9474d4 | |||
bea4da357c | |||
a5112dcbdd | |||
b481b124a8 | |||
675c220c79 | |||
fb4c5f3416 | |||
1ef0f5465b | |||
fbd46924d1 | |||
0abd2c2ca3 | |||
7758a3b7cc | |||
a2e79b08bd | |||
0df20f4008 | |||
ed422215f0 | |||
6840f8220e | |||
f990882127 | |||
4e7db63b49 | |||
145d4dac45 | |||
e890502041 | |||
0e85f72177 | |||
02566d7957 |
103
AbstractMap.java
Normal file
103
AbstractMap.java
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
import java.awt.*;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public abstract class AbstractMap {
|
||||||
|
private IDrawingObject _drawingObject = null;
|
||||||
|
protected int[][] _map = null;
|
||||||
|
protected int _width;
|
||||||
|
protected int _height;
|
||||||
|
protected float _size_x;
|
||||||
|
protected float _size_y;
|
||||||
|
protected final Random _random = new Random();
|
||||||
|
protected final int _freeRoad = 0;
|
||||||
|
protected final int _barrier = 1;
|
||||||
|
|
||||||
|
public Image createMap(int width, int height, IDrawingObject drawingObject) {
|
||||||
|
_width = width;
|
||||||
|
_height = height;
|
||||||
|
_drawingObject = drawingObject;
|
||||||
|
do {
|
||||||
|
generateMap();
|
||||||
|
} while (!setObjectOnMap());
|
||||||
|
return drawMapWithObject();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Image moveObject(Direction direction) {
|
||||||
|
_drawingObject.moveObject(direction);
|
||||||
|
if (objectIntersects()) {
|
||||||
|
switch (direction) {
|
||||||
|
case Left -> _drawingObject.moveObject(Direction.Right);
|
||||||
|
case Right -> _drawingObject.moveObject(Direction.Left);
|
||||||
|
case Up -> _drawingObject.moveObject(Direction.Down);
|
||||||
|
case Down -> _drawingObject.moveObject(Direction.Up);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return drawMapWithObject();
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean setObjectOnMap() {
|
||||||
|
if (_drawingObject == null || _map == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 2; i < _map.length; i++)
|
||||||
|
{
|
||||||
|
for (int j = 2; j < _map[i].length; j++)
|
||||||
|
{
|
||||||
|
_drawingObject.setObject((int) (i * _size_x), (int) (j * _size_y), _width, _height);
|
||||||
|
if (!objectIntersects()) return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean objectIntersects() {
|
||||||
|
float[] location = _drawingObject.getCurrentPosition();
|
||||||
|
Rectangle self = new Rectangle((int) location[0], (int) location[2], (int) location[1] - (int) location[0], (int) location[3] - (int) location[2]);
|
||||||
|
for (int i = 0; i < _map.length; i++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < _map[i].length; j++)
|
||||||
|
{
|
||||||
|
if (_map[i][j] == _barrier)
|
||||||
|
{
|
||||||
|
if (self.intersects(new Rectangle(j * (int) _size_x, i * (int) _size_y, (int) _size_x, (int) _size_y)))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Image drawMapWithObject() {
|
||||||
|
Image img = new BufferedImage(_width, _height, BufferedImage.TYPE_INT_ARGB);
|
||||||
|
if (_drawingObject == null || _map == null) {
|
||||||
|
return img;
|
||||||
|
}
|
||||||
|
Graphics2D g = (Graphics2D) img.getGraphics();
|
||||||
|
for (int i = 0; i < _map.length; ++i)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < _map[i].length; ++j)
|
||||||
|
{
|
||||||
|
if (_map[i][j] == _freeRoad)
|
||||||
|
{
|
||||||
|
drawRoadPart(g, i, j);
|
||||||
|
} else if (_map[i][j] == _barrier)
|
||||||
|
{
|
||||||
|
drawBarrierPart(g, i, j);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_drawingObject.drawingObject(g);
|
||||||
|
return img;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract void generateMap();
|
||||||
|
protected abstract void drawRoadPart(Graphics2D g, int i, int j);
|
||||||
|
protected abstract void drawBarrierPart(Graphics2D g, int i, int j);
|
||||||
|
}
|
@ -2,5 +2,6 @@ public enum Direction {
|
|||||||
Up,
|
Up,
|
||||||
Down,
|
Down,
|
||||||
Left,
|
Left,
|
||||||
Right
|
Right,
|
||||||
|
None
|
||||||
}
|
}
|
||||||
|
28
DrawingAdvancedArtillery.java
Normal file
28
DrawingAdvancedArtillery.java
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class DrawingAdvancedArtillery extends DrawingArtillery {
|
||||||
|
public DrawingAdvancedArtillery(int speed, float weight, Color bodyColor, int rollersCount, Color dopColor, boolean weapon, boolean salvoBattery) {
|
||||||
|
super(speed, weight, bodyColor, rollersCount, 80, 50);
|
||||||
|
artillery = new EntityAdvancedArtillery(speed, weight, bodyColor, dopColor, weapon, salvoBattery);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void drawTransport(Graphics2D g) {
|
||||||
|
if (!(artillery instanceof EntityAdvancedArtillery advancedArtillery)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
g.setColor(advancedArtillery.getDopColor());
|
||||||
|
if (advancedArtillery.getWeapon()) {
|
||||||
|
g.setStroke(new BasicStroke(8));
|
||||||
|
g.drawLine((int) _startPosX + _artilleryWidth / 2, (int) _startPosY + _artilleryHeight / 10, (int) _startPosX + _artilleryWidth, (int) _startPosY);
|
||||||
|
}
|
||||||
|
g.setStroke(new BasicStroke(6));
|
||||||
|
if (advancedArtillery.getSalvoBattery()) {
|
||||||
|
g.drawLine((int) _startPosX + _artilleryWidth / 4, (int) _startPosY + _artilleryHeight / 4, (int) _startPosX + _artilleryWidth / 4 + _artilleryHeight / 4, (int) _startPosY - 5);
|
||||||
|
g.drawLine((int) _startPosX + _artilleryWidth / 4 - _artilleryHeight / 4, (int) _startPosY + _artilleryHeight / 4, (int) _startPosX + _artilleryWidth / 4, (int) _startPosY - 5);
|
||||||
|
g.drawLine((int) _startPosX + _artilleryWidth / 4 - _artilleryHeight / 2, (int) _startPosY + _artilleryHeight / 4, (int) _startPosX + _artilleryWidth / 4 - _artilleryHeight / 4, (int) _startPosY - 5);
|
||||||
|
}
|
||||||
|
super.drawTransport(g);
|
||||||
|
}
|
||||||
|
}
|
@ -1,27 +1,31 @@
|
|||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
|
||||||
public class DrawingArtillery {
|
public class DrawingArtillery {
|
||||||
private EntityArtillery artillery;
|
protected EntityArtillery artillery;
|
||||||
private DrawingRollers drawingRollers;
|
protected IDrawingRollers drawingRollers;
|
||||||
private float _startPosX;
|
protected float _startPosX;
|
||||||
private float _startPosY;
|
protected float _startPosY;
|
||||||
private Integer _pictureWidth = null;
|
private Integer _pictureWidth = null;
|
||||||
private Integer _pictureHeight = null;
|
private Integer _pictureHeight = null;
|
||||||
private final int _artilleryWidth = 80;
|
protected int _artilleryWidth = 80;
|
||||||
private final int _artilleryHeight = 50;
|
protected int _artilleryHeight = 50;
|
||||||
|
|
||||||
public EntityArtillery getArtillery() {
|
public EntityArtillery getArtillery() {
|
||||||
return artillery;
|
return artillery;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Init(int speed, float weight, Color bodyColor, int rollersCount) {
|
public DrawingArtillery(int speed, float weight, Color bodyColor, int rollersCount) {
|
||||||
artillery = new EntityArtillery();
|
artillery = new EntityArtillery(speed, weight, bodyColor);
|
||||||
artillery.Init(speed, weight, bodyColor);
|
drawingRollers = RollersType.random(rollersCount, bodyColor);
|
||||||
drawingRollers = new DrawingRollers();
|
|
||||||
drawingRollers.Init(rollersCount, bodyColor);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetPosition(int x, int y, int width, int height) {
|
protected DrawingArtillery(int speed, float weight, Color bodyColor, int rollersCount, int artilleryWidth, int artilleryHeight) {
|
||||||
|
this(speed, weight, bodyColor, rollersCount);
|
||||||
|
_artilleryWidth = artilleryWidth;
|
||||||
|
_artilleryHeight = artilleryHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPosition(int x, int y, int width, int height) {
|
||||||
if (x < 0 || x + _artilleryWidth >= width)
|
if (x < 0 || x + _artilleryWidth >= width)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
@ -82,7 +86,7 @@ public class DrawingArtillery {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
g.setColor(artillery.getBodyColor() != null ? artillery.getBodyColor() : Color.BLACK);
|
g.setColor(artillery.getBodyColor() != null ? artillery.getBodyColor() : Color.BLACK);
|
||||||
g.fillRect((int) (_startPosX + _artilleryWidth / 8 * 2), (int) _startPosY, _artilleryWidth / 8 * 4, _artilleryWidth / 5);
|
g.fillRect((int) (_startPosX + _artilleryWidth / 8 * 2), (int) _startPosY, _artilleryWidth / 8 * 4, _artilleryHeight / 5);
|
||||||
g.fillRect((int) _startPosX, (int) (_startPosY + _artilleryHeight / 5), _artilleryWidth, _artilleryHeight / 3);
|
g.fillRect((int) _startPosX, (int) (_startPosY + _artilleryHeight / 5), _artilleryWidth, _artilleryHeight / 3);
|
||||||
|
|
||||||
|
|
||||||
@ -110,4 +114,8 @@ public class DrawingArtillery {
|
|||||||
_startPosY = _pictureHeight - _artilleryHeight;
|
_startPosY = _pictureHeight - _artilleryHeight;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public float[] getCurrentPosition() {
|
||||||
|
return new float[] { _startPosX, _startPosX + _artilleryWidth - 1, _startPosY, _startPosY + _artilleryHeight -1 };
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
82
DrawingCrossRollers.java
Normal file
82
DrawingCrossRollers.java
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class DrawingCrossRollers implements IDrawingRollers {
|
||||||
|
private RollersCount rollersCount;
|
||||||
|
private Color color;
|
||||||
|
|
||||||
|
public DrawingCrossRollers(int rollersCount, Color bodyColor) {
|
||||||
|
setRollersCount(rollersCount);
|
||||||
|
color = bodyColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRollersCount(int num) {
|
||||||
|
if (num <= 4) {
|
||||||
|
rollersCount = RollersCount.Four;
|
||||||
|
} else if (num >= 6) {
|
||||||
|
rollersCount = RollersCount.Six;
|
||||||
|
} else {
|
||||||
|
rollersCount = RollersCount.Five;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void draw(Graphics2D g, int x, int y, int artilleryWidth, int artilleryHeight) {
|
||||||
|
g.setColor(color != null ? color : Color.BLACK);
|
||||||
|
g.fillOval(x + artilleryWidth / 20, y + artilleryHeight * 7 / 15, artilleryWidth * 4 / 20, artilleryHeight * 10 / 32);
|
||||||
|
g.fillOval(x + artilleryWidth * 15 / 20, y + artilleryHeight * 7 / 15, artilleryWidth * 4 / 20, artilleryHeight * 10 / 32);
|
||||||
|
switch (rollersCount) {
|
||||||
|
case Six: {
|
||||||
|
g.fillOval(x + artilleryWidth * 8 / 20, y + artilleryHeight * 10 / 16, artilleryWidth * 2 / 20, artilleryHeight * 6 / 32);
|
||||||
|
}
|
||||||
|
case Five: {
|
||||||
|
g.fillOval(x + artilleryWidth * 10 / 20, y + artilleryHeight * 10 / 16, artilleryWidth * 2 / 20, artilleryHeight * 6 / 32);
|
||||||
|
}
|
||||||
|
case Four: {
|
||||||
|
g.fillOval(x + artilleryWidth * 5 / 20, y + artilleryHeight * 9 / 16, artilleryWidth * 3 / 20, artilleryHeight * 8 / 32);
|
||||||
|
g.fillOval(x + artilleryWidth * 12 / 20, y + artilleryHeight * 9 / 16, artilleryWidth * 3 / 20, artilleryHeight * 8 / 32);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
drawOrnament(g, x, y, artilleryWidth, artilleryHeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void drawOrnament(Graphics2D g, int x, int y, int artilleryWidth, int artilleryHeight) {
|
||||||
|
g.setStroke(new BasicStroke(1));
|
||||||
|
g.setColor(Color.BLACK);
|
||||||
|
|
||||||
|
|
||||||
|
g.drawLine(x + artilleryWidth / 20, y + artilleryHeight * 7 / 15 + artilleryHeight * 5 / 32, x + artilleryWidth * 5 / 20 - 1, y + artilleryHeight * 7 / 15 + artilleryHeight * 5 / 32);
|
||||||
|
g.drawLine(x + artilleryWidth * 3 / 20, y + artilleryHeight * 7 / 15, x + artilleryWidth * 3 / 20, y + artilleryHeight * 7 / 15 + artilleryHeight * 10 / 32);
|
||||||
|
g.drawLine(x + artilleryWidth * 2 / 20, y + artilleryHeight * 7 / 15 + artilleryHeight * 5 / 64, x + artilleryWidth * 4 / 20, y + artilleryHeight * 7 / 15 + artilleryHeight * 15 / 64);
|
||||||
|
g.drawLine(x + artilleryWidth * 4 / 20, y + artilleryHeight * 7 / 15 + artilleryHeight * 5 / 64, x + artilleryWidth * 2 / 20, y + artilleryHeight * 7 / 15 + artilleryHeight * 15 / 64);
|
||||||
|
|
||||||
|
g.drawLine(x + artilleryWidth * 15 / 20, y + artilleryHeight * 7 / 15 + artilleryHeight * 5 / 32, x + artilleryWidth * 19 / 20 - 1, y + artilleryHeight * 7 / 15 + artilleryHeight * 5 / 32);
|
||||||
|
g.drawLine(x + artilleryWidth * 17 / 20, y + artilleryHeight * 7 / 15, x + artilleryWidth * 17 / 20, y + artilleryHeight * 7 / 15 + artilleryHeight * 10 / 32);
|
||||||
|
g.drawLine(x + artilleryWidth * 16 / 20, y + artilleryHeight * 7 / 15 + artilleryHeight * 5 / 64, x + artilleryWidth * 18 / 20, y + artilleryHeight * 7 / 15 + artilleryHeight * 15 / 64);
|
||||||
|
g.drawLine(x + artilleryWidth * 18 / 20, y + artilleryHeight * 7 / 15 + artilleryHeight * 5 / 64, x + artilleryWidth * 16 / 20, y + artilleryHeight * 7 / 15 + artilleryHeight * 15 / 64);
|
||||||
|
|
||||||
|
switch(rollersCount) {
|
||||||
|
case Six: {
|
||||||
|
g.drawLine(x + artilleryWidth * 8 / 20, y + artilleryHeight * 10 / 16 + artilleryHeight * 3 / 32, x + artilleryWidth * 10 / 20, y + artilleryHeight * 10 / 16 + artilleryHeight * 3 / 32);
|
||||||
|
g.drawLine(x + artilleryWidth * 9 / 20, y + artilleryHeight * 10 / 16, x + artilleryWidth * 9 / 20, y + artilleryHeight * 10 / 16 + artilleryHeight * 6 / 32);
|
||||||
|
g.drawLine(x + artilleryWidth * 8 / 20 + artilleryWidth * 2 / 80, y + artilleryHeight * 10 / 16 + artilleryHeight * 3 / 32 - artilleryHeight * 3 / 64, x + artilleryWidth * 10 / 20 - artilleryWidth * 2 / 80, y + artilleryHeight * 10 / 16 + artilleryHeight * 3 / 32 + artilleryHeight * 3 / 64);
|
||||||
|
g.drawLine(x + artilleryWidth * 9 / 20 + artilleryWidth * 2 / 80, y + artilleryHeight * 10 / 16 + artilleryHeight * 3 / 32 - artilleryHeight * 3 / 64, x + artilleryWidth * 8 / 20 + artilleryWidth * 2 / 80, y + artilleryHeight * 10 / 16 + artilleryHeight * 3 / 32 + artilleryHeight * 3 / 64);
|
||||||
|
}
|
||||||
|
case Five: {
|
||||||
|
g.drawLine(x + artilleryWidth * 10 / 20, y + artilleryHeight * 10 / 16 + artilleryHeight * 3 / 32, x + artilleryWidth * 12 / 20, y + artilleryHeight * 10 / 16 + artilleryHeight * 3 / 32);
|
||||||
|
g.drawLine(x + artilleryWidth * 11 / 20, y + artilleryHeight * 10 / 16, x + artilleryWidth * 11 / 20, y + artilleryHeight * 10 / 16 + artilleryHeight * 6 / 32);
|
||||||
|
g.drawLine(x + artilleryWidth * 12 / 20 + artilleryWidth * 2 / 80, y + artilleryHeight * 10 / 16 + artilleryHeight * 3 / 32 - artilleryHeight * 3 / 64, x + artilleryWidth * 12 / 20 - artilleryWidth * 2 / 80, y + artilleryHeight * 10 / 16 + artilleryHeight * 3 / 32 + artilleryHeight * 3 / 64);
|
||||||
|
g.drawLine(x + artilleryWidth * 11 / 20 + artilleryWidth * 2 / 80, y + artilleryHeight * 10 / 16 + artilleryHeight * 3 / 32 - artilleryHeight * 3 / 64, x + artilleryWidth * 10 / 20 + artilleryWidth * 2 / 80, y + artilleryHeight * 10 / 16 + artilleryHeight * 3 / 32 + artilleryHeight * 3 / 64);
|
||||||
|
}
|
||||||
|
case Four: {
|
||||||
|
g.drawLine(x + artilleryWidth * 5 / 20, y + artilleryHeight * 9 / 16 + artilleryHeight * 4 / 32, x + artilleryWidth * 5 / 20 + artilleryWidth * 3 / 20, y + artilleryHeight * 9 / 16 + artilleryHeight * 4 / 32);
|
||||||
|
g.drawLine(x + artilleryWidth * 5 / 20 + artilleryWidth * 3 / 40, y + artilleryHeight * 9 / 16, x + artilleryWidth * 5 / 20 + artilleryWidth * 3 / 40, y + artilleryHeight * 9 / 16 + artilleryHeight * 8 / 32);
|
||||||
|
g.drawLine(x + artilleryWidth * 5 / 20 + artilleryWidth * 3 / 80, y + artilleryHeight * 9 / 16 + artilleryHeight * 2 / 32, x + artilleryWidth * 5 / 20 + artilleryWidth * 9 / 80, y + artilleryHeight * 9 / 16 + artilleryHeight * 6 / 32);
|
||||||
|
g.drawLine(x + artilleryWidth * 5 / 20 + artilleryWidth * 9 / 80, y + artilleryHeight * 9 / 16 + artilleryHeight * 2 / 32, x + artilleryWidth * 5 / 20 + artilleryWidth * 3 / 80, y + artilleryHeight * 9 / 16 + artilleryHeight * 6 / 32);
|
||||||
|
|
||||||
|
g.drawLine(x + artilleryWidth * 12 / 20, y + artilleryHeight * 9 / 16 + artilleryHeight * 4 / 32, x + artilleryWidth * 12 / 20 + artilleryWidth * 3 / 20, y + artilleryHeight * 9 / 16 + artilleryHeight * 4 / 32);
|
||||||
|
g.drawLine(x + artilleryWidth * 12 / 20 + artilleryWidth * 3 / 40, y + artilleryHeight * 9 / 16, x + artilleryWidth * 12 / 20 + artilleryWidth * 3 / 40, y + artilleryHeight * 9 / 16 + artilleryHeight * 8 / 32);
|
||||||
|
g.drawLine(x + artilleryWidth * 12 / 20 + artilleryWidth * 3 / 80, y + artilleryHeight * 9 / 16 + artilleryHeight * 2 / 32, x + artilleryWidth * 12 / 20 + artilleryWidth * 9 / 80, y + artilleryHeight * 9 / 16 + artilleryHeight * 6 / 32);
|
||||||
|
g.drawLine(x + artilleryWidth * 12 / 20 + artilleryWidth * 9 / 80, y + artilleryHeight * 9 / 16 + artilleryHeight * 2 / 32, x + artilleryWidth * 12 / 20 + artilleryWidth * 3 / 80, y + artilleryHeight * 9 / 16 + artilleryHeight * 6 / 32);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
37
DrawingObjectArtillery.java
Normal file
37
DrawingObjectArtillery.java
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class DrawingObjectArtillery implements IDrawingObject {
|
||||||
|
private DrawingArtillery _artillery = null;
|
||||||
|
|
||||||
|
public DrawingObjectArtillery(DrawingArtillery artillery) {
|
||||||
|
_artillery = artillery;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getStep() {
|
||||||
|
if (_artillery != null && _artillery.artillery != null) {
|
||||||
|
return _artillery.artillery.getStep();
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float[] getCurrentPosition() {
|
||||||
|
if (_artillery != null) {
|
||||||
|
return _artillery.getCurrentPosition();
|
||||||
|
}
|
||||||
|
return new float[] { 0, 0, 0, 0 };
|
||||||
|
}
|
||||||
|
|
||||||
|
public void moveObject(Direction direction) {
|
||||||
|
if (_artillery != null) {
|
||||||
|
_artillery.moveTransport(direction);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setObject(int x, int y, int width, int height) {
|
||||||
|
_artillery.setPosition(x, y, width, height);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void drawingObject(Graphics2D g) {
|
||||||
|
_artillery.drawTransport(g);
|
||||||
|
}
|
||||||
|
}
|
@ -1,10 +1,10 @@
|
|||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
|
||||||
public class DrawingRollers {
|
public class DrawingRollers implements IDrawingRollers {
|
||||||
private RollersCount rollersCount;
|
private RollersCount rollersCount;
|
||||||
private Color color;
|
private Color color;
|
||||||
|
|
||||||
public void Init(int rollersCount, Color bodyColor) {
|
public DrawingRollers(int rollersCount, Color bodyColor) {
|
||||||
setRollersCount(rollersCount);
|
setRollersCount(rollersCount);
|
||||||
color = bodyColor;
|
color = bodyColor;
|
||||||
}
|
}
|
||||||
|
107
DrawingSquaredRollers.java
Normal file
107
DrawingSquaredRollers.java
Normal file
@ -0,0 +1,107 @@
|
|||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class DrawingSquaredRollers implements IDrawingRollers {
|
||||||
|
private RollersCount rollersCount;
|
||||||
|
private Color color;
|
||||||
|
|
||||||
|
public DrawingSquaredRollers(int rollersCount, Color bodyColor) {
|
||||||
|
setRollersCount(rollersCount);
|
||||||
|
color = bodyColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRollersCount(int num) {
|
||||||
|
if (num <= 4) {
|
||||||
|
rollersCount = RollersCount.Four;
|
||||||
|
} else if (num >= 6) {
|
||||||
|
rollersCount = RollersCount.Six;
|
||||||
|
} else {
|
||||||
|
rollersCount = RollersCount.Five;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void draw(Graphics2D g, int x, int y, int artilleryWidth, int artilleryHeight) {
|
||||||
|
g.setColor(color != null ? color : Color.BLACK);
|
||||||
|
g.fillOval(x + artilleryWidth / 20, y + artilleryHeight * 7 / 15, artilleryWidth * 4 / 20, artilleryHeight * 10 / 32);
|
||||||
|
g.fillOval(x + artilleryWidth * 15 / 20, y + artilleryHeight * 7 / 15, artilleryWidth * 4 / 20, artilleryHeight * 10 / 32);
|
||||||
|
switch (rollersCount) {
|
||||||
|
case Six: {
|
||||||
|
g.fillOval(x + artilleryWidth * 8 / 20, y + artilleryHeight * 10 / 16, artilleryWidth * 2 / 20, artilleryHeight * 6 / 32);
|
||||||
|
}
|
||||||
|
case Five: {
|
||||||
|
g.fillOval(x + artilleryWidth * 10 / 20, y + artilleryHeight * 10 / 16, artilleryWidth * 2 / 20, artilleryHeight * 6 / 32);
|
||||||
|
}
|
||||||
|
case Four: {
|
||||||
|
g.fillOval(x + artilleryWidth * 5 / 20, y + artilleryHeight * 9 / 16, artilleryWidth * 3 / 20, artilleryHeight * 8 / 32);
|
||||||
|
g.fillOval(x + artilleryWidth * 12 / 20, y + artilleryHeight * 9 / 16, artilleryWidth * 3 / 20, artilleryHeight * 8 / 32);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
drawOrnament(g, x, y, artilleryWidth, artilleryHeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void drawOrnament(Graphics2D g, int x, int y, int artilleryWidth, int artilleryHeight) {
|
||||||
|
g.setStroke(new BasicStroke(1));
|
||||||
|
g.setColor(Color.BLACK);
|
||||||
|
|
||||||
|
Polygon bigRollerFirstPattern = new Polygon();
|
||||||
|
bigRollerFirstPattern.addPoint(x + artilleryWidth / 20 + 1, y + artilleryHeight * 7 / 15 + artilleryHeight * 5 / 32);
|
||||||
|
bigRollerFirstPattern.addPoint(x + artilleryWidth * 3 / 20, y + artilleryHeight * 7 / 15 + 1);
|
||||||
|
bigRollerFirstPattern.addPoint(x + artilleryWidth * 5 / 20 - 1, y + artilleryHeight * 7 / 15 + artilleryHeight * 5 / 32);
|
||||||
|
bigRollerFirstPattern.addPoint(x + artilleryWidth * 3 / 20, y + artilleryHeight * 7 / 15 + artilleryHeight * 10 / 32 - 1);
|
||||||
|
g.drawPolygon(bigRollerFirstPattern);
|
||||||
|
bigRollerFirstPattern.translate(artilleryWidth * 14 / 20, 0);
|
||||||
|
g.drawPolygon(bigRollerFirstPattern);
|
||||||
|
|
||||||
|
Polygon bigRollerSecondPattern = new Polygon();
|
||||||
|
bigRollerSecondPattern.addPoint(x + artilleryWidth * 2 / 20, y + artilleryHeight * 7 / 15 + artilleryHeight * 5 / 64);
|
||||||
|
bigRollerSecondPattern.addPoint(x + artilleryWidth * 4 / 20, y + artilleryHeight * 7 / 15 + artilleryHeight * 5 / 64);
|
||||||
|
bigRollerSecondPattern.addPoint(x + artilleryWidth * 4 / 20, y + artilleryHeight * 7 / 15 + artilleryHeight * 15 / 64);
|
||||||
|
bigRollerSecondPattern.addPoint(x + artilleryWidth * 2 / 20, y + artilleryHeight * 7 / 15 + artilleryHeight * 15 / 64);
|
||||||
|
g.drawPolygon(bigRollerSecondPattern);
|
||||||
|
bigRollerSecondPattern.translate(artilleryWidth * 14 / 20, 0);
|
||||||
|
g.drawPolygon(bigRollerSecondPattern);
|
||||||
|
|
||||||
|
Polygon smallRollerFirstPattern = new Polygon();
|
||||||
|
smallRollerFirstPattern.addPoint(x + artilleryWidth * 8 / 20, y + artilleryHeight * 10 / 16 + artilleryHeight * 3 / 32);
|
||||||
|
smallRollerFirstPattern.addPoint(x + artilleryWidth * 9 / 20, y + artilleryHeight * 10 / 16);
|
||||||
|
smallRollerFirstPattern.addPoint(x + artilleryWidth * 10 / 20, y + artilleryHeight * 10 / 16 + artilleryHeight * 3 / 32);
|
||||||
|
smallRollerFirstPattern.addPoint(x + artilleryWidth * 9 / 20, y + artilleryHeight * 10 / 16 + artilleryHeight * 6 / 32);
|
||||||
|
|
||||||
|
Polygon smallRollerSecondPattern = new Polygon();
|
||||||
|
smallRollerSecondPattern.addPoint(x + artilleryWidth * 8 / 20 + artilleryWidth * 2 / 80, y + artilleryHeight * 10 / 16 + artilleryHeight * 3 / 32 - artilleryHeight * 3 / 64);
|
||||||
|
smallRollerSecondPattern.addPoint(x + artilleryWidth * 9 / 20 + artilleryWidth * 2 / 80, y + artilleryHeight * 10 / 16 + artilleryHeight * 3 / 32 - artilleryHeight * 3 / 64);
|
||||||
|
smallRollerSecondPattern.addPoint(x + artilleryWidth * 10 / 20 - artilleryWidth * 2 / 80, y + artilleryHeight * 10 / 16 + artilleryHeight * 3 / 32 + artilleryHeight * 3 / 64);
|
||||||
|
smallRollerSecondPattern.addPoint(x + artilleryWidth * 8 / 20 + artilleryWidth * 2 / 80, y + artilleryHeight * 10 / 16 + artilleryHeight * 3 / 32 + artilleryHeight * 3 / 64);
|
||||||
|
|
||||||
|
switch(rollersCount) {
|
||||||
|
case Six: {
|
||||||
|
g.drawPolygon(smallRollerFirstPattern);
|
||||||
|
g.drawPolygon(smallRollerSecondPattern);
|
||||||
|
}
|
||||||
|
case Five: {
|
||||||
|
smallRollerFirstPattern.translate(artilleryWidth * 2 / 20, 0);
|
||||||
|
smallRollerSecondPattern.translate(artilleryWidth * 2 / 20, 0);
|
||||||
|
g.drawPolygon(smallRollerFirstPattern);
|
||||||
|
g.drawPolygon(smallRollerSecondPattern);
|
||||||
|
}
|
||||||
|
case Four: {
|
||||||
|
Polygon mediumRollerFirstPattern = new Polygon();
|
||||||
|
mediumRollerFirstPattern.addPoint(x + artilleryWidth * 5 / 20, y + artilleryHeight * 9 / 16 + artilleryHeight * 4 / 32);
|
||||||
|
mediumRollerFirstPattern.addPoint(x + artilleryWidth * 5 / 20 + artilleryWidth * 3 / 40, y + artilleryHeight * 9 / 16);
|
||||||
|
mediumRollerFirstPattern.addPoint(x + artilleryWidth * 5 / 20 + artilleryWidth * 3 / 20, y + artilleryHeight * 9 / 16 + artilleryHeight * 4 / 32);
|
||||||
|
mediumRollerFirstPattern.addPoint(x + artilleryWidth * 5 / 20 + artilleryWidth * 3 / 40, y + artilleryHeight * 9 / 16 + artilleryHeight * 8 / 32);
|
||||||
|
g.drawPolygon(mediumRollerFirstPattern);
|
||||||
|
mediumRollerFirstPattern.translate(artilleryWidth * 7 / 20, 0);
|
||||||
|
g.drawPolygon(mediumRollerFirstPattern);
|
||||||
|
|
||||||
|
Polygon mediumRollerSecondPattern = new Polygon();
|
||||||
|
mediumRollerSecondPattern.addPoint(x + artilleryWidth * 5 / 20 + artilleryWidth * 3 / 80, y + artilleryHeight * 9 / 16 + artilleryHeight * 2 / 32);
|
||||||
|
mediumRollerSecondPattern.addPoint(x + artilleryWidth * 5 / 20 + artilleryWidth * 9 / 80, y + artilleryHeight * 9 / 16 + artilleryHeight * 2 / 32);
|
||||||
|
mediumRollerSecondPattern.addPoint(x + artilleryWidth * 5 / 20 + artilleryWidth * 9 / 80, y + artilleryHeight * 9 / 16 + artilleryHeight * 6 / 32);
|
||||||
|
mediumRollerSecondPattern.addPoint(x + artilleryWidth * 5 / 20 + artilleryWidth * 3 / 80, y + artilleryHeight * 9 / 16 + artilleryHeight * 6 / 32);
|
||||||
|
g.drawPolygon(mediumRollerSecondPattern);
|
||||||
|
mediumRollerSecondPattern.translate(artilleryWidth * 7 / 20, 0);
|
||||||
|
g.drawPolygon(mediumRollerSecondPattern);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
26
EntityAdvancedArtillery.java
Normal file
26
EntityAdvancedArtillery.java
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class EntityAdvancedArtillery extends EntityArtillery {
|
||||||
|
private Color dopColor;
|
||||||
|
private boolean weapon;
|
||||||
|
private boolean salvoBattery;
|
||||||
|
|
||||||
|
public EntityAdvancedArtillery(int speed, float weight, Color bodyColor, Color dopColor, boolean weapon, boolean salvoBattery) {
|
||||||
|
super(speed, weight, bodyColor);
|
||||||
|
this.dopColor = dopColor;
|
||||||
|
this.weapon = weapon;
|
||||||
|
this.salvoBattery = salvoBattery;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Color getDopColor() {
|
||||||
|
return dopColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getWeapon() {
|
||||||
|
return weapon;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getSalvoBattery() {
|
||||||
|
return salvoBattery;
|
||||||
|
}
|
||||||
|
}
|
@ -6,7 +6,7 @@ public class EntityArtillery {
|
|||||||
private float weight;
|
private float weight;
|
||||||
private Color bodyColor;
|
private Color bodyColor;
|
||||||
|
|
||||||
public void Init(int speed, float weight, Color bodyColor) {
|
public EntityArtillery(int speed, float weight, Color bodyColor) {
|
||||||
Random rnd = new Random();
|
Random rnd = new Random();
|
||||||
this.speed = speed <= 0 ? rnd.nextInt(50, 150) : speed;
|
this.speed = speed <= 0 ? rnd.nextInt(50, 150) : speed;
|
||||||
this.weight = weight <= 0 ? rnd.nextInt(40, 70) : weight;
|
this.weight = weight <= 0 ? rnd.nextInt(40, 70) : weight;
|
||||||
|
49
ForestMap.java
Normal file
49
ForestMap.java
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
import java.awt.*;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class ForestMap extends AbstractMap {
|
||||||
|
private final Color barrierColor = Color.green;
|
||||||
|
private final Color roadColor = new Color(165, 42, 42, 255);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void drawBarrierPart(Graphics2D g, int i, int j)
|
||||||
|
{
|
||||||
|
g.setColor(barrierColor);
|
||||||
|
g.fillRect(j * (int) _size_x, i * (int) _size_y, (int) _size_x, (int) _size_y);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void drawRoadPart(Graphics2D g, int i, int j)
|
||||||
|
{
|
||||||
|
g.setColor(roadColor);
|
||||||
|
g.fillRect(j * (int) _size_x, i * (int) _size_y, (int) _size_x, (int) _size_y);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void generateMap() {
|
||||||
|
_map = new int[50][50];
|
||||||
|
_size_x = (float)_width / _map[0].length;
|
||||||
|
_size_y = (float)_height / _map.length;
|
||||||
|
int counter = 0;
|
||||||
|
for (int[] row : _map) {
|
||||||
|
Arrays.fill(row, _freeRoad);
|
||||||
|
}
|
||||||
|
while (counter < 20)
|
||||||
|
{
|
||||||
|
int x = _random.nextInt(2, 49);
|
||||||
|
int y = _random.nextInt(3, 50);
|
||||||
|
var points = new int[] { _map[y][x], _map[y - 1][x], _map[y - 2][x], _map[y - 2][x - 1], _map[y - 2][x + 1], _map[y - 3][x] };
|
||||||
|
var forComparison = new int[] { _freeRoad, _freeRoad, _freeRoad, _freeRoad, _freeRoad, _freeRoad };
|
||||||
|
if (Arrays.equals(points, forComparison))
|
||||||
|
{
|
||||||
|
_map[y][x] = _barrier;
|
||||||
|
_map[y - 1][x] = _barrier;
|
||||||
|
_map[y - 2][x] = _barrier;
|
||||||
|
_map[y - 2][x - 1] = _barrier;
|
||||||
|
_map[y - 2][x + 1] = _barrier;
|
||||||
|
_map[y - 3][x] = _barrier;
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -53,7 +53,7 @@
|
|||||||
</component>
|
</component>
|
||||||
</children>
|
</children>
|
||||||
</grid>
|
</grid>
|
||||||
<grid id="fa947" binding="pictureBox" layout-manager="GridLayoutManager" row-count="3" column-count="6" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
<grid id="fa947" binding="pictureBox" layout-manager="GridLayoutManager" row-count="3" column-count="8" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||||
<margin top="0" left="0" bottom="0" right="0"/>
|
<margin top="0" left="0" bottom="0" right="0"/>
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||||
@ -61,11 +61,6 @@
|
|||||||
<properties/>
|
<properties/>
|
||||||
<border type="none"/>
|
<border type="none"/>
|
||||||
<children>
|
<children>
|
||||||
<hspacer id="f89d0">
|
|
||||||
<constraints>
|
|
||||||
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
</hspacer>
|
|
||||||
<vspacer id="402e3">
|
<vspacer id="402e3">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||||
@ -73,12 +68,12 @@
|
|||||||
</vspacer>
|
</vspacer>
|
||||||
<vspacer id="bbd8c">
|
<vspacer id="bbd8c">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
<grid row="0" column="3" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||||
</constraints>
|
</constraints>
|
||||||
</vspacer>
|
</vspacer>
|
||||||
<component id="271ef" class="javax.swing.JButton" binding="buttonUp">
|
<component id="271ef" class="javax.swing.JButton" binding="buttonUp">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="1" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
<grid row="1" column="6" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||||
<minimum-size width="30" height="30"/>
|
<minimum-size width="30" height="30"/>
|
||||||
<preferred-size width="30" height="30"/>
|
<preferred-size width="30" height="30"/>
|
||||||
<maximum-size width="30" height="30"/>
|
<maximum-size width="30" height="30"/>
|
||||||
@ -93,7 +88,7 @@
|
|||||||
</component>
|
</component>
|
||||||
<component id="4b967" class="javax.swing.JButton" binding="buttonDown">
|
<component id="4b967" class="javax.swing.JButton" binding="buttonDown">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="2" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
<grid row="2" column="6" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||||
<minimum-size width="30" height="30"/>
|
<minimum-size width="30" height="30"/>
|
||||||
<preferred-size width="30" height="30"/>
|
<preferred-size width="30" height="30"/>
|
||||||
<maximum-size width="30" height="30"/>
|
<maximum-size width="30" height="30"/>
|
||||||
@ -107,7 +102,7 @@
|
|||||||
</component>
|
</component>
|
||||||
<component id="2e663" class="javax.swing.JButton" binding="buttonLeft">
|
<component id="2e663" class="javax.swing.JButton" binding="buttonLeft">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="2" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
<grid row="2" column="5" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||||
<minimum-size width="30" height="30"/>
|
<minimum-size width="30" height="30"/>
|
||||||
<preferred-size width="30" height="30"/>
|
<preferred-size width="30" height="30"/>
|
||||||
<maximum-size width="30" height="30"/>
|
<maximum-size width="30" height="30"/>
|
||||||
@ -122,7 +117,7 @@
|
|||||||
</component>
|
</component>
|
||||||
<component id="c2d76" class="javax.swing.JButton" binding="buttonRight">
|
<component id="c2d76" class="javax.swing.JButton" binding="buttonRight">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="2" column="5" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
<grid row="2" column="7" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||||
<minimum-size width="30" height="30"/>
|
<minimum-size width="30" height="30"/>
|
||||||
<preferred-size width="30" height="30"/>
|
<preferred-size width="30" height="30"/>
|
||||||
<maximum-size width="30" height="30"/>
|
<maximum-size width="30" height="30"/>
|
||||||
@ -137,7 +132,7 @@
|
|||||||
</component>
|
</component>
|
||||||
<component id="7bc68" class="javax.swing.JButton" binding="createButton">
|
<component id="7bc68" class="javax.swing.JButton" binding="createButton">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="2" fill="1" indent="0" use-parent-layout="false"/>
|
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
</constraints>
|
</constraints>
|
||||||
<properties>
|
<properties>
|
||||||
<alignmentX value="0.0"/>
|
<alignmentX value="0.0"/>
|
||||||
@ -145,6 +140,27 @@
|
|||||||
<text value="Создать"/>
|
<text value="Создать"/>
|
||||||
</properties>
|
</properties>
|
||||||
</component>
|
</component>
|
||||||
|
<component id="27408" class="javax.swing.JButton" binding="createAdvancedButton">
|
||||||
|
<constraints>
|
||||||
|
<grid row="2" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Модификация"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="d034f" class="javax.swing.JButton" binding="buttonSelect">
|
||||||
|
<constraints>
|
||||||
|
<grid row="2" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Выбрать"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<hspacer id="f89d0">
|
||||||
|
<constraints>
|
||||||
|
<grid row="1" column="3" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
</hspacer>
|
||||||
</children>
|
</children>
|
||||||
</grid>
|
</grid>
|
||||||
</children>
|
</children>
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.ComponentAdapter;
|
import java.awt.event.*;
|
||||||
import java.awt.event.ComponentEvent;
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
public class FormArtillery extends JFrame {
|
public class FormArtillery extends JDialog {
|
||||||
private JPanel artilleryPane;
|
private JPanel artilleryPane;
|
||||||
private JLabel speedLabel;
|
private JLabel speedLabel;
|
||||||
private JLabel weightLabel;
|
private JLabel weightLabel;
|
||||||
@ -15,25 +14,23 @@ public class FormArtillery extends JFrame {
|
|||||||
private JButton buttonDown;
|
private JButton buttonDown;
|
||||||
private JButton buttonLeft;
|
private JButton buttonLeft;
|
||||||
private JButton buttonRight;
|
private JButton buttonRight;
|
||||||
|
private JButton createAdvancedButton;
|
||||||
|
public JButton buttonSelect;
|
||||||
|
|
||||||
private DrawingArtillery _artillery;
|
private DrawingArtillery _artillery;
|
||||||
|
private DrawingArtillery selectedArtillery;
|
||||||
|
|
||||||
public FormArtillery() {
|
public FormArtillery() {
|
||||||
this.setTitle("Artillery");
|
this.setTitle("Artillery");
|
||||||
this.setContentPane(artilleryPane);
|
this.setContentPane(artilleryPane);
|
||||||
createButton.addActionListener(e -> {
|
createButton.addActionListener(e -> {
|
||||||
Random rnd = new Random();
|
Random rnd = new Random();
|
||||||
_artillery = new DrawingArtillery();
|
Color color = JColorChooser.showDialog(this, "Цвет", new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256)));
|
||||||
_artillery.Init(
|
if (color == null) {
|
||||||
rnd.nextInt(100, 300),
|
color = new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256));
|
||||||
rnd.nextInt(1000, 2000),
|
}
|
||||||
new Color(
|
_artillery = new DrawingArtillery(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000), color, rnd.nextInt(4, 7));
|
||||||
rnd.nextInt(0, 256),
|
_artillery.setPosition(10 + rnd.nextInt(90), 10 + rnd.nextInt(90), pictureBox.getWidth(), pictureBox.getHeight());
|
||||||
rnd.nextInt(0, 256),
|
|
||||||
rnd.nextInt(0, 256)),
|
|
||||||
rnd.nextInt(4, 7)
|
|
||||||
);
|
|
||||||
_artillery.SetPosition(10 + rnd.nextInt(90), 10 + rnd.nextInt(90), pictureBox.getWidth(), pictureBox.getHeight());
|
|
||||||
speedLabel.setText(String.format("Скорость: %s", _artillery.getArtillery().getSpeed()));
|
speedLabel.setText(String.format("Скорость: %s", _artillery.getArtillery().getSpeed()));
|
||||||
weightLabel.setText(String.format("Вес: %s", _artillery.getArtillery().getWeight()));
|
weightLabel.setText(String.format("Вес: %s", _artillery.getArtillery().getWeight()));
|
||||||
colorLabel.setText(String.format("Цвет: %x", _artillery.getArtillery().getBodyColor().getRGB()));
|
colorLabel.setText(String.format("Цвет: %x", _artillery.getArtillery().getBodyColor().getRGB()));
|
||||||
@ -62,12 +59,45 @@ public class FormArtillery extends JFrame {
|
|||||||
if (_artillery != null) _artillery.moveTransport(Direction.Down);
|
if (_artillery != null) _artillery.moveTransport(Direction.Down);
|
||||||
repaint();
|
repaint();
|
||||||
});
|
});
|
||||||
|
createAdvancedButton.addActionListener(e -> {
|
||||||
|
Random rnd = new Random();
|
||||||
|
Color color = JColorChooser.showDialog(this, "Основной цвет", Color.white);
|
||||||
|
if (color == null) {
|
||||||
|
color = new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256));
|
||||||
|
}
|
||||||
|
Color dopColor = JColorChooser.showDialog(this, "Дополнительный цвет", Color.white);
|
||||||
|
if (dopColor == null) {
|
||||||
|
dopColor = new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256));
|
||||||
|
}
|
||||||
|
_artillery = new DrawingAdvancedArtillery(
|
||||||
|
rnd.nextInt(100, 300),
|
||||||
|
rnd.nextInt(1000, 2000),
|
||||||
|
color,
|
||||||
|
rnd.nextInt(4, 7),
|
||||||
|
dopColor,
|
||||||
|
rnd.nextBoolean(),
|
||||||
|
rnd.nextBoolean()
|
||||||
|
);
|
||||||
|
_artillery.setPosition(10 + rnd.nextInt(90), 10 + rnd.nextInt(90), pictureBox.getWidth(), pictureBox.getHeight());
|
||||||
|
speedLabel.setText(String.format("Скорость: %s", _artillery.getArtillery().getSpeed()));
|
||||||
|
weightLabel.setText(String.format("Вес: %s", _artillery.getArtillery().getWeight()));
|
||||||
|
colorLabel.setText(String.format("Цвет: %x", _artillery.getArtillery().getBodyColor().getRGB()));
|
||||||
|
repaint();
|
||||||
|
});
|
||||||
|
buttonSelect.addActionListener(e -> {
|
||||||
|
selectedArtillery = _artillery;
|
||||||
|
dispose();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public DrawingArtillery getSelectedArtillery() {
|
||||||
|
return selectedArtillery;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void paint(Graphics g) {
|
public void paint(Graphics g) {
|
||||||
super.paint(g);
|
super.paint(g);
|
||||||
Graphics2D g2d = (Graphics2D) artilleryPane.getGraphics();
|
Graphics2D g2d = (Graphics2D) pictureBox.getGraphics();
|
||||||
if (_artillery != null) {
|
if (_artillery != null) {
|
||||||
_artillery.drawTransport(g2d);
|
_artillery.drawTransport(g2d);
|
||||||
}
|
}
|
||||||
|
158
FormMap.form
Normal file
158
FormMap.form
Normal file
@ -0,0 +1,158 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormMap">
|
||||||
|
<grid id="27dc6" binding="artilleryPane" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||||
|
<margin top="0" left="0" bottom="0" right="0"/>
|
||||||
|
<constraints>
|
||||||
|
<xy x="20" y="20" width="630" height="420"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<minimumSize width="80" height="50"/>
|
||||||
|
<preferredSize width="640" height="480"/>
|
||||||
|
</properties>
|
||||||
|
<border type="none"/>
|
||||||
|
<children>
|
||||||
|
<grid id="57516" layout-manager="GridLayoutManager" row-count="1" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||||
|
<margin top="0" left="0" bottom="0" right="0"/>
|
||||||
|
<constraints>
|
||||||
|
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children>
|
||||||
|
<component id="dcb7f" class="javax.swing.JLabel" binding="speedLabel">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value=""/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="998a6" class="javax.swing.JLabel" binding="weightLabel">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value=""/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="cffd1" class="javax.swing.JLabel" binding="colorLabel">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value=""/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
<grid id="52641" binding="pictureBox" layout-manager="GridLayoutManager" row-count="4" column-count="6" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||||
|
<margin top="0" left="0" bottom="0" right="0"/>
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children>
|
||||||
|
<component id="6937b" class="javax.swing.JButton" binding="buttonUp">
|
||||||
|
<constraints>
|
||||||
|
<grid row="2" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||||
|
<minimum-size width="30" height="30"/>
|
||||||
|
<preferred-size width="30" height="30"/>
|
||||||
|
<maximum-size width="30" height="30"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<borderPainted value="true"/>
|
||||||
|
<contentAreaFilled value="false"/>
|
||||||
|
<icon value="Resources/ArrowUp.png"/>
|
||||||
|
<text value=""/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<hspacer id="48a84">
|
||||||
|
<constraints>
|
||||||
|
<grid row="2" column="2" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
</hspacer>
|
||||||
|
<vspacer id="f9d1a">
|
||||||
|
<constraints>
|
||||||
|
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
</vspacer>
|
||||||
|
<component id="e761a" class="javax.swing.JButton" binding="buttonDown">
|
||||||
|
<constraints>
|
||||||
|
<grid row="3" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||||
|
<minimum-size width="30" height="30"/>
|
||||||
|
<preferred-size width="30" height="30"/>
|
||||||
|
<maximum-size width="30" height="30"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<contentAreaFilled value="false"/>
|
||||||
|
<icon value="Resources/ArrowDown.png"/>
|
||||||
|
<text value=""/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="b99d6" class="javax.swing.JButton" binding="buttonLeft">
|
||||||
|
<constraints>
|
||||||
|
<grid row="3" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||||
|
<minimum-size width="30" height="30"/>
|
||||||
|
<preferred-size width="30" height="30"/>
|
||||||
|
<maximum-size width="30" height="30"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<contentAreaFilled value="false"/>
|
||||||
|
<icon value="Resources/ArrowLeft.png"/>
|
||||||
|
<label value=""/>
|
||||||
|
<text value=""/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="7f134" class="javax.swing.JButton" binding="buttonRight">
|
||||||
|
<constraints>
|
||||||
|
<grid row="3" column="5" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||||
|
<minimum-size width="30" height="30"/>
|
||||||
|
<preferred-size width="30" height="30"/>
|
||||||
|
<maximum-size width="30" height="30"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<contentAreaFilled value="false"/>
|
||||||
|
<icon value="Resources/ArrowRight.png"/>
|
||||||
|
<label value=""/>
|
||||||
|
<text value=""/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="fc5b2" class="javax.swing.JButton" binding="createButton">
|
||||||
|
<constraints>
|
||||||
|
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<alignmentX value="0.0"/>
|
||||||
|
<margin top="0" left="0" bottom="0" right="0"/>
|
||||||
|
<text value="Создать"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="65e99" class="javax.swing.JButton" binding="createAdvancedButton">
|
||||||
|
<constraints>
|
||||||
|
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Модификация"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="80160" class="javax.swing.JComboBox" binding="comboBoxSelectorMap">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<model>
|
||||||
|
<item value="Простая карта"/>
|
||||||
|
<item value="Лесная карта"/>
|
||||||
|
</model>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
</form>
|
110
FormMap.java
Normal file
110
FormMap.java
Normal file
@ -0,0 +1,110 @@
|
|||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.ItemEvent;
|
||||||
|
import java.awt.event.ItemListener;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class FormMap extends JFrame {
|
||||||
|
private JPanel artilleryPane;
|
||||||
|
private JLabel speedLabel;
|
||||||
|
private JLabel weightLabel;
|
||||||
|
private JLabel colorLabel;
|
||||||
|
private JPanel pictureBox;
|
||||||
|
private JButton buttonUp;
|
||||||
|
private JButton buttonDown;
|
||||||
|
private JButton buttonLeft;
|
||||||
|
private JButton buttonRight;
|
||||||
|
private JButton createButton;
|
||||||
|
private JButton createAdvancedButton;
|
||||||
|
private JComboBox comboBoxSelectorMap;
|
||||||
|
|
||||||
|
private AbstractMap _abstractMap;
|
||||||
|
private Image bufferedImage;
|
||||||
|
|
||||||
|
public FormMap() {
|
||||||
|
this.setTitle("Artillery");
|
||||||
|
this.setContentPane(artilleryPane);
|
||||||
|
|
||||||
|
_abstractMap = new SimpleMap();
|
||||||
|
|
||||||
|
createButton.addActionListener(e -> {
|
||||||
|
Random rnd = new Random();
|
||||||
|
var artillery = new DrawingArtillery(
|
||||||
|
rnd.nextInt(100, 300),
|
||||||
|
rnd.nextInt(1000, 2000),
|
||||||
|
new Color(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)),
|
||||||
|
rnd.nextInt(4, 6 + 1)
|
||||||
|
);
|
||||||
|
setData(artillery);
|
||||||
|
});
|
||||||
|
buttonLeft.setForeground(new Color(0, 0, 0, 0));
|
||||||
|
buttonRight.setForeground(new Color(0, 0, 0, 0));
|
||||||
|
buttonUp.setForeground(new Color(0, 0, 0, 0));
|
||||||
|
buttonDown.setForeground(new Color(0, 0, 0, 0));
|
||||||
|
buttonLeft.addActionListener(e -> {
|
||||||
|
if (_abstractMap != null) {
|
||||||
|
bufferedImage = _abstractMap.moveObject(Direction.Left);
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
buttonRight.addActionListener(e -> {
|
||||||
|
if (_abstractMap != null) {
|
||||||
|
bufferedImage = _abstractMap.moveObject(Direction.Right);
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
buttonUp.addActionListener(e -> {
|
||||||
|
if (_abstractMap != null) {
|
||||||
|
bufferedImage = _abstractMap.moveObject(Direction.Up);
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
buttonDown.addActionListener(e -> {
|
||||||
|
if (_abstractMap != null) {
|
||||||
|
bufferedImage = _abstractMap.moveObject(Direction.Down);
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
createAdvancedButton.addActionListener(e -> {
|
||||||
|
Random rnd = new Random();
|
||||||
|
var artillery = new DrawingAdvancedArtillery(
|
||||||
|
rnd.nextInt(100, 300),
|
||||||
|
rnd.nextInt(1000, 2000),
|
||||||
|
new Color(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)),
|
||||||
|
rnd.nextInt(4, 6 + 1),
|
||||||
|
new Color(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)),
|
||||||
|
rnd.nextBoolean(),
|
||||||
|
rnd.nextBoolean()
|
||||||
|
);
|
||||||
|
setData(artillery);
|
||||||
|
});
|
||||||
|
comboBoxSelectorMap.addItemListener(e -> {
|
||||||
|
if (e.getStateChange() == ItemEvent.SELECTED) {
|
||||||
|
switch (e.getItem().toString()) {
|
||||||
|
case "Простая карта" -> _abstractMap = new SimpleMap();
|
||||||
|
case "Лесная карта" -> _abstractMap = new ForestMap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setData(DrawingArtillery artillery) {
|
||||||
|
Random rnd = new Random();
|
||||||
|
artillery.setPosition(rnd.nextInt(10, 100), rnd.nextInt(10, 100), pictureBox.getWidth(), pictureBox.getHeight());
|
||||||
|
speedLabel.setText(String.format("Скорость: %d", artillery.artillery.getSpeed()));
|
||||||
|
weightLabel.setText(String.format("Вес: %f", artillery.artillery.getWeight()));
|
||||||
|
colorLabel.setText(String.format("Цвет: %x", artillery.getArtillery().getBodyColor().getRGB()));
|
||||||
|
bufferedImage = _abstractMap.createMap(pictureBox.getWidth(), pictureBox.getHeight(), new DrawingObjectArtillery(artillery));
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void paint(Graphics g) {
|
||||||
|
super.paint(g);
|
||||||
|
|
||||||
|
if (bufferedImage != null) {
|
||||||
|
pictureBox.paintComponents(bufferedImage.getGraphics());
|
||||||
|
pictureBox.getGraphics().drawImage(bufferedImage, 0, 0, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
161
FormMapWithSetArtilleries.form
Normal file
161
FormMapWithSetArtilleries.form
Normal file
@ -0,0 +1,161 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormMapWithSetArtilleries">
|
||||||
|
<grid id="27dc6" binding="paneArtilleries" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||||
|
<margin top="0" left="0" bottom="0" right="0"/>
|
||||||
|
<constraints>
|
||||||
|
<xy x="20" y="20" width="613" height="400"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children>
|
||||||
|
<grid id="fcfe1" binding="pictureBox" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||||
|
<margin top="0" left="0" bottom="0" right="0"/>
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children/>
|
||||||
|
</grid>
|
||||||
|
<grid id="f232" binding="toolsGroup" layout-manager="GridLayoutManager" row-count="9" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||||
|
<margin top="0" left="0" bottom="0" right="0"/>
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children>
|
||||||
|
<component id="d7a62" class="javax.swing.JLabel" binding="toolsLabel">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Инструменты"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<hspacer id="1c91f">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="1" row-span="1" col-span="3" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
</hspacer>
|
||||||
|
<vspacer id="352bc">
|
||||||
|
<constraints>
|
||||||
|
<grid row="5" column="0" row-span="2" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
</vspacer>
|
||||||
|
<component id="6a0f5" class="javax.swing.JComboBox" binding="comboBoxMapSelector">
|
||||||
|
<constraints>
|
||||||
|
<grid row="1" column="1" row-span="1" col-span="3" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<model>
|
||||||
|
<item value="Простая карта"/>
|
||||||
|
<item value="Лесная карта"/>
|
||||||
|
</model>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="52049" class="javax.swing.JButton" binding="buttonAddArtillery">
|
||||||
|
<constraints>
|
||||||
|
<grid row="2" column="1" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Добавить артиллерию"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="2f9ed" class="javax.swing.JFormattedTextField" binding="textBoxPosition">
|
||||||
|
<constraints>
|
||||||
|
<grid row="3" column="1" row-span="1" col-span="3" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
||||||
|
<preferred-size width="150" height="-1"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
</component>
|
||||||
|
<component id="1dbb5" class="javax.swing.JButton" binding="buttonRemoveArtillery">
|
||||||
|
<constraints>
|
||||||
|
<grid row="4" column="1" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<actionCommand value=""/>
|
||||||
|
<text value="Удалить артиллерию"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="4e6ca" class="javax.swing.JButton" binding="buttonShowStorage">
|
||||||
|
<constraints>
|
||||||
|
<grid row="5" column="1" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Посмотреть хранилище"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="51371" class="javax.swing.JButton" binding="buttonShowOnMap">
|
||||||
|
<constraints>
|
||||||
|
<grid row="6" column="1" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Посмотреть карту"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="fb3e4" class="javax.swing.JButton" binding="buttonUp">
|
||||||
|
<constraints>
|
||||||
|
<grid row="7" column="1" row-span="1" col-span="3" vsize-policy="0" hsize-policy="0" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||||
|
<minimum-size width="30" height="30"/>
|
||||||
|
<preferred-size width="30" height="30"/>
|
||||||
|
<maximum-size width="30" height="30"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<borderPainted value="true"/>
|
||||||
|
<contentAreaFilled value="false"/>
|
||||||
|
<icon value="Resources/ArrowUp.png"/>
|
||||||
|
<text value=""/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="328f6" class="javax.swing.JButton" binding="buttonDown">
|
||||||
|
<constraints>
|
||||||
|
<grid row="8" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||||
|
<minimum-size width="30" height="30"/>
|
||||||
|
<preferred-size width="30" height="30"/>
|
||||||
|
<maximum-size width="30" height="30"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<contentAreaFilled value="false"/>
|
||||||
|
<icon value="Resources/ArrowDown.png"/>
|
||||||
|
<text value=""/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="4f2dc" class="javax.swing.JButton" binding="buttonLeft">
|
||||||
|
<constraints>
|
||||||
|
<grid row="8" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||||
|
<minimum-size width="30" height="30"/>
|
||||||
|
<preferred-size width="30" height="30"/>
|
||||||
|
<maximum-size width="30" height="30"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<contentAreaFilled value="false"/>
|
||||||
|
<icon value="Resources/ArrowLeft.png"/>
|
||||||
|
<label value=""/>
|
||||||
|
<text value=""/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="bac06" class="javax.swing.JButton" binding="buttonRight">
|
||||||
|
<constraints>
|
||||||
|
<grid row="8" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||||
|
<minimum-size width="30" height="30"/>
|
||||||
|
<preferred-size width="30" height="30"/>
|
||||||
|
<maximum-size width="30" height="30"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<contentAreaFilled value="false"/>
|
||||||
|
<icon value="Resources/ArrowRight.png"/>
|
||||||
|
<label value=""/>
|
||||||
|
<text value=""/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
</form>
|
150
FormMapWithSetArtilleries.java
Normal file
150
FormMapWithSetArtilleries.java
Normal file
@ -0,0 +1,150 @@
|
|||||||
|
import javax.swing.*;
|
||||||
|
import javax.swing.text.DefaultFormatterFactory;
|
||||||
|
import javax.swing.text.MaskFormatter;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.text.ParseException;
|
||||||
|
|
||||||
|
public class FormMapWithSetArtilleries extends JFrame {
|
||||||
|
private JPanel pictureBox;
|
||||||
|
private JPanel toolsGroup;
|
||||||
|
private JLabel toolsLabel;
|
||||||
|
private JComboBox comboBoxMapSelector;
|
||||||
|
private JButton buttonAddArtillery;
|
||||||
|
private JPanel paneArtilleries;
|
||||||
|
private JFormattedTextField textBoxPosition;
|
||||||
|
private JButton buttonRemoveArtillery;
|
||||||
|
private JButton buttonShowStorage;
|
||||||
|
private JButton buttonUp;
|
||||||
|
private JButton buttonDown;
|
||||||
|
private JButton buttonLeft;
|
||||||
|
private JButton buttonRight;
|
||||||
|
private JButton buttonShowOnMap;
|
||||||
|
|
||||||
|
private Image bufferedImage;
|
||||||
|
private MapWithSetArtilleriesGeneric<DrawingObjectArtillery, AbstractMap> _mapArtilleriesCollectionGeneric;
|
||||||
|
|
||||||
|
public FormMapWithSetArtilleries() {
|
||||||
|
this.setTitle("Artillery");
|
||||||
|
this.setContentPane(paneArtilleries);
|
||||||
|
|
||||||
|
try {
|
||||||
|
textBoxPosition.setFormatterFactory(new DefaultFormatterFactory(new MaskFormatter("##")));
|
||||||
|
} catch (ParseException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
comboBoxMapSelector.addActionListener(e -> {
|
||||||
|
AbstractMap map = switch (((JComboBox) e.getSource()).getSelectedItem().toString()) {
|
||||||
|
case "Простая карта" -> new SimpleMap();
|
||||||
|
case "Лесная карта" -> new ForestMap();
|
||||||
|
default -> null;
|
||||||
|
};
|
||||||
|
|
||||||
|
if (map != null) {
|
||||||
|
_mapArtilleriesCollectionGeneric = new MapWithSetArtilleriesGeneric<>(pictureBox.getWidth(), pictureBox.getHeight(), map);
|
||||||
|
} else {
|
||||||
|
_mapArtilleriesCollectionGeneric = null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
buttonAddArtillery.addActionListener(e -> {
|
||||||
|
if (_mapArtilleriesCollectionGeneric == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
FormArtillery dialog = new FormArtillery();
|
||||||
|
dialog.setSize(800, 500);
|
||||||
|
dialog.setModalityType(Dialog.ModalityType.APPLICATION_MODAL);
|
||||||
|
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
||||||
|
|
||||||
|
dialog.setVisible(true);
|
||||||
|
|
||||||
|
if (dialog.getSelectedArtillery() != null) {
|
||||||
|
DrawingObjectArtillery car = new DrawingObjectArtillery(dialog.getSelectedArtillery());
|
||||||
|
if (_mapArtilleriesCollectionGeneric.addArtillery(car) != -1)
|
||||||
|
{
|
||||||
|
JOptionPane.showMessageDialog(this, "Объект добавлен", "Успех", JOptionPane.INFORMATION_MESSAGE);
|
||||||
|
bufferedImage = _mapArtilleriesCollectionGeneric.showSet();
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
JOptionPane.showMessageDialog(this, "Не удалось добавить объект", "Провал", JOptionPane.INFORMATION_MESSAGE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
buttonRemoveArtillery.addActionListener(e -> {
|
||||||
|
String text = textBoxPosition.getText();
|
||||||
|
if (text == null || text.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (JOptionPane.showConfirmDialog(this, "Удалить объект?", "Удаление", JOptionPane.YES_NO_OPTION) == JOptionPane.NO_OPTION) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int position = Integer.parseInt(text);
|
||||||
|
|
||||||
|
if (_mapArtilleriesCollectionGeneric.removeArtilleryAt(position) != null) {
|
||||||
|
JOptionPane.showMessageDialog(this, "Объект удалён", "Успех", JOptionPane.INFORMATION_MESSAGE);
|
||||||
|
bufferedImage = _mapArtilleriesCollectionGeneric.showSet();
|
||||||
|
repaint();
|
||||||
|
} else {
|
||||||
|
JOptionPane.showMessageDialog(this, "Не удалось удалить объект", "Провал", JOptionPane.INFORMATION_MESSAGE);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
buttonShowStorage.addActionListener(e -> {
|
||||||
|
if (_mapArtilleriesCollectionGeneric == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
bufferedImage = _mapArtilleriesCollectionGeneric.showSet();
|
||||||
|
repaint();
|
||||||
|
});
|
||||||
|
|
||||||
|
buttonShowOnMap.addActionListener(e -> {
|
||||||
|
if (_mapArtilleriesCollectionGeneric == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
bufferedImage = _mapArtilleriesCollectionGeneric.showOnMap();
|
||||||
|
repaint();
|
||||||
|
});
|
||||||
|
|
||||||
|
buttonLeft.addActionListener(e -> {
|
||||||
|
if (_mapArtilleriesCollectionGeneric != null) {
|
||||||
|
bufferedImage = _mapArtilleriesCollectionGeneric.moveObject(Direction.Left);
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
buttonRight.addActionListener(e -> {
|
||||||
|
if (_mapArtilleriesCollectionGeneric != null) {
|
||||||
|
bufferedImage = _mapArtilleriesCollectionGeneric.moveObject(Direction.Right);
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
buttonUp.addActionListener(e -> {
|
||||||
|
if (_mapArtilleriesCollectionGeneric != null) {
|
||||||
|
bufferedImage = _mapArtilleriesCollectionGeneric.moveObject(Direction.Up);
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
buttonDown.addActionListener(e -> {
|
||||||
|
if (_mapArtilleriesCollectionGeneric != null) {
|
||||||
|
bufferedImage = _mapArtilleriesCollectionGeneric.moveObject(Direction.Down);
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void paint(Graphics g) {
|
||||||
|
super.paint(g);
|
||||||
|
|
||||||
|
if (bufferedImage != null) {
|
||||||
|
pictureBox.paintComponents(bufferedImage.getGraphics());
|
||||||
|
pictureBox.getGraphics().drawImage(bufferedImage, 0, 0, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
9
IDrawingObject.java
Normal file
9
IDrawingObject.java
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public interface IDrawingObject {
|
||||||
|
float getStep();
|
||||||
|
void setObject(int x, int y, int width, int height);
|
||||||
|
void moveObject(Direction direction);
|
||||||
|
void drawingObject(Graphics2D g);
|
||||||
|
float[] getCurrentPosition();
|
||||||
|
}
|
6
IDrawingRollers.java
Normal file
6
IDrawingRollers.java
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public interface IDrawingRollers {
|
||||||
|
void setRollersCount(int num);
|
||||||
|
void draw(Graphics2D g, int x, int y, int artilleryWidth, int artilleryHeight);
|
||||||
|
}
|
133
MapWithSetArtilleriesGeneric.java
Normal file
133
MapWithSetArtilleriesGeneric.java
Normal file
@ -0,0 +1,133 @@
|
|||||||
|
import java.awt.*;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
|
||||||
|
public class MapWithSetArtilleriesGeneric<T extends IDrawingObject, U extends AbstractMap> {
|
||||||
|
public final int _pictureWidth;
|
||||||
|
public final int _pictureHeight;
|
||||||
|
public final int _placeSizeWidth = 210;
|
||||||
|
public final int _placeSizeHeight = 90;
|
||||||
|
private final SetArtilleriesGeneric<T> _setArtilleries;
|
||||||
|
private final U _map;
|
||||||
|
|
||||||
|
public MapWithSetArtilleriesGeneric(int picWidth, int picHeight, U map) {
|
||||||
|
int width = picWidth / _placeSizeWidth;
|
||||||
|
int height = picHeight / _placeSizeHeight;
|
||||||
|
_setArtilleries = new SetArtilleriesGeneric<T>(width * height);
|
||||||
|
_pictureWidth = picWidth;
|
||||||
|
_pictureHeight = picHeight;
|
||||||
|
_map = map;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int addArtillery(T artillery) {
|
||||||
|
return _setArtilleries.insert(artillery);
|
||||||
|
}
|
||||||
|
|
||||||
|
public T removeArtilleryAt(int position) {
|
||||||
|
return _setArtilleries.remove(position);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Image showSet() {
|
||||||
|
BufferedImage img = new BufferedImage(_pictureWidth, _pictureHeight, BufferedImage.TYPE_INT_ARGB);
|
||||||
|
Graphics2D g2d = (Graphics2D) img.getGraphics();
|
||||||
|
drawBackground(g2d);
|
||||||
|
drawArtilleries(g2d);
|
||||||
|
return img;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Image showOnMap() {
|
||||||
|
shaking();
|
||||||
|
for (int i = 0; i < _setArtilleries.getCount(); i++)
|
||||||
|
{
|
||||||
|
var car = _setArtilleries.get(i);
|
||||||
|
if (car != null)
|
||||||
|
{
|
||||||
|
return _map.createMap(_pictureWidth, _pictureHeight, car);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new BufferedImage(_pictureWidth, _pictureHeight, BufferedImage.TYPE_INT_ARGB);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Image moveObject(Direction direction) {
|
||||||
|
if (_map != null) {
|
||||||
|
return _map.moveObject(direction);
|
||||||
|
}
|
||||||
|
return new BufferedImage(_pictureWidth, _pictureHeight, BufferedImage.TYPE_INT_ARGB);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void shaking() {
|
||||||
|
int j = _setArtilleries.getCount() - 1;
|
||||||
|
for (int i = 0; i < _setArtilleries.getCount(); i++)
|
||||||
|
{
|
||||||
|
if (_setArtilleries.get(i) == null)
|
||||||
|
{
|
||||||
|
for (; j > i; j--)
|
||||||
|
{
|
||||||
|
var artillery = _setArtilleries.get(j);
|
||||||
|
if (artillery != null)
|
||||||
|
{
|
||||||
|
_setArtilleries.insert(artillery, i);
|
||||||
|
_setArtilleries.remove(j);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (j <= i)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void drawBackground(Graphics2D g) {
|
||||||
|
Color pen = Color.black;
|
||||||
|
Color box = new Color(0, 100, 0, 255);
|
||||||
|
Color flag = Color.red;
|
||||||
|
Stroke normalStroke = new BasicStroke(1);
|
||||||
|
Stroke penStroke = new BasicStroke(3);
|
||||||
|
Stroke thinPenStroke = new BasicStroke(2);
|
||||||
|
|
||||||
|
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
|
||||||
|
{
|
||||||
|
g.setColor(pen);
|
||||||
|
g.setStroke(penStroke);
|
||||||
|
g.drawLine(i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight);
|
||||||
|
|
||||||
|
g.setColor(box);
|
||||||
|
g.fillRect(i * _placeSizeWidth + 5, j * _placeSizeHeight + _placeSizeHeight * 3 / 4 - 5, _placeSizeWidth / 3 - 5, _placeSizeHeight / 3 - 5);
|
||||||
|
|
||||||
|
g.setColor(pen);
|
||||||
|
g.setStroke(thinPenStroke);
|
||||||
|
g.drawLine(i * _placeSizeWidth + 5, j * _placeSizeHeight + _placeSizeHeight * 3 / 4 - 5, i * _placeSizeWidth + _placeSizeWidth / 3, j * _placeSizeHeight + _placeSizeHeight * 3 / 4 + _placeSizeHeight / 3 - 10);
|
||||||
|
g.drawLine(i * _placeSizeWidth + 5, j * _placeSizeHeight + _placeSizeHeight * 3 / 4 + _placeSizeHeight / 3 - 10, i * _placeSizeWidth + _placeSizeWidth / 3, j * _placeSizeHeight + _placeSizeHeight * 3 / 4 - 5);
|
||||||
|
|
||||||
|
g.setColor(flag);
|
||||||
|
g.fillRect(i * _placeSizeWidth + _placeSizeWidth * 5 / 12, j * _placeSizeHeight + _placeSizeHeight * 5 / 8 - 5, _placeSizeWidth / 5, _placeSizeHeight / 5);
|
||||||
|
|
||||||
|
g.setColor(pen);
|
||||||
|
g.setStroke(thinPenStroke);
|
||||||
|
g.drawLine(i * _placeSizeWidth + _placeSizeWidth * 5 / 12, j * _placeSizeHeight + _placeSizeHeight - 5, i * _placeSizeWidth + _placeSizeWidth * 5 / 12, j * _placeSizeHeight + _placeSizeHeight * 5 / 8 - 5);
|
||||||
|
}
|
||||||
|
g.setColor(pen);
|
||||||
|
g.setStroke(penStroke);
|
||||||
|
g.drawLine(i * _placeSizeWidth, 0, i * _placeSizeWidth, (_pictureHeight / _placeSizeHeight) * _placeSizeHeight);
|
||||||
|
}
|
||||||
|
g.setStroke(normalStroke);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void drawArtilleries(Graphics2D g) {
|
||||||
|
int width = _pictureWidth / _placeSizeWidth;
|
||||||
|
int height = _pictureHeight / _placeSizeHeight;
|
||||||
|
|
||||||
|
for (int i = 0; i < _setArtilleries.getCount(); i++)
|
||||||
|
{
|
||||||
|
var artillery = _setArtilleries.get(i);
|
||||||
|
if (artillery != null)
|
||||||
|
{
|
||||||
|
artillery.setObject(i % width * _placeSizeWidth + 10, (height - 1 - i / width) * _placeSizeHeight + 10, _pictureWidth, _pictureHeight);
|
||||||
|
artillery.drawingObject(g);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -2,7 +2,7 @@ import javax.swing.*;
|
|||||||
|
|
||||||
public class Program {
|
public class Program {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
FormArtillery form = new FormArtillery();
|
FormMapWithSetArtilleries form = new FormMapWithSetArtilleries();
|
||||||
form.setSize(640, 480);
|
form.setSize(640, 480);
|
||||||
form.setVisible(true);
|
form.setVisible(true);
|
||||||
form.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
form.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
||||||
|
17
RollersType.java
Normal file
17
RollersType.java
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import java.awt.*;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public enum RollersType {
|
||||||
|
Standard,
|
||||||
|
Squared,
|
||||||
|
Cross;
|
||||||
|
|
||||||
|
public static IDrawingRollers random(int rollersCount, Color bodyColor) {
|
||||||
|
return switch (new Random().nextInt(RollersType.values().length)) {
|
||||||
|
case 0 -> new DrawingRollers(rollersCount, bodyColor);
|
||||||
|
case 1 -> new DrawingSquaredRollers(rollersCount, bodyColor);
|
||||||
|
case 2 -> new DrawingCrossRollers(rollersCount, bodyColor);
|
||||||
|
default -> null;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
70
SetArtilleriesGeneric.java
Normal file
70
SetArtilleriesGeneric.java
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
public class SetArtilleriesGeneric<T> {
|
||||||
|
private final Object[] _places;
|
||||||
|
|
||||||
|
public int getCount() {
|
||||||
|
return _places.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SetArtilleriesGeneric(int count) {
|
||||||
|
_places = new Object[count];
|
||||||
|
}
|
||||||
|
|
||||||
|
public int insert(T artillery) {
|
||||||
|
return insert(artillery, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int insert(T artillery, int position) {
|
||||||
|
if (position < 0 || position >= getCount()) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_places[position] == null) {
|
||||||
|
_places[position] = artillery;
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
|
||||||
|
int firstNull = -1;
|
||||||
|
|
||||||
|
for (int i = position + 1; i < getCount(); i++)
|
||||||
|
{
|
||||||
|
if (_places[i] == null)
|
||||||
|
{
|
||||||
|
firstNull = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (firstNull == -1)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
System.arraycopy(_places, position, _places, position + 1, firstNull - position);
|
||||||
|
|
||||||
|
_places[position] = artillery;
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public T remove(int position) {
|
||||||
|
if (position < 0 || position >= getCount())
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var result = _places[position];
|
||||||
|
|
||||||
|
_places[position] = null;
|
||||||
|
|
||||||
|
return (T) result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public T get(int position) {
|
||||||
|
if (position < 0 || position >= getCount()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (T) _places[position];
|
||||||
|
}
|
||||||
|
}
|
40
SimpleMap.java
Normal file
40
SimpleMap.java
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
import java.awt.*;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class SimpleMap extends AbstractMap {
|
||||||
|
private final Color barrierColor = Color.black;
|
||||||
|
private final Color roadColor = Color.gray;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void drawBarrierPart(Graphics2D g, int i, int j) {
|
||||||
|
g.setColor(barrierColor);
|
||||||
|
g.fillRect(j * (int) _size_x, i * (int) _size_y, (int) _size_x, (int) _size_y);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void drawRoadPart(Graphics2D g, int i, int j) {
|
||||||
|
g.setColor(roadColor);
|
||||||
|
g.fillRect(j * (int) _size_x, i * (int) _size_y, (int) _size_x, (int) _size_y);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void generateMap() {
|
||||||
|
_map = new int[100][100];
|
||||||
|
_size_x = (float)_width / _map[0].length;
|
||||||
|
_size_y = (float)_height / _map.length;
|
||||||
|
int counter = 0;
|
||||||
|
for (int[] row : _map) {
|
||||||
|
Arrays.fill(row, _freeRoad);
|
||||||
|
}
|
||||||
|
while (counter < 50)
|
||||||
|
{
|
||||||
|
int x = _random.nextInt(0, 100);
|
||||||
|
int y = _random.nextInt(0, 100);
|
||||||
|
if (_map[y][x] == _freeRoad)
|
||||||
|
{
|
||||||
|
_map[y][x] = _barrier;
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user