Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
3b5af9bbb1 |
@ -1,188 +0,0 @@
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.HashMap;
|
||||
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)
|
||||
{
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.drawingObject = drawingObject;
|
||||
GenerateMap();
|
||||
while (!SetObjectOnMap())
|
||||
{
|
||||
GenerateMap();
|
||||
}
|
||||
return DrawMapWithObject();
|
||||
}
|
||||
|
||||
public Image MoveObject(Direction direction)
|
||||
{
|
||||
if (drawingObject == null)
|
||||
return null;
|
||||
boolean flag = true;
|
||||
float step = drawingObject.getStep();
|
||||
|
||||
HashMap<String, Float> hashMap = drawingObject.GetCurrentPosition();
|
||||
float left = hashMap.get("Left");
|
||||
float right = hashMap.get("Right");
|
||||
float top = hashMap.get("Top");
|
||||
float bottom = hashMap.get("Bottom");
|
||||
|
||||
int x1_obj_next = (int)((left - step) / size_x);
|
||||
int y1_obj_next = (int)((top - step) / size_y);
|
||||
int x2_obj_next = (int)((right + step) / size_x);
|
||||
int y2_obj_next = (int)((bottom + step) / size_y);
|
||||
|
||||
int x1_obj_current = (int)(left / size_x);
|
||||
int y1_obj_current = (int)(top / size_y);
|
||||
int x2_obj_current = (int)(right / size_x);
|
||||
int y2_obj_current = (int)(bottom / size_y);
|
||||
|
||||
switch (direction)
|
||||
{
|
||||
case Left:
|
||||
{
|
||||
if (x1_obj_next < 0)
|
||||
flag = false;
|
||||
else
|
||||
{
|
||||
for (int i = x1_obj_next; i <= x1_obj_current; i++)
|
||||
{
|
||||
for (int j = y1_obj_current; j <= y2_obj_current; j++)
|
||||
{
|
||||
if (map[i][j] == _barrier)
|
||||
flag = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case Right:
|
||||
{
|
||||
if (x2_obj_next >= map.length)
|
||||
flag = false;
|
||||
else
|
||||
{
|
||||
for (int i = x2_obj_current; i <= x2_obj_next; i++)
|
||||
{
|
||||
for (int j = y1_obj_current; j <= y2_obj_current; j++)
|
||||
{
|
||||
if (map[i][j] == _barrier)
|
||||
flag = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case Up:
|
||||
{
|
||||
if (y1_obj_next < 0)
|
||||
flag = false;
|
||||
else
|
||||
{
|
||||
for (int i = x1_obj_current; i <= x2_obj_current; i++)
|
||||
{
|
||||
for (int j = y1_obj_next; j <= y1_obj_current; j++)
|
||||
{
|
||||
if (map[i][j] == _barrier)
|
||||
flag = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case Down:
|
||||
{
|
||||
if (y2_obj_next >= map.length)
|
||||
flag = false;
|
||||
else
|
||||
{
|
||||
for (int i = x1_obj_current; i <= x2_obj_current; i++)
|
||||
{
|
||||
for (int j = y2_obj_current; j <= y2_obj_next; j++)
|
||||
{
|
||||
if (map[i][j] == _barrier)
|
||||
flag = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (flag)
|
||||
{
|
||||
drawingObject.MoveObject(direction);
|
||||
}
|
||||
return DrawMapWithObject();
|
||||
}
|
||||
private boolean SetObjectOnMap()
|
||||
{
|
||||
if (drawingObject == null || map == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
int x = random.nextInt(0, 10);
|
||||
int y = random.nextInt(0, 10);
|
||||
drawingObject.SetObject(x, y, width, height);
|
||||
|
||||
HashMap<String, Float> hashMap = drawingObject.GetCurrentPosition();
|
||||
float left = hashMap.get("Left");
|
||||
float right = hashMap.get("Right");
|
||||
float top = hashMap.get("Top");
|
||||
float bottom = hashMap.get("Bottom");
|
||||
|
||||
for (int i = (int)(x / size_x); i <= (int) (right / size_x); i++)
|
||||
{
|
||||
for (int j = (int)(y / size_y); j <= (int) (bottom / size_y); j++)
|
||||
{
|
||||
if (map[i][j] == _barrier)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private Image DrawMapWithObject()
|
||||
{
|
||||
BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_BGR);
|
||||
if (drawingObject == null || map == null)
|
||||
return img;
|
||||
|
||||
Graphics2D gr = img.createGraphics();
|
||||
|
||||
for (int i = 0; i < map.length; ++i)
|
||||
{
|
||||
for (int j = 0; j < map[0].length; ++j)
|
||||
{
|
||||
if (map[i][j] == _freeRoad)
|
||||
{
|
||||
DrawRoadPart(gr, i, j);
|
||||
}
|
||||
else if (map[i][j] == _barrier)
|
||||
{
|
||||
DrawBarrierPart(gr, i, j);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
drawingObject.DrawingObject(gr);
|
||||
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);
|
||||
}
|
@ -1,48 +1,33 @@
|
||||
import java.awt.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.Random;
|
||||
|
||||
public class DrawingArmoredCar {
|
||||
protected EntityArmoredCar armoredCar;
|
||||
private EntityArmoredCar armoredCar;
|
||||
|
||||
protected float startPosX;
|
||||
private float startPosX;
|
||||
|
||||
protected float startPosY;
|
||||
private float startPosY;
|
||||
|
||||
private int pictureWidth;
|
||||
|
||||
private int pictureHeight;
|
||||
|
||||
private int carWidth = 80;
|
||||
private static final int carWidth = 80;
|
||||
|
||||
private int carHeight = 50;
|
||||
private static final int carHeight = 50;
|
||||
|
||||
protected IDrawingCaterpillar drawingCaterpillar;
|
||||
private DrawingCaterpillar drawingCaterpillar;
|
||||
|
||||
public EntityArmoredCar getArmoredCar() {
|
||||
return armoredCar;
|
||||
}
|
||||
|
||||
public DrawingArmoredCar(int speed, float weight, Color bodyColor) {
|
||||
this.armoredCar = new EntityArmoredCar(speed, weight, bodyColor);
|
||||
IDrawingCaterpillar[] realisations = new IDrawingCaterpillar[]{
|
||||
new DrawingCaterpillar(bodyColor),
|
||||
new DrawingCrossCaterpillar(bodyColor),
|
||||
new DrawingDoubleCaterpillar(bodyColor)};
|
||||
public void Init(int speed, float weight, Color bodyColor) {
|
||||
this.armoredCar = new EntityArmoredCar();
|
||||
this.armoredCar.init(speed, weight, bodyColor);
|
||||
Random r = new Random();
|
||||
int num = r.nextInt(4, 7);
|
||||
this.drawingCaterpillar = realisations[r.nextInt(3)];
|
||||
drawingCaterpillar.setNumRinks(num);
|
||||
}
|
||||
|
||||
protected DrawingArmoredCar(int speed, float weight, Color bodyColor, int carWidth, int carHeight) {
|
||||
this(speed, weight, bodyColor);
|
||||
this.carWidth = carWidth;
|
||||
this.carHeight = carHeight;
|
||||
}
|
||||
|
||||
public void SetCaterpillar(IDrawingCaterpillar caterpillar) {
|
||||
this.drawingCaterpillar = caterpillar;
|
||||
this.drawingCaterpillar = new DrawingCaterpillar();
|
||||
this.drawingCaterpillar.Init(r.nextInt(4, 7), bodyColor);
|
||||
}
|
||||
|
||||
public void SetPosition(int x, int y, int width, int height) {
|
||||
@ -99,19 +84,17 @@ public class DrawingArmoredCar {
|
||||
{
|
||||
return;
|
||||
}
|
||||
g2d.setPaint(armoredCar.getBodyColor());
|
||||
// отрисовка корпуса и гусеницы
|
||||
int new_startPosX = Math.round(startPosX);
|
||||
int new_startPosY = Math.round(startPosY);
|
||||
g2d.fillRect(new_startPosX + 20, new_startPosY, 40, 20);
|
||||
g2d.setPaint(armoredCar.getBodyColor());
|
||||
g2d.fillRect((int ) startPosX + 20, (int) startPosY, 40, 20);
|
||||
g2d.setPaint(Color.LIGHT_GRAY);
|
||||
g2d.fillRect(new_startPosX, new_startPosY + 20, 80, 20);
|
||||
g2d.fillRect((int ) startPosX, (int ) startPosY + 20, 80, 20);
|
||||
|
||||
g2d.fillOval(new_startPosX, new_startPosY + 30, 20, 20);
|
||||
g2d.fillOval(new_startPosX + 80 - 20, new_startPosY + 30, 20, 20);
|
||||
g2d.fillRect(new_startPosX + 15, new_startPosY + 20, 60, 30);
|
||||
g2d.fillOval((int ) startPosX, (int ) startPosY + 30, 20, 20);
|
||||
g2d.fillOval((int ) startPosX + 80 - 20, (int ) startPosY + 30, 20, 20);
|
||||
g2d.fillRect((int ) startPosX + 15, (int ) startPosY + 20, 60, 30);
|
||||
// отрисовка катков в гусенице
|
||||
drawingCaterpillar.DrawCaterpillar(g2d, new_startPosX, new_startPosY);
|
||||
drawingCaterpillar.DrawCaterpillar(g2d, (int)startPosX, (int)startPosY);
|
||||
}
|
||||
|
||||
public void ChangeBorders(int width, int height)
|
||||
@ -133,14 +116,4 @@ public class DrawingArmoredCar {
|
||||
startPosY = pictureHeight - carHeight;
|
||||
}
|
||||
}
|
||||
|
||||
public HashMap<String, Float> GetCurrentPosition()
|
||||
{
|
||||
HashMap<String, Float> hashMap = new HashMap<String, Float>();
|
||||
hashMap.put("Left", startPosX);
|
||||
hashMap.put("Right", startPosX + carWidth);
|
||||
hashMap.put("Top", startPosY);
|
||||
hashMap.put("Bottom", startPosY + carHeight);
|
||||
return hashMap;
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,14 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawingCaterpillar implements IDrawingCaterpillar {
|
||||
public class DrawingCaterpillar {
|
||||
private NumRinks numRinks = NumRinks.Four;
|
||||
private Color color;
|
||||
|
||||
public DrawingCaterpillar(Color color) {
|
||||
public void Init(int n, Color color) {
|
||||
setNumRinks(n);
|
||||
this.color = color;
|
||||
}
|
||||
@Override
|
||||
|
||||
public void setNumRinks(int n) {
|
||||
switch (n) {
|
||||
case 4 -> numRinks = NumRinks.Four;
|
||||
@ -21,7 +22,7 @@ public class DrawingCaterpillar implements IDrawingCaterpillar {
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
|
||||
public void DrawCaterpillar(Graphics2D g2d, int startPosX, int startPosY)
|
||||
{
|
||||
color = color != null ? color : Color.YELLOW;
|
||||
|
@ -1,42 +0,0 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawingCrossCaterpillar implements IDrawingCaterpillar{
|
||||
private NumRinks numRinks = NumRinks.Four;
|
||||
private Color color;
|
||||
|
||||
public DrawingCrossCaterpillar(Color color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNumRinks(int n) {
|
||||
switch (n) {
|
||||
case 4 -> numRinks = NumRinks.Four;
|
||||
|
||||
case 5 -> numRinks = NumRinks.Five;
|
||||
|
||||
case 6 -> numRinks = NumRinks.Six;
|
||||
|
||||
default -> {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void DrawCaterpillar(Graphics2D g2d, int startPosX, int startPosY) {
|
||||
color = color != null ? color : Color.YELLOW;
|
||||
|
||||
int size = numRinks == NumRinks.Four ? 15 : 10;
|
||||
int dist = numRinks == NumRinks.Four ? 20 : 13;
|
||||
startPosX = numRinks == NumRinks.Five ? startPosX + 5 : startPosX;
|
||||
for (int i = 0; i < numRinks.val(); i++) {
|
||||
g2d.setPaint(color);
|
||||
g2d.fillOval(startPosX + dist * i, startPosY + 30, size, size);
|
||||
g2d.setColor(Color.BLACK);
|
||||
g2d.setStroke(new BasicStroke(3));
|
||||
g2d.drawLine(startPosX + dist * i, startPosY + 30, startPosX + dist * i + size, startPosY + 30 + size);
|
||||
g2d.drawLine(startPosX + dist * i + size, startPosY + 30, startPosX + dist * i, startPosY + 30 + size);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawingDoubleCaterpillar implements IDrawingCaterpillar{
|
||||
private NumRinks numRinks = NumRinks.Four;
|
||||
private Color color;
|
||||
|
||||
public DrawingDoubleCaterpillar(Color color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNumRinks(int n) {
|
||||
switch (n) {
|
||||
case 4 -> numRinks = NumRinks.Four;
|
||||
|
||||
case 5 -> numRinks = NumRinks.Five;
|
||||
|
||||
case 6 -> numRinks = NumRinks.Six;
|
||||
|
||||
default -> {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void DrawCaterpillar(Graphics2D g2d, int startPosX, int startPosY) {
|
||||
color = color != null ? color : Color.YELLOW;
|
||||
int size = numRinks == NumRinks.Four ? 15 : 10;
|
||||
int dist = numRinks == NumRinks.Four ? 20 : 13;
|
||||
startPosX = numRinks == NumRinks.Five ? startPosX + 5 : startPosX;
|
||||
for (int i = 0; i < numRinks.val(); i++) {
|
||||
g2d.setPaint(color);
|
||||
g2d.fillOval(startPosX + dist * i, startPosY + 30, size, size);
|
||||
g2d.setPaint(Color.WHITE);
|
||||
g2d.fillOval(startPosX + dist * i + size/4, startPosY + 30 + size/4, size/2, size/2);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
import java.awt.*;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class DrawingObjectArmoredCar implements IDrawingObject{
|
||||
private DrawingArmoredCar armoredCar = null;
|
||||
|
||||
public DrawingObjectArmoredCar(DrawingArmoredCar armoredCar) {
|
||||
this.armoredCar = armoredCar;
|
||||
}
|
||||
|
||||
public DrawingArmoredCar getArmoredCar() {
|
||||
return armoredCar;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getStep() {
|
||||
if (armoredCar != null)
|
||||
return armoredCar.armoredCar.step;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void SetObject(int x, int y, int width, int height) {
|
||||
if (armoredCar != null)
|
||||
armoredCar.SetPosition(x, y, width, height);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void MoveObject(Direction direction) {
|
||||
if (armoredCar != null)
|
||||
armoredCar.MoveTransport(direction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void DrawingObject(Graphics2D g) {
|
||||
if (armoredCar != null)
|
||||
armoredCar.DrawTransport(g);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashMap<String, Float> GetCurrentPosition() {
|
||||
return armoredCar.GetCurrentPosition();
|
||||
}
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawingTank extends DrawingArmoredCar{
|
||||
public DrawingTank(int speed, float weight, Color bodyColor, Color dopColor,
|
||||
boolean towerWeapon, boolean AMachineGun) {
|
||||
super(speed, weight, bodyColor, 80, 60);
|
||||
armoredCar = new EntityTank(speed, weight, bodyColor, dopColor, towerWeapon, AMachineGun);
|
||||
}
|
||||
@Override
|
||||
public void DrawTransport(Graphics2D g) {
|
||||
if (!(armoredCar instanceof EntityTank tank)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (tank.isTowerWeapon()) {
|
||||
g.setColor(tank.getDopColor());
|
||||
g.fillRect((int)startPosX + 40, (int)startPosY, 5, 20);
|
||||
g.fillRect((int)startPosX + 40, (int)startPosY, 40, 5);
|
||||
g.fillOval((int)startPosX + 27, (int)startPosY + 7, 30, 10);
|
||||
}
|
||||
if (tank.isAMachineGun()) {
|
||||
g.setColor(tank.getDopColor());
|
||||
g.fillRect((int)startPosX + 60, (int)startPosY + 15, 7, 10);
|
||||
g.fillRect((int)startPosX + 60, (int)startPosY + 17, 20, 5);
|
||||
}
|
||||
startPosY += 5;
|
||||
super.DrawTransport(g);
|
||||
startPosY -= 5;
|
||||
}
|
||||
}
|
@ -7,7 +7,7 @@ public class EntityArmoredCar {
|
||||
private Color bodyColor;
|
||||
public float step;
|
||||
|
||||
public EntityArmoredCar(int speed, float weight, Color bodyColor) {
|
||||
public void init(int speed, float weight, Color bodyColor) {
|
||||
this.speed = speed;
|
||||
this.weight = weight;
|
||||
this.bodyColor = bodyColor;
|
||||
|
@ -1,26 +0,0 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class EntityTank extends EntityArmoredCar{
|
||||
private Color dopColor;
|
||||
private boolean towerWeapon;
|
||||
private boolean AMachineGun;
|
||||
|
||||
public Color getDopColor() {
|
||||
return dopColor;
|
||||
}
|
||||
|
||||
public boolean isTowerWeapon() {
|
||||
return towerWeapon;
|
||||
}
|
||||
|
||||
public boolean isAMachineGun() {
|
||||
return AMachineGun;
|
||||
}
|
||||
|
||||
public EntityTank(int speed, float weight, Color bodyColor, Color dopColor, boolean towerWeapon, boolean AMachineGun) {
|
||||
super(speed, weight, bodyColor);
|
||||
this.dopColor = dopColor;
|
||||
this.towerWeapon = towerWeapon;
|
||||
this.AMachineGun = AMachineGun;
|
||||
}
|
||||
}
|
@ -22,7 +22,7 @@
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<grid id="7c72e" layout-manager="GridLayoutManager" row-count="2" column-count="6" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<grid id="7c72e" layout-manager="GridLayoutManager" row-count="2" 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="3" column="0" row-span="1" col-span="3" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="true"/>
|
||||
@ -40,7 +40,7 @@
|
||||
</component>
|
||||
<component id="f4d6e" class="javax.swing.JButton" binding="buttonRight">
|
||||
<constraints>
|
||||
<grid row="1" 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="1" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<icon value="Right.png"/>
|
||||
@ -49,7 +49,7 @@
|
||||
</component>
|
||||
<component id="12974" class="javax.swing.JButton" binding="buttonUp">
|
||||
<constraints>
|
||||
<grid row="0" 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="0" 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>
|
||||
<enabled value="true"/>
|
||||
@ -60,7 +60,7 @@
|
||||
</component>
|
||||
<component id="da478" class="javax.swing.JButton" binding="buttonDown">
|
||||
<constraints>
|
||||
<grid row="1" 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="1" 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>
|
||||
<icon value="Down.png"/>
|
||||
@ -69,7 +69,7 @@
|
||||
</component>
|
||||
<component id="43d8e" class="javax.swing.JButton" binding="buttonLeft">
|
||||
<constraints>
|
||||
<grid row="1" 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="1" 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>
|
||||
<icon value="Left.png"/>
|
||||
@ -77,22 +77,6 @@
|
||||
<visible value="true"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="64b34" class="javax.swing.JButton" binding="buttonCreate_Modif">
|
||||
<constraints>
|
||||
<grid row="1" 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="7c1e4" class="javax.swing.JButton" binding="buttonSelectArmoredCar">
|
||||
<constraints>
|
||||
<grid row="1" 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>
|
||||
</children>
|
||||
</grid>
|
||||
<component id="2cd31" class="javax.swing.JLabel" binding="labelSpeed">
|
||||
|
@ -17,16 +17,13 @@ public class FormArmoredCar extends JFrame{
|
||||
private JLabel labelSpeed;
|
||||
private JLabel labelWeight;
|
||||
private JLabel labelColor;
|
||||
private JButton buttonCreate_Modif;
|
||||
private JButton buttonSelectArmoredCar;
|
||||
|
||||
private DrawingArmoredCar armoredCar;
|
||||
private DrawingArmoredCar selectedCar;
|
||||
public boolean DialogResult = false;
|
||||
|
||||
public FormArmoredCar() {
|
||||
super("Бронированная машина");
|
||||
setBounds(100, 100, 700, 700);
|
||||
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
|
||||
addComponentListener(new ComponentAdapter() {
|
||||
public void componentResized(ComponentEvent componentEvent) {
|
||||
@ -45,11 +42,16 @@ public class FormArmoredCar extends JFrame{
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent actionEvent) {
|
||||
Random rnd = new Random();
|
||||
Color newColor = JColorChooser.showDialog(null, "Choose a color", Color.RED);
|
||||
armoredCar = new DrawingArmoredCar(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000),
|
||||
newColor);
|
||||
armoredCar = new DrawingArmoredCar();
|
||||
armoredCar.Init(rnd.nextInt(100,300), rnd.nextInt(1000, 2000),
|
||||
new Color(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)));
|
||||
|
||||
setData();
|
||||
armoredCar.SetPosition(rnd.nextInt(10, 100), rnd.nextInt(10, 100),
|
||||
drawPanel.getWidth(), drawPanel.getHeight());
|
||||
|
||||
labelSpeed.setText("Скорость: " + armoredCar.getArmoredCar().getSpeed());
|
||||
labelWeight.setText("Вес: " + armoredCar.getArmoredCar().getWeight());
|
||||
labelColor.setText("Цвет: " + armoredCar.getArmoredCar().getBodyColor().getRGB());
|
||||
}
|
||||
});
|
||||
|
||||
@ -92,30 +94,6 @@ public class FormArmoredCar extends JFrame{
|
||||
|
||||
setContentPane(mainPanel);
|
||||
setVisible(true);
|
||||
buttonCreate_Modif.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Random rnd = new Random();
|
||||
Color newColor = JColorChooser.showDialog(null, "Choose a color", Color.RED);
|
||||
Color newColorDop = JColorChooser.showDialog(null, "Choose a color", Color.RED);
|
||||
armoredCar = new DrawingTank(rnd.nextInt(100, 300), rnd.nextInt(1000,
|
||||
2000),
|
||||
newColor,
|
||||
newColorDop,
|
||||
1 == rnd.nextInt(0, 2), 1 == rnd.nextInt(0, 2));
|
||||
setData();
|
||||
}
|
||||
});
|
||||
buttonSelectArmoredCar.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (armoredCar != null) {
|
||||
selectedCar = armoredCar;
|
||||
DialogResult = true;
|
||||
dispose();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void createUIComponents() {
|
||||
@ -131,22 +109,4 @@ public class FormArmoredCar extends JFrame{
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public DrawingArmoredCar getSelectedCar() {
|
||||
return selectedCar;
|
||||
}
|
||||
|
||||
private void setData()
|
||||
{
|
||||
Random rnd = new Random();
|
||||
armoredCar.SetPosition(rnd.nextInt(10, 100), rnd.nextInt(10, 100), drawPanel.getWidth(), drawPanel.getHeight());
|
||||
labelSpeed.setText("Скорость: " + armoredCar.getArmoredCar().getSpeed());
|
||||
labelWeight.setText("Вес: " + armoredCar.getArmoredCar().getWeight());
|
||||
labelColor.setText("Цвет: " + armoredCar.getArmoredCar().getBodyColor().getRGB());
|
||||
}
|
||||
|
||||
public void setArmoredCar(DrawingArmoredCar armoredCar) {
|
||||
this.armoredCar = armoredCar;
|
||||
setData();
|
||||
}
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormGenericArmoredCar">
|
||||
<grid id="27dc6" binding="mainPanel" custom-create="true" layout-manager="GridLayoutManager" row-count="2" 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="833" height="459"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="6837" class="javax.swing.JButton" binding="createButton">
|
||||
<constraints>
|
||||
<grid row="1" 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>
|
||||
<hspacer id="8e062">
|
||||
<constraints>
|
||||
<grid row="1" column="0" 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="31893">
|
||||
<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"/>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
@ -1,83 +0,0 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.Random;
|
||||
|
||||
public class FormGenericArmoredCar extends JFrame{
|
||||
private JButton createButton;
|
||||
private JPanel mainPanel;
|
||||
GenericEntityArmoredCar<EntityArmoredCar, IDrawingCaterpillar> genericEntityArmoredCar;
|
||||
DrawingArmoredCar[] cars = new DrawingArmoredCar[3];
|
||||
|
||||
public FormGenericArmoredCar() {
|
||||
super("Форма с новым объектом");
|
||||
|
||||
setBounds(100, 100, 1000, 700);
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
|
||||
fill();
|
||||
createButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
for (int i = 0; i < 3; i++) {
|
||||
cars[i] = genericEntityArmoredCar.getDrawingObject();
|
||||
}
|
||||
setData();
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
setContentPane(mainPanel);
|
||||
setVisible(true);
|
||||
}
|
||||
private void fill() {
|
||||
genericEntityArmoredCar = new GenericEntityArmoredCar<>(10);
|
||||
for (int i = 0; i < 10; i++) {
|
||||
Random r = new Random();
|
||||
EntityArmoredCar armoredCar = new EntityArmoredCar(
|
||||
r.nextInt(1000, 2000),
|
||||
r.nextInt(1000, 2000),
|
||||
new Color(r.nextInt(256), r.nextInt(256), r.nextInt(256)));
|
||||
IDrawingCaterpillar[] realisations = new IDrawingCaterpillar[]{
|
||||
new DrawingCaterpillar(armoredCar.getBodyColor()),
|
||||
new DrawingCrossCaterpillar(armoredCar.getBodyColor()),
|
||||
new DrawingDoubleCaterpillar(armoredCar.getBodyColor())};
|
||||
IDrawingCaterpillar drawingCaterpillar = realisations[r.nextInt(3)];
|
||||
genericEntityArmoredCar.Insert(armoredCar);
|
||||
genericEntityArmoredCar.Insert(drawingCaterpillar);
|
||||
}
|
||||
}
|
||||
private void setData()
|
||||
{
|
||||
int x = mainPanel.getWidth() / 4;
|
||||
int y = mainPanel.getHeight() / 2;
|
||||
for (DrawingArmoredCar armoredCar :
|
||||
cars) {
|
||||
armoredCar.SetPosition(x, y, mainPanel.getWidth(), mainPanel.getHeight());
|
||||
x += 150;
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawCars(Graphics2D g) {
|
||||
for (DrawingArmoredCar armoredCar : cars) {
|
||||
if (armoredCar == null)
|
||||
return;
|
||||
armoredCar.DrawTransport(g);
|
||||
}
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
new FormGenericArmoredCar();
|
||||
}
|
||||
|
||||
private void createUIComponents() {
|
||||
mainPanel = new JPanel() {
|
||||
@Override
|
||||
public void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
DrawCars((Graphics2D) g);
|
||||
super.repaint();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
@ -1,129 +0,0 @@
|
||||
<?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="mainPanel" layout-manager="GridLayoutManager" row-count="4" column-count="5" 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="564" height="400"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="7cc9f" binding="drawPanel" custom-create="true" layout-manager="BorderLayout" hgap="0" vgap="0">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="5" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<background color="-1"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<grid id="e4749" layout-manager="GridLayoutManager" row-count="2" column-count="5" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="3" column="0" row-span="1" col-span="5" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="true"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="30a94" class="javax.swing.JButton" binding="buttonCreate">
|
||||
<constraints>
|
||||
<grid row="1" 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>
|
||||
<text value="Создать"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="e6875" class="javax.swing.JButton" binding="buttonRight">
|
||||
<constraints>
|
||||
<grid row="1" 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>
|
||||
<icon value="Right.png"/>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="81a7c" class="javax.swing.JButton" binding="buttonUp">
|
||||
<constraints>
|
||||
<grid row="0" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<enabled value="true"/>
|
||||
<hideActionText value="true"/>
|
||||
<icon value="Up.png"/>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="87a25" class="javax.swing.JButton" binding="buttonDown">
|
||||
<constraints>
|
||||
<grid row="1" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<icon value="Down.png"/>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="fee79" class="javax.swing.JButton" binding="buttonLeft">
|
||||
<constraints>
|
||||
<grid row="1" 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>
|
||||
<icon value="Left.png"/>
|
||||
<text value=""/>
|
||||
<visible value="true"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="2d428" class="javax.swing.JButton" binding="buttonCreate_Modif">
|
||||
<constraints>
|
||||
<grid row="1" 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>
|
||||
</children>
|
||||
</grid>
|
||||
<component id="54172" class="javax.swing.JLabel" binding="labelSpeed">
|
||||
<constraints>
|
||||
<grid row="2" 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="725a5" class="javax.swing.JLabel" binding="labelWeight">
|
||||
<constraints>
|
||||
<grid row="2" column="3" 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="46832" class="javax.swing.JLabel" binding="labelColor">
|
||||
<constraints>
|
||||
<grid row="2" column="4" 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="625" class="javax.swing.JComboBox" binding="mapSelectorComboBox">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<model>
|
||||
<item value="Простая карта"/>
|
||||
<item value="Карта 1"/>
|
||||
<item value="Карта 2"/>
|
||||
</model>
|
||||
</properties>
|
||||
</component>
|
||||
<hspacer id="9af30">
|
||||
<constraints>
|
||||
<grid row="0" column="1" 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>
|
||||
</grid>
|
||||
</form>
|
@ -1,149 +0,0 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ComponentAdapter;
|
||||
import java.awt.event.ComponentEvent;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.Objects;
|
||||
import java.util.Random;
|
||||
|
||||
public class FormMap extends JFrame {
|
||||
private JPanel drawPanel;
|
||||
private JButton buttonCreate;
|
||||
private JButton buttonRight;
|
||||
private JButton buttonUp;
|
||||
private JButton buttonDown;
|
||||
private JButton buttonLeft;
|
||||
private JButton buttonCreate_Modif;
|
||||
private JLabel labelSpeed;
|
||||
private JLabel labelWeight;
|
||||
private JLabel labelColor;
|
||||
private JComboBox mapSelectorComboBox;
|
||||
private JPanel mainPanel;
|
||||
|
||||
private AbstractMap abstractMap;
|
||||
private Image img;
|
||||
public FormMap() {
|
||||
super("Карта");
|
||||
abstractMap = new SimpleMap();
|
||||
|
||||
setBounds(100, 100, 700, 700);
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
|
||||
labelSpeed.setText("Скорость: ");
|
||||
labelWeight.setText("Вес: ");
|
||||
labelColor.setText("Цвет: ");
|
||||
|
||||
buttonCreate.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent actionEvent) {
|
||||
Random rnd = new Random();
|
||||
DrawingArmoredCar armoredCar = new DrawingArmoredCar(rnd.nextInt(100,300), rnd.nextInt(1000, 2000),
|
||||
new Color(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)));
|
||||
setData(armoredCar);
|
||||
}
|
||||
});
|
||||
|
||||
buttonUp.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent actionEvent) {
|
||||
if (abstractMap != null) {
|
||||
img = abstractMap.MoveObject(Direction.Up);
|
||||
drawPanel.repaint();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
buttonDown.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent actionEvent) {
|
||||
if (abstractMap != null) {
|
||||
img = abstractMap.MoveObject(Direction.Down);
|
||||
drawPanel.repaint();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
buttonLeft.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent actionEvent) {
|
||||
if (abstractMap != null) {
|
||||
img = abstractMap.MoveObject(Direction.Left);
|
||||
drawPanel.repaint();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
buttonRight.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent actionEvent) {
|
||||
if (abstractMap != null) {
|
||||
img = abstractMap.MoveObject(Direction.Right);
|
||||
drawPanel.repaint();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
setContentPane(mainPanel);
|
||||
setVisible(true);
|
||||
buttonCreate_Modif.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Random rnd = new Random();
|
||||
DrawingTank tank = new DrawingTank(rnd.nextInt(100, 300), rnd.nextInt(1000,
|
||||
2000),
|
||||
new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0,
|
||||
256)),
|
||||
new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0,
|
||||
256)),
|
||||
1==rnd.nextInt(0, 2), 1==rnd.nextInt(0, 2));
|
||||
setData(tank);
|
||||
}
|
||||
});
|
||||
mapSelectorComboBox.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
String name = (String) mapSelectorComboBox.getSelectedItem();
|
||||
switch (name)
|
||||
{
|
||||
case "Простая карта":
|
||||
abstractMap = new SimpleMap();
|
||||
break;
|
||||
case "Карта 1":
|
||||
abstractMap = new MyMapWooden();
|
||||
break;
|
||||
case "Карта 2":
|
||||
abstractMap = new MyMapLabyrinth();
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void createUIComponents() {
|
||||
drawPanel = new JPanel() {
|
||||
@Override
|
||||
public void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.drawImage(img, 0, 0, this);
|
||||
super.repaint();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private void setData(DrawingArmoredCar drawingArmoredCar)
|
||||
{
|
||||
if (abstractMap != null)
|
||||
img = abstractMap.CreateMap(drawPanel.getWidth(), drawPanel.getHeight(), new DrawingObjectArmoredCar(drawingArmoredCar));
|
||||
|
||||
labelSpeed.setText("Скорость: " + drawingArmoredCar.getArmoredCar().getSpeed());
|
||||
labelWeight.setText("Вес: " + drawingArmoredCar.getArmoredCar().getWeight());
|
||||
labelColor.setText("Цвет: " + drawingArmoredCar.getArmoredCar().getBodyColor().getRGB());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1,171 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormMapWithArmoredCars">
|
||||
<grid id="27dc6" binding="mainPanel" layout-manager="GridLayoutManager" row-count="2" 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="947" height="629"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="d36a5" binding="btnPanel" layout-manager="GridLayoutManager" row-count="13" 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="0" column="1" row-span="2" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<name value=""/>
|
||||
<toolTipText value=""/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="abbc4" class="javax.swing.JButton" binding="buttonAddArmoredCar">
|
||||
<constraints>
|
||||
<grid row="5" column="0" 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="ab78e" class="javax.swing.JButton" binding="buttonRemoveArmoredCar">
|
||||
<constraints>
|
||||
<grid row="7" column="0" 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="28eda" class="javax.swing.JButton" binding="buttonShowStorage">
|
||||
<constraints>
|
||||
<grid row="8" column="0" 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="633b9" class="javax.swing.JButton" binding="buttonShowOnMap">
|
||||
<constraints>
|
||||
<grid row="9" column="0" 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="30614" class="javax.swing.JTextField" binding="maskedTextBoxPosition">
|
||||
<constraints>
|
||||
<grid row="6" column="0" 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="4f2a5" class="javax.swing.JComboBox" binding="mapSelectorComboBox">
|
||||
<constraints>
|
||||
<grid row="1" column="0" 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="Карта 1"/>
|
||||
<item value="Карта 2"/>
|
||||
</model>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="bf66e" class="javax.swing.JButton" binding="buttonUp">
|
||||
<constraints>
|
||||
<grid row="11" 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>
|
||||
<enabled value="true"/>
|
||||
<hideActionText value="true"/>
|
||||
<icon value="Up.png"/>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="56422" class="javax.swing.JButton" binding="buttonDown">
|
||||
<constraints>
|
||||
<grid row="12" 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>
|
||||
<icon value="Down.png"/>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="f47b8" class="javax.swing.JButton" binding="buttonRight">
|
||||
<constraints>
|
||||
<grid row="12" 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>
|
||||
<icon value="Right.png"/>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="a0cfb" class="javax.swing.JButton" binding="buttonLeft">
|
||||
<constraints>
|
||||
<grid row="12" 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>
|
||||
<icon value="Left.png"/>
|
||||
<text value=""/>
|
||||
<visible value="true"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="b0b2e" class="javax.swing.JTextField" binding="textBoxNewMapName">
|
||||
<constraints>
|
||||
<grid row="0" column="0" 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="8adee" class="javax.swing.JButton" binding="AddMapButton">
|
||||
<constraints>
|
||||
<grid row="2" column="0" 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="e7216" class="javax.swing.JButton" binding="DeleteMapButton">
|
||||
<constraints>
|
||||
<grid row="4" column="0" 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="7099e" class="javax.swing.JList" binding="listBoxMaps">
|
||||
<constraints>
|
||||
<grid row="3" column="0" row-span="1" col-span="3" vsize-policy="6" hsize-policy="2" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="150" height="50"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<component id="ccba6" class="javax.swing.JButton" binding="lookDeletedButton">
|
||||
<constraints>
|
||||
<grid row="10" column="0" 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>
|
||||
</children>
|
||||
</grid>
|
||||
<hspacer id="da837">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
<grid id="e184c" binding="drawPanel" custom-create="true" 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>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
@ -1,241 +0,0 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Queue;
|
||||
|
||||
public class FormMapWithArmoredCars extends JFrame{
|
||||
private JButton buttonAddArmoredCar;
|
||||
private JButton buttonRemoveArmoredCar;
|
||||
private JButton buttonShowStorage;
|
||||
private JButton buttonShowOnMap;
|
||||
private JTextField maskedTextBoxPosition;
|
||||
private JComboBox mapSelectorComboBox;
|
||||
private JPanel drawPanel;
|
||||
private JButton buttonUp;
|
||||
private JButton buttonDown;
|
||||
private JButton buttonRight;
|
||||
private JButton buttonLeft;
|
||||
private JPanel mainPanel;
|
||||
private JPanel btnPanel;
|
||||
private JTextField textBoxNewMapName;
|
||||
private JButton AddMapButton;
|
||||
private JButton DeleteMapButton;
|
||||
private JList listBoxMaps;
|
||||
private JButton lookDeletedButton;
|
||||
|
||||
private Image img;
|
||||
|
||||
private final HashMap<String, AbstractMap> _mapsDict = new HashMap<>() {{
|
||||
put("Простая карта", new SimpleMap());
|
||||
put("Карта 1", new MyMapLabyrinth());
|
||||
put("Карта 2", new MyMapWooden());
|
||||
}};
|
||||
|
||||
private final MapsCollection _mapsCollection;
|
||||
private final Queue<DrawingObjectArmoredCar> queue = new LinkedList<>();
|
||||
|
||||
public FormMapWithArmoredCars() {
|
||||
super("Карта с набором объектов");
|
||||
|
||||
setBounds(100, 100, 1000, 700);
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
|
||||
mapSelectorComboBox.removeAllItems();
|
||||
for (var elem : _mapsDict.keySet())
|
||||
{
|
||||
mapSelectorComboBox.addItem(elem);
|
||||
}
|
||||
|
||||
buttonAddArmoredCar.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (listBoxMaps.getSelectedIndex() == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
FormArmoredCar form = new FormArmoredCar();
|
||||
form.addWindowListener(new WindowAdapter() {
|
||||
@Override
|
||||
public void windowDeactivated(WindowEvent e) {
|
||||
if (form.getSelectedCar() == null)
|
||||
return;
|
||||
DrawingObjectArmoredCar armoredCar = new DrawingObjectArmoredCar(form.getSelectedCar());
|
||||
if (_mapsCollection.get((String)listBoxMaps.getSelectedValue()).add(armoredCar) > -1)
|
||||
{
|
||||
if (form.DialogResult) {
|
||||
JOptionPane.showMessageDialog(null, "Объект добавлен");
|
||||
img = _mapsCollection.get((String) listBoxMaps.getSelectedValue()).ShowSet();
|
||||
repaint();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, "Не удалось добавить объект");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
buttonRemoveArmoredCar.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (maskedTextBoxPosition.getText().equals(""))
|
||||
{
|
||||
return;
|
||||
}
|
||||
int res = JOptionPane.showConfirmDialog (null,"Удалить объект?",
|
||||
"Удаление", JOptionPane.YES_NO_OPTION);
|
||||
if (res == JOptionPane.YES_OPTION) {
|
||||
int pos = Integer.parseInt(maskedTextBoxPosition.getText());
|
||||
DrawingObjectArmoredCar deletedArmoredCar = (DrawingObjectArmoredCar) _mapsCollection.get((String) listBoxMaps.getSelectedValue(), pos);
|
||||
if (_mapsCollection.get((String) listBoxMaps.getSelectedValue()).remove(pos) != null)
|
||||
{
|
||||
queue.add(deletedArmoredCar);
|
||||
JOptionPane.showMessageDialog(null, "Объект удален");
|
||||
img = _mapsCollection.get((String) listBoxMaps.getSelectedValue()).ShowSet();
|
||||
}
|
||||
else
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, "Не удалось удалить объект");
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
buttonShowStorage.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (_mapsCollection.get((String) listBoxMaps.getSelectedValue()) == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
img = _mapsCollection.get((String) listBoxMaps.getSelectedValue()).ShowSet();
|
||||
repaint();
|
||||
}
|
||||
});
|
||||
|
||||
buttonShowOnMap.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (_mapsCollection.get((String) listBoxMaps.getSelectedValue()) == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
img = _mapsCollection.get((String) listBoxMaps.getSelectedValue()).ShowOnMap();
|
||||
repaint();
|
||||
}
|
||||
});
|
||||
|
||||
setContentPane(mainPanel);
|
||||
setVisible(true);
|
||||
buttonLeft.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
img = _mapsCollection.get((String) listBoxMaps.getSelectedValue()).MoveObject(Direction.Left);
|
||||
repaint();
|
||||
}
|
||||
});
|
||||
buttonUp.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
img = _mapsCollection.get((String) listBoxMaps.getSelectedValue()).MoveObject(Direction.Up);
|
||||
repaint();
|
||||
}
|
||||
});
|
||||
buttonDown.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
img = _mapsCollection.get((String) listBoxMaps.getSelectedValue()).MoveObject(Direction.Down);
|
||||
repaint();
|
||||
}
|
||||
});
|
||||
buttonRight.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
img = _mapsCollection.get((String) listBoxMaps.getSelectedValue()).MoveObject(Direction.Right);
|
||||
repaint();
|
||||
}
|
||||
});
|
||||
AddMapButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (mapSelectorComboBox.getSelectedIndex() == -1 || textBoxNewMapName.getText().equals(""))
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, "Не все данные заполнены", "Ошибка", JOptionPane.ERROR_MESSAGE);
|
||||
return;
|
||||
}
|
||||
if (!_mapsDict.containsKey((String) mapSelectorComboBox.getSelectedItem()))
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, "Нет такой карты", "Ошибка", JOptionPane.ERROR_MESSAGE);
|
||||
return;
|
||||
}
|
||||
_mapsCollection.AddMap(textBoxNewMapName.getText(), _mapsDict.get((String) mapSelectorComboBox.getSelectedItem()));
|
||||
ReloadMaps();
|
||||
}
|
||||
});
|
||||
_mapsCollection = new MapsCollection(drawPanel.getWidth(), drawPanel.getHeight());
|
||||
|
||||
listBoxMaps.addListSelectionListener(e -> {
|
||||
if (listBoxMaps.getSelectedValue() != null) {
|
||||
img = _mapsCollection.get((String) listBoxMaps.getSelectedValue()).ShowSet();
|
||||
repaint();
|
||||
}
|
||||
});
|
||||
|
||||
DeleteMapButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (listBoxMaps.getSelectedIndex() == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (JOptionPane.showConfirmDialog(null, "Удалить карту" +
|
||||
listBoxMaps.getSelectedValue()+ "?", "Удаление", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)
|
||||
{
|
||||
_mapsCollection.DelMap((String) listBoxMaps.getSelectedValue());
|
||||
ReloadMaps();
|
||||
}
|
||||
}
|
||||
});
|
||||
lookDeletedButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
|
||||
if (!queue.isEmpty()) {
|
||||
FormArmoredCar form = new FormArmoredCar();
|
||||
form.setArmoredCar(queue.poll().getArmoredCar());
|
||||
}
|
||||
else
|
||||
JOptionPane.showMessageDialog(null, "Нет удаленных объектов");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void createUIComponents() {
|
||||
drawPanel = new JPanel() {
|
||||
@Override
|
||||
public void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.drawImage(img, 0, 0, this);
|
||||
super.repaint();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private void ReloadMaps() {
|
||||
int index = listBoxMaps.getSelectedIndex();
|
||||
listBoxMaps.setListData(_mapsCollection.getKeys().toArray(new Object[0]));
|
||||
if (listBoxMaps.getModel().getSize() > 0 && (index == -1 || index >=
|
||||
listBoxMaps.getModel().getSize()))
|
||||
{
|
||||
listBoxMaps.setSelectedIndex(0);
|
||||
}
|
||||
else if (listBoxMaps.getModel().getSize() > 0 && index > -1 && index <
|
||||
listBoxMaps.getModel().getSize())
|
||||
{
|
||||
listBoxMaps.setSelectedIndex(index);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
import java.util.Random;
|
||||
|
||||
public class GenericEntityArmoredCar<T extends EntityArmoredCar, U extends IDrawingCaterpillar> {
|
||||
private T[] armoredCars;
|
||||
private int carsCount = 0;
|
||||
private U[] caterpillars;
|
||||
private int caterpillarsCount = 0;
|
||||
|
||||
public GenericEntityArmoredCar(int numberObjects) {
|
||||
this.armoredCars = (T[]) new EntityArmoredCar[numberObjects];
|
||||
this.caterpillars = (U[]) new IDrawingCaterpillar[numberObjects];
|
||||
}
|
||||
|
||||
public void Insert(T armoredCar)
|
||||
{
|
||||
if (carsCount >= armoredCars.length)
|
||||
return;
|
||||
armoredCars[carsCount++] = armoredCar;
|
||||
}
|
||||
|
||||
public void Insert(U caterpillar)
|
||||
{
|
||||
if (caterpillarsCount >= caterpillars.length)
|
||||
return;
|
||||
caterpillars[caterpillarsCount++] = caterpillar;
|
||||
}
|
||||
|
||||
public DrawingArmoredCar getDrawingObject() {
|
||||
Random r = new Random();
|
||||
EntityArmoredCar armoredCar = armoredCars[r.nextInt(carsCount)];
|
||||
IDrawingCaterpillar caterpillar = caterpillars[r.nextInt(caterpillarsCount)];
|
||||
DrawingArmoredCar o = new DrawingArmoredCar(armoredCar.getSpeed(), armoredCar.getWeight(), armoredCar.getBodyColor());
|
||||
o.SetCaterpillar(caterpillar);
|
||||
return o;
|
||||
}
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
import java.awt.*;
|
||||
|
||||
public interface IDrawingCaterpillar {
|
||||
void setNumRinks(int n);
|
||||
|
||||
void DrawCaterpillar(Graphics2D g2d, int startPosX, int startPosY);
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
import java.awt.*;
|
||||
import java.util.HashMap;
|
||||
|
||||
public interface IDrawingObject {
|
||||
float getStep();
|
||||
|
||||
void SetObject(int x, int y, int width, int height);
|
||||
|
||||
void MoveObject(Direction direction);
|
||||
|
||||
void DrawingObject(Graphics2D g);
|
||||
|
||||
HashMap<String, Float> GetCurrentPosition();
|
||||
}
|
@ -1,146 +0,0 @@
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
public class MapWithSetArmoredCarsGeneric<T extends IDrawingObject, U extends AbstractMap> {
|
||||
|
||||
private int _pictureWidth;
|
||||
|
||||
private int _pictureHeight;
|
||||
|
||||
private int _placeSizeWidth = 210;
|
||||
|
||||
private int _placeSizeHeight = 110;
|
||||
|
||||
private SetArmoredCarsGeneric<T> _setCars;
|
||||
|
||||
private U _map;
|
||||
|
||||
public MapWithSetArmoredCarsGeneric(int picWidth, int picHeight, U map)
|
||||
{
|
||||
int width = picWidth / _placeSizeWidth;
|
||||
int height = picHeight / _placeSizeHeight;
|
||||
_setCars = new SetArmoredCarsGeneric<T>(width * height);
|
||||
_pictureWidth = picWidth;
|
||||
_pictureHeight = picHeight;
|
||||
_map = map;
|
||||
}
|
||||
|
||||
public int add(T car)
|
||||
{
|
||||
return _setCars.Insert(car);
|
||||
}
|
||||
|
||||
public T remove(int position)
|
||||
{
|
||||
return _setCars.Remove(position);
|
||||
}
|
||||
|
||||
public Image ShowSet()
|
||||
{
|
||||
Image bmp = new BufferedImage(_pictureWidth, _pictureHeight, BufferedImage.TYPE_INT_BGR);
|
||||
Graphics gr = bmp.getGraphics();
|
||||
DrawBackground(gr);
|
||||
DrawArmoredCars(gr);
|
||||
return bmp;
|
||||
}
|
||||
|
||||
public Image ShowOnMap()
|
||||
{
|
||||
Shaking();
|
||||
for (var armoredCar : _setCars.GetArmoredCars())
|
||||
{
|
||||
return _map.CreateMap(_pictureWidth, _pictureHeight, armoredCar);
|
||||
}
|
||||
return new BufferedImage(_pictureWidth, _pictureHeight, BufferedImage.TYPE_INT_BGR);
|
||||
}
|
||||
|
||||
public Image MoveObject(Direction direction)
|
||||
{
|
||||
if (_map != null)
|
||||
{
|
||||
return _map.MoveObject(direction);
|
||||
}
|
||||
return new BufferedImage(_pictureWidth, _pictureHeight, BufferedImage.TYPE_INT_BGR);
|
||||
}
|
||||
|
||||
private void Shaking()
|
||||
{
|
||||
int j = _setCars.getCount() - 1;
|
||||
for (int i = 0; i < _setCars.getCount(); i++)
|
||||
{
|
||||
if (_setCars.Get(i) == null)
|
||||
{
|
||||
for (; j > i; j--)
|
||||
{
|
||||
var car = _setCars.Get(j);
|
||||
if (car != null)
|
||||
{
|
||||
_setCars.Insert(car, i);
|
||||
_setCars.Remove(j);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (j <= i)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawBackground(Graphics g)
|
||||
{
|
||||
Color colorRoad = Color.GRAY;
|
||||
Color colorBox = new Color(110, 69, 19, 255);
|
||||
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
|
||||
{
|
||||
for (int j = 0; j < _pictureHeight / _placeSizeHeight; j++)
|
||||
{
|
||||
g.setColor(colorRoad);
|
||||
g.fillRect(i * _placeSizeWidth, j * _placeSizeHeight, _placeSizeWidth, _placeSizeHeight);
|
||||
|
||||
g.setColor(colorBox);
|
||||
int boxSize = _placeSizeWidth / 7;
|
||||
g.fillRect(i * _placeSizeWidth + _placeSizeWidth / 2,
|
||||
j * _placeSizeHeight + _placeSizeHeight / 5, boxSize, boxSize);
|
||||
|
||||
g.fillRect(i * _placeSizeWidth + _placeSizeWidth / 2 - boxSize / 2,
|
||||
j * _placeSizeHeight + _placeSizeHeight / 5 + boxSize, boxSize, boxSize);
|
||||
|
||||
g.fillRect(i * _placeSizeWidth + _placeSizeWidth / 2 + boxSize / 2,
|
||||
j * _placeSizeHeight + _placeSizeHeight / 5 + boxSize, boxSize, boxSize);
|
||||
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawLine(i * _placeSizeWidth, j * _placeSizeHeight,
|
||||
i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight);
|
||||
|
||||
g.drawRect(i * _placeSizeWidth + _placeSizeWidth / 2,
|
||||
j * _placeSizeHeight + _placeSizeHeight / 5, boxSize, boxSize);
|
||||
|
||||
g.drawRect( i * _placeSizeWidth + _placeSizeWidth / 2 - boxSize / 2,
|
||||
j * _placeSizeHeight + _placeSizeHeight / 5 + boxSize, boxSize, boxSize);
|
||||
|
||||
g.drawRect( i * _placeSizeWidth + _placeSizeWidth / 2 + boxSize / 2,
|
||||
j * _placeSizeHeight + _placeSizeHeight / 5 + boxSize, boxSize, boxSize);
|
||||
}
|
||||
g.drawLine(i * _placeSizeWidth, 0, i * _placeSizeWidth,
|
||||
(_pictureHeight / _placeSizeHeight) * _placeSizeHeight);
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawArmoredCars(Graphics g)
|
||||
{
|
||||
int width = _pictureWidth / _placeSizeWidth;
|
||||
int i = 0;
|
||||
for (var armoredCar : _setCars.GetArmoredCars())
|
||||
{
|
||||
armoredCar.SetObject(i % width * _placeSizeWidth + 5, i / width * _placeSizeHeight + 10, _pictureWidth, _pictureHeight);
|
||||
armoredCar.DrawingObject((Graphics2D) g);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
public SetArmoredCarsGeneric<T> get_setCars() {
|
||||
return _setCars;
|
||||
}
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class MapsCollection {
|
||||
public HashMap<String, MapWithSetArmoredCarsGeneric<IDrawingObject, AbstractMap>> _mapStorages;
|
||||
private int _pictureWidth;
|
||||
private int _pictureHeight;
|
||||
|
||||
public MapsCollection(int pictureWidth, int pictureHeight)
|
||||
{
|
||||
_mapStorages = new HashMap<>();
|
||||
_pictureWidth = pictureWidth;
|
||||
_pictureHeight = pictureHeight;
|
||||
}
|
||||
|
||||
public Set<String> getKeys() {
|
||||
return _mapStorages.keySet();
|
||||
}
|
||||
|
||||
public void AddMap(String name, AbstractMap map)
|
||||
{
|
||||
if (!getKeys().contains(name))
|
||||
_mapStorages.put(name, new MapWithSetArmoredCarsGeneric<>(_pictureWidth, _pictureHeight, map));
|
||||
}
|
||||
|
||||
public void DelMap(String name)
|
||||
{
|
||||
if (getKeys().contains(name))
|
||||
_mapStorages.remove(name);
|
||||
}
|
||||
|
||||
public MapWithSetArmoredCarsGeneric<IDrawingObject, AbstractMap> get(String ind)
|
||||
{
|
||||
if (getKeys().contains(ind))
|
||||
return _mapStorages.get(ind);
|
||||
return null;
|
||||
}
|
||||
// дополнительное задание: метод "индексатор" с двумя параметрами
|
||||
public IDrawingObject get(String ind1, int pos) {
|
||||
if (_mapStorages.containsKey(ind1))
|
||||
return _mapStorages.get(ind1).get_setCars().Get(pos);
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,65 +0,0 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class MyMapLabyrinth extends AbstractMap{
|
||||
private final Color barrierColor = Color.BLUE;
|
||||
private final Color roadColor = Color.BLACK;
|
||||
@Override
|
||||
protected void GenerateMap() {
|
||||
map = new int[50][50];
|
||||
size_x = (float)width / map.length;
|
||||
size_y = (float)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 < 20)
|
||||
{
|
||||
int x = random.nextInt(0, 50);
|
||||
int y = random.nextInt(0, 50);
|
||||
int number = random.nextInt(1, 16);
|
||||
if (counter < 5) {
|
||||
if (number + x > map.length)
|
||||
{
|
||||
number = map.length - x - 1;
|
||||
}
|
||||
for (int i = x; i < x + number; ++i)
|
||||
{
|
||||
map[i][y] = _barrier;
|
||||
}
|
||||
} else
|
||||
{
|
||||
if (number + y > map[0].length)
|
||||
{
|
||||
number = map[0].length - y - 1;
|
||||
}
|
||||
for (int i = y; i < y + number; ++i)
|
||||
{
|
||||
map[x][i] = _barrier;
|
||||
}
|
||||
}
|
||||
counter++;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void DrawRoadPart(Graphics2D g, int i, int j) {
|
||||
g.setColor(roadColor);
|
||||
int new_size_x = Math.round(size_x);
|
||||
int new_size_y = Math.round(size_y);
|
||||
g.fillRect(i * new_size_x, j * new_size_y, new_size_x, new_size_y);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void DrawBarrierPart(Graphics2D g, int i, int j) {
|
||||
g.setColor(barrierColor);
|
||||
int new_size_x = Math.round(size_x);
|
||||
int new_size_y = Math.round(size_y);
|
||||
g.fillRect(i * new_size_x, j * new_size_y, new_size_x, new_size_y);
|
||||
}
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class MyMapWooden extends AbstractMap{
|
||||
private final Color barrierColor = new Color(45, 77, 44);
|
||||
private final Color roadColor = new Color(105, 70, 35);
|
||||
@Override
|
||||
protected void GenerateMap() {
|
||||
map = new int[10][10];
|
||||
size_x = (float)width / map.length;
|
||||
size_y = (float)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 < 10)
|
||||
{
|
||||
int x = random.nextInt(10);
|
||||
int y = random.nextInt(10);
|
||||
if (map[x][y] == _freeRoad)
|
||||
{
|
||||
map[x][y] = _barrier;
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void DrawRoadPart(Graphics2D g, int i, int j) {
|
||||
g.setColor(roadColor);
|
||||
int new_size_x = Math.round(size_x);
|
||||
int new_size_y = Math.round(size_y);
|
||||
g.fillRect(i * new_size_x, j * new_size_y, new_size_x, new_size_y);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void DrawBarrierPart(Graphics2D g, int i, int j) {
|
||||
g.setColor(barrierColor);
|
||||
int new_size_x = Math.round(size_x);
|
||||
int new_size_y = Math.round(size_y);
|
||||
g.fillRect(i * new_size_x, j * new_size_y, new_size_x, new_size_y);
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
public class Program {
|
||||
public static void main(String[] args) {
|
||||
new FormMapWithArmoredCars();
|
||||
new FormArmoredCar();
|
||||
}
|
||||
}
|
||||
|
@ -1,51 +0,0 @@
|
||||
import java.util.*;
|
||||
|
||||
public class SetArmoredCarsGeneric<T> {
|
||||
private ArrayList<T> _places;
|
||||
private int maxCount;
|
||||
|
||||
public SetArmoredCarsGeneric(int count)
|
||||
{
|
||||
_places = new ArrayList<T>();
|
||||
maxCount = count;
|
||||
}
|
||||
|
||||
public int getCount() {
|
||||
return _places != null ? _places.size() : 0;
|
||||
}
|
||||
|
||||
public int Insert(T armoredCar)
|
||||
{
|
||||
return Insert(armoredCar, 0);
|
||||
}
|
||||
|
||||
public int Insert(T armoredCar, int position)
|
||||
{
|
||||
if (getCount() >= maxCount || position < 0 || position >= maxCount)
|
||||
return -1;
|
||||
|
||||
_places.add(position, armoredCar);
|
||||
return position;
|
||||
}
|
||||
|
||||
public T Remove(int position)
|
||||
{
|
||||
if (position < 0 || position >= _places.size())
|
||||
return null;
|
||||
T armoredCar = _places.get(position);
|
||||
_places.remove(position);
|
||||
return armoredCar;
|
||||
}
|
||||
|
||||
public T Get(int position)
|
||||
{
|
||||
if (position < 0 || position >= maxCount)
|
||||
return null;
|
||||
return _places.get(position);
|
||||
}
|
||||
|
||||
public Iterable<T> GetArmoredCars()
|
||||
{
|
||||
return () -> _places.stream().filter(Objects::nonNull).iterator();
|
||||
}
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class SimpleMap extends AbstractMap{
|
||||
private final Color barrierColor = Color.BLACK;
|
||||
private final Color roadColor = Color.DARK_GRAY;
|
||||
@Override
|
||||
protected void GenerateMap() {
|
||||
map = new int[100][100];
|
||||
size_x = (float)width / map.length;
|
||||
size_y = (float)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(100);
|
||||
int y = random.nextInt(100);
|
||||
if (map[x][y] == _freeRoad)
|
||||
{
|
||||
map[x][y] = _barrier;
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void DrawRoadPart(Graphics2D g, int i, int j) {
|
||||
g.setColor(roadColor);
|
||||
int new_size_x = Math.round(size_x);
|
||||
int new_size_y = Math.round(size_y);
|
||||
g.fillRect(i * new_size_x, j * new_size_y, new_size_x, new_size_y);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void DrawBarrierPart(Graphics2D g, int i, int j) {
|
||||
g.setColor(barrierColor);
|
||||
int new_size_x = Math.round(size_x);
|
||||
int new_size_y = Math.round(size_y);
|
||||
g.fillRect(i * new_size_x, j * new_size_y, new_size_x, new_size_y);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user