Compare commits

..

13 Commits

Author SHA1 Message Date
Макс Бондаренко
097cb7f944 готово 4 2022-12-15 22:31:51 +04:00
Макс Бондаренко
30e3d67aeb готово 3 2022-12-15 22:28:43 +04:00
Макс Бондаренко
1dc780afc9 название 2022-11-30 10:32:51 +04:00
Макс Бондаренко
c7d2376962 исправил перемещение 2022-11-29 22:32:20 +04:00
Макс Бондаренко
e822561eec исправил 2022-11-29 22:21:03 +04:00
Макс Бондаренко
1703457b15 готово 2022-11-29 22:18:43 +04:00
Макс Бондаренко
6c8db7840d астракт мапу добавил 2022-11-29 19:01:22 +04:00
Макс Бондаренко
ce917ced05 астракт мапу добавил 2022-11-29 18:58:13 +04:00
Макс Бондаренко
82055e73fe интерфейс 2022-11-29 00:27:51 +04:00
Макс Бондаренко
e5a1bec005 модификация добавленна 2022-11-29 00:17:16 +04:00
Макс Бондаренко
1c30871417 rework construction 2022-11-28 23:26:56 +04:00
Макс Бондаренко
60e488021c rework Jpanel 2022-11-28 23:18:52 +04:00
Макс Бондаренко
c36ffe6688 Suck_Pop 2022-11-16 18:24:14 +04:00
37 changed files with 2679 additions and 2 deletions

View File

@ -2,7 +2,9 @@
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager">
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" project-jdk-name="openjdk-19" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

115
AbstractMap.java Normal file
View File

@ -0,0 +1,115 @@
import java.awt.*;
import java.awt.image.BufferedImage;
import java.util.Random;
public abstract class AbstractMap {
private IDrawningObject _drawningObject = null;
protected int[][] _map = null;
protected int _width;
protected int _height;
protected float _size_x;
protected float _size_y;
protected Random _random = new Random();
protected int _freeRoad = 0;
protected int _barrier = 1;
public BufferedImage CreateMap(int width, int height, IDrawningObject drawningObject)
{
_width = width;
_height = height;
_drawningObject = drawningObject;
GenerateMap();
while (!SetObjectOnMap())
{
GenerateMap();
}
return DrawMapWithObject();
}
private boolean CanMove(float[] position) //Проверка на возможность шага
{
for (int i = (int)(position[2] / _size_y); i <= (int)(position[3] / _size_y); ++i)
{
for (int j = (int)(position[0] / _size_x); j <= (int)(position[1] / _size_x); ++j)
{
if (i >= 0 && j >= 0 && i < _map.length && j < _map[0].length && _map[i][j] == _barrier) return false;
}
}
return true;
}
public BufferedImage MoveObject(Direction direction)
{
float[] position = _drawningObject.GetCurrentPosition();
if (direction == Direction.Left)
{
position[0] -= _drawningObject.getStep();
}
else if (direction == Direction.Right)
{
position[1] += _drawningObject.getStep();
}
else if (direction == Direction.Up)
{
position[2] -= _drawningObject.getStep();
}
else if (direction == Direction.Down)
{
position[3] += _drawningObject.getStep();
}
if (CanMove(position))
{
_drawningObject.MoveObject(direction);
}
return DrawMapWithObject();
}
private boolean SetObjectOnMap()
{
if (_drawningObject == null || _map == null)
{
return false;
}
int x = _random.nextInt(0, 10);
int y = _random.nextInt(0, 10);
_drawningObject.SetObject(x, y, _width, _height);
for (int i = (int)(_drawningObject.GetCurrentPosition()[2] / _size_y); i <= (int)(_drawningObject.GetCurrentPosition()[3] / _size_y); ++i)
{
for (int j = (int)(_drawningObject.GetCurrentPosition()[0] / _size_x); j <= (int)(_drawningObject.GetCurrentPosition()[1] / _size_x); ++j)
{
if (_map[i][j] == _barrier) _map[i][j] = _freeRoad;
}
}
return true;
}
public BufferedImage DrawMapWithObject()
{
BufferedImage bmp = new BufferedImage(_width, _height, BufferedImage.TYPE_INT_RGB);
if (_drawningObject == null || _map == null)
{
return bmp;
}
Graphics g = bmp.getGraphics();
for (int i = 0; i < _map.length; ++i)
{
for (int j = 0; j < _map[0].length; ++j)
{
if (_map[i][j] == _freeRoad)
{
DrawRoadPart(g, i, j);
}
else if (_map[i][j] == _barrier)
{
DrawBarrierPart(g, i, j);
}
}
}
_drawningObject.DrawningObject(g);
return bmp;
}
protected abstract void GenerateMap();
protected abstract void DrawRoadPart(Graphics g, int i, int j);
protected abstract void DrawBarrierPart(Graphics g, int i, int j);
}

22
Deck.java Normal file
View File

@ -0,0 +1,22 @@
public enum Deck {
One(1),
Two(2),
Three(3);
Deck(int i) {
}
public static Deck GetDeck(int i){
switch (i)
{
case 1:
return One;
case 2:
return Two;
case 3:
return Three;
}
return null;
}
}

10
Direction.java Normal file
View File

@ -0,0 +1,10 @@
public enum Direction {
None(0), //None
Left(1), //Влево
Up(2), //Вверх
Right(3), //Вправо
Down(4); //Вниз
Direction(int i) {
}
}

32
DrawDeck.java Normal file
View File

@ -0,0 +1,32 @@
import java.awt.*;
public class DrawDeck implements IDrawningDeck {
private Deck deckCount;
@Override
public void SetDeckCount(int count){
deckCount = Deck.GetDeck(count);
}
@Override
public void DrawningDeck(float _startPosX, float _startPosY, int _warmlyShipWidth, Graphics2D g2d, Color bodyColor){
int count = 1;
switch (deckCount)
{
case One:
break;
case Two:
count = 2;
break;
case Three:
count = 3;
break;
}
for (int i = 1; i < count; ++i){
g2d.setColor(bodyColor);
g2d.fillRect((int)(_startPosX + _warmlyShipWidth / 5), (int)_startPosY - 20 * i, _warmlyShipWidth * 3 / 5, 20);
g2d.setColor(Color.BLACK);
g2d.drawRect((int)(_startPosX + _warmlyShipWidth / 5), (int)_startPosY - 20 * i, _warmlyShipWidth * 3 / 5, 20);
}
}
}

32
DrawGuns.java Normal file
View File

@ -0,0 +1,32 @@
import java.awt.*;
public class DrawGuns implements IDrawningDeck {
private Deck gunsCount;
@Override
public void SetDeckCount(int count) {
gunsCount = Deck.GetDeck(count);
}
@Override
public void DrawningDeck(float _startPosX, float _startPosY, int _warmlyShipWidth, Graphics2D g2d, Color bodyColor) {
int count = 1;
switch (gunsCount)
{
case One:
break;
case Two:
count = 2;
break;
case Three:
count = 3;
break;
}
g2d.setColor(Color.DARK_GRAY);
for (int i = 0; i < count; ++i)
{
g2d.fillPolygon(new Polygon(new int[]{(int)(_startPosX + _warmlyShipWidth / 5 * (i + 1)) + 10, (int)(_startPosX + _warmlyShipWidth / 5 * (i + 1)) + 25, (int)(_startPosX + _warmlyShipWidth / 5 * (i + 1)) + 40, (int)(_startPosX + _warmlyShipWidth / 5 * (i + 1)) + 25}, new int[]{(int)_startPosY - 20, (int)_startPosY - 10, (int)_startPosY - 30, (int)_startPosY - 40}, 4));
g2d.fillOval((int)(_startPosX + _warmlyShipWidth / 5 * (i + 1)), (int)_startPosY - 20, 25, 20);
}
}
}

32
DrawOvalDeck.java Normal file
View File

@ -0,0 +1,32 @@
import java.awt.*;
public class DrawOvalDeck implements IDrawningDeck{
private Deck deckCount;
@Override
public void SetDeckCount(int count) {
deckCount = Deck.GetDeck(count);
}
@Override
public void DrawningDeck(float _startPosX, float _startPosY, int _warmlyShipWidth, Graphics2D g2d, Color bodyColor) {
int count = 1;
switch (deckCount)
{
case One:
break;
case Two:
count = 2;
break;
case Three:
count = 3;
break;
}
for (int i = 1; i < count; ++i){
g2d.setColor(bodyColor);
g2d.fillOval((int)(_startPosX + _warmlyShipWidth / 5), (int)_startPosY - 20 * i, _warmlyShipWidth * 3 / 5, 20);
g2d.setColor(Color.BLACK);
g2d.drawOval((int)(_startPosX + _warmlyShipWidth / 5), (int)_startPosY - 20 * i, _warmlyShipWidth * 3 / 5, 20);
}
}
}

136
DrawingShip.java Normal file
View File

@ -0,0 +1,136 @@
import javax.swing.*;
import java.awt.*;
import java.util.*;
public class DrawingShip extends JPanel {
public EntityWarmlyShip warmlyShip; //Класс-сущность
public EntityWarmlyShip GetWarmlyShip(){return warmlyShip;}
public float _startPosX; //Координаты отрисовки по оси x
public float _startPosY; //Координаты отрисовки по оси y
private Integer _pictureWidth = null; //Ширина окна
private Integer _pictureHeight = null; //Высота окна
protected int _warmlyShipWidth = 125; //Ширина отрисовки корабля
protected int _warmlyShipHeight = 50; //Высота отрисовки корабля
private IDrawningDeck idd;
//Инициализация
public DrawingShip(int speed, float weight, Color bodyColor)
{
warmlyShip = new EntityWarmlyShip(speed, weight, bodyColor);
Random random = new Random();
switch (random.nextInt(3))
{
case 0:
idd = new DrawDeck();
break;
case 1:
idd = new DrawGuns();
break;
case 2:
idd = new DrawOvalDeck();
break;
}
idd.SetDeckCount(random.nextInt(1, 4));
}
public DrawingShip(EntityWarmlyShip ship, IDrawningDeck deck)
{
warmlyShip = ship;
idd = deck;
}
protected DrawingShip(int speed, float weight, Color bodyColor, int warmlyWidth, int warmlyHeight)
{
this(speed, weight, bodyColor);
_warmlyShipWidth = warmlyWidth;
_warmlyShipHeight = warmlyHeight;
}
//Начальные коордитанты
public void SetPosition(int x, int y, int width, int height)
{
if (width < _warmlyShipWidth || height < _warmlyShipHeight) return;
Random random = new Random();
_startPosX = x < 0 || x + _warmlyShipWidth > width ? random.nextFloat(0, width - _warmlyShipWidth) : x;
_startPosY = y < 0 || y + _warmlyShipHeight > height ? random.nextFloat(0, height - _warmlyShipHeight) : y;
_pictureWidth = width;
_pictureHeight = height;
}
//Движение транспорта по координатам
public void MoveTransport(Direction direction)
{
if (_pictureWidth == null || _pictureHeight == null) return;
switch (direction)
{
case Left: //Влево
if (_startPosX - warmlyShip.GetStep() > 0) _startPosX -= warmlyShip.GetStep();
break;
case Up: //Вверх
if (_startPosY - warmlyShip.GetStep() > 0) _startPosY -= warmlyShip.GetStep();
break;
case Right: //Вправо
if (_startPosX + _warmlyShipWidth + warmlyShip.GetStep() < _pictureWidth) _startPosX += warmlyShip.GetStep();
break;
case Down: //Вниз
if (_startPosY + _warmlyShipHeight + warmlyShip.GetStep() < _pictureHeight) _startPosY += warmlyShip.GetStep();
break;
}
}
//Отрисовка транспорта
public void DrawTransport(Graphics g)
{
if (GetWarmlyShip() == null) return;
if (_startPosX < 0 || _startPosY < 0 || _pictureWidth == null || _pictureHeight == null)
{
return;
}
Graphics2D g2d = (Graphics2D) g;
g2d.setColor(warmlyShip.GetBodyColor());
int[] xPol = new int[] {(int)(_startPosX), (int)(_startPosX + _warmlyShipWidth), (int)(_startPosX + _warmlyShipWidth - 25), (int)(_startPosX + 25)};
int[] yPol = new int[] {(int)(_startPosY + 20), (int)(_startPosY + 20), (int)(_startPosY + _warmlyShipHeight), (int)(_startPosY + _warmlyShipHeight)};
g2d.fillPolygon(new Polygon(xPol, yPol, xPol.length));
g2d.fillRect((int)(_startPosX + _warmlyShipWidth / 5), (int)_startPosY, _warmlyShipWidth * 3 / 5, 20);
g2d.setColor(Color.CYAN);
g2d.fillOval((int)(_startPosX + _warmlyShipWidth / 5), (int)_startPosY + 25, 20, 20);
g2d.fillOval((int)(_startPosX + _warmlyShipWidth * 3 / 5 + 5), (int)_startPosY + 25, 20, 20);
g2d.fillOval((int)(_startPosX + _warmlyShipWidth * 2 / 5 + 2.5f), (int)_startPosY + 25, 20, 20);
g2d.setColor(Color.BLACK);
g2d.drawPolygon(new Polygon(xPol, yPol, xPol.length));
g2d.drawRect((int)(_startPosX + _warmlyShipWidth / 5), (int)(_startPosY), _warmlyShipWidth * 3 / 5, 20);
g2d.setColor(Color.BLUE);
g2d.drawOval((int)(_startPosX + _warmlyShipWidth / 5), (int)_startPosY + 25, 20, 20);
g2d.drawOval((int)(_startPosX + _warmlyShipWidth * 3 / 5 + 5), (int)_startPosY + 25, 20, 20);
g2d.drawOval((int)(_startPosX + _warmlyShipWidth * 2 / 5 + 2.5f), (int)_startPosY + 25, 20, 20);
idd.DrawningDeck(_startPosX, _startPosY, _warmlyShipWidth, g2d, warmlyShip.GetBodyColor());
}
//Изменение границ отрисовки
public void ChangeBorders(int width, int height)
{
_pictureWidth = width;
_pictureHeight = height;
if (_pictureWidth <= _warmlyShipWidth || _pictureHeight <= _warmlyShipHeight)
{
_pictureWidth = null;
_pictureHeight = null;
return;
}
if (_startPosX + _warmlyShipWidth > _pictureWidth)
{
_startPosX = _pictureWidth - _warmlyShipWidth;
}
if (_startPosY + _warmlyShipHeight > _pictureHeight)
{
_startPosY = _pictureHeight - _warmlyShipHeight;
}
}
public float[] GetCurrentPosition() {
return new float[]{_startPosX, _startPosX + _warmlyShipWidth, _startPosY, _startPosY + _warmlyShipHeight};
}
}

50
DrawningMotorShip.java Normal file
View File

@ -0,0 +1,50 @@
import java.awt.*;
public class DrawningMotorShip extends DrawingShip {
public DrawningMotorShip(int speed, float weight, Color bodyColor, Color dopColor, boolean tubes, boolean cistern)
{
super(speed, weight, bodyColor, 150, 75);
warmlyShip = new EntityMotorShip(speed, weight, bodyColor, dopColor, tubes , cistern);
}
public DrawningMotorShip(EntityWarmlyShip ship, IDrawningDeck deck){
super(ship, deck);
warmlyShip = ship;
}
@Override
public void DrawTransport(Graphics g)
{
if (!(warmlyShip instanceof EntityMotorShip motorShip))
{
return;
}
Graphics2D g2d = (Graphics2D) g;
g2d.setColor(Color.BLACK);
g2d.setColor(motorShip.GetDopColor());
if (motorShip.GetTubes())
{
g2d.setColor(motorShip.GetDopColor());
g2d.fillRect((int)_startPosX + _warmlyShipWidth / 5, (int)_startPosY, _warmlyShipWidth / 5, _warmlyShipHeight / 2);
g2d.setColor(Color.BLACK);
g2d.drawRect((int)_startPosX + _warmlyShipWidth / 5, (int)_startPosY, _warmlyShipWidth / 5, _warmlyShipHeight / 2);
g2d.setColor(motorShip.GetDopColor());
g2d.fillRect((int)_startPosX + _warmlyShipWidth * 3 / 5, (int)_startPosY, _warmlyShipWidth / 5, _warmlyShipHeight / 2);
g2d.setColor(Color.BLACK);
g2d.drawRect((int)_startPosX + _warmlyShipWidth * 3 / 5, (int)_startPosY, _warmlyShipWidth / 5, _warmlyShipHeight / 2);
}
_startPosY += 25;
super.DrawTransport(g);
_startPosY -= 25;
if (motorShip.GetCistern())
{
g2d.setColor(motorShip.GetDopColor());
g2d.fillOval((int)_startPosX, (int)_startPosY + 25, 25, 20);
g2d.setColor(Color.BLACK);
g2d.drawOval((int)_startPosX, (int)_startPosY + 25, 25, 20);
}
}
}

40
DrawningObjectShip.java Normal file
View File

@ -0,0 +1,40 @@
import java.awt.*;
public class DrawningObjectShip implements IDrawningObject {
private DrawingShip _warmlyShip = null;
public DrawningObjectShip(DrawingShip warmlyShip)
{
_warmlyShip = warmlyShip;
}
public DrawingShip getDrawingShip() {return _warmlyShip;}
@Override
public float getStep() {
if (_warmlyShip == null || _warmlyShip.warmlyShip == null) return 0;
return _warmlyShip.warmlyShip.GetStep();
}
@Override
public void SetObject(int x, int y, int width, int height) {
_warmlyShip.SetPosition(x, y, width, height);
}
@Override
public void MoveObject(Direction direction) {
_warmlyShip.MoveTransport(direction);
}
@Override
public void DrawningObject(Graphics g) {
_warmlyShip.DrawTransport(g);
}
@Override
public float[] GetCurrentPosition() {
if (_warmlyShip == null || _warmlyShip.warmlyShip == null) return null;
return _warmlyShip.GetCurrentPosition();
}
}

21
EntityMotorShip.java Normal file
View File

@ -0,0 +1,21 @@
import java.awt.*;
public class EntityMotorShip extends EntityWarmlyShip {
private Color DopColor;
private boolean Tubes;
private boolean Cistern;
public EntityMotorShip(int speed, float weight, Color bodyColor, Color dopColor, boolean tubes, boolean cistern)
{
super(speed, weight, bodyColor);
DopColor = dopColor;
Tubes = tubes;
Cistern = cistern;
}
public Color GetDopColor(){return DopColor;}
public boolean GetTubes(){return Tubes;}
public boolean GetCistern(){return Cistern;}
}

35
EntityWarmlyShip.java Normal file
View File

@ -0,0 +1,35 @@
import java.awt.*;
import java.util.*;
public class EntityWarmlyShip {
private int Speed; //Скорость
private float Weight; //Вес
private Color BodyColor; //Цвет
private float Step; //Шаг при перемещении
//Инициализация
public EntityWarmlyShip(int speed, float weight, Color bodyColor)
{
Random random = new Random();
Speed = speed <= 0 ? random.nextInt(50, 150) : speed;
Weight = weight <= 0 ? random.nextInt(50, 150) : weight;
BodyColor = bodyColor;
Step = Speed * 100 / Weight;
}
public int GetSpeed(){
return Speed;
}
public float GetWeight(){
return Weight;
}
public Color GetBodyColor(){
return BodyColor;
}
public float GetStep(){
return Step;
}
}

133
FormMap.form Normal file
View File

@ -0,0 +1,133 @@
<?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="JPanel" 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>
<xy x="20" y="20" width="500" height="400"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<grid id="bd11a" binding="Mainpanel" 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="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<opaque value="true"/>
<preferredSize width="800" height="600"/>
</properties>
<border type="none"/>
<children>
<component id="aa94c" class="javax.swing.JButton" binding="buttonDown">
<constraints>
<grid row="2" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" 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>
<text value=""/>
</properties>
</component>
<component id="579c4" class="javax.swing.JButton" binding="buttonRight">
<constraints>
<grid row="2" column="5" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" 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>
<horizontalAlignment value="0"/>
<text value=""/>
</properties>
</component>
<component id="43c16" class="javax.swing.JButton" binding="buttonUp">
<constraints>
<grid row="1" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" 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>
<text value=""/>
</properties>
</component>
<toolbar id="595a9" binding="statusStrip">
<constraints>
<grid row="3" column="0" row-span="1" col-span="6" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false">
<minimum-size width="-1" height="20"/>
<preferred-size width="-1" height="20"/>
<maximum-size width="-1" height="20"/>
</grid>
</constraints>
<properties>
<enabled value="false"/>
</properties>
<border type="none"/>
<children/>
</toolbar>
<component id="769a2" class="javax.swing.JButton" binding="buttonCreate">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="122" height="30"/>
</grid>
</constraints>
<properties>
<text value="Создать"/>
</properties>
</component>
<component id="b0694" class="javax.swing.JButton" binding="buttonLeft">
<constraints>
<grid row="2" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" 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>
<text value=""/>
</properties>
</component>
<grid id="55dd2" binding="GraphicsOutput" layout-manager="FlowLayout" hgap="5" vgap="5" flow-align="1">
<constraints>
<grid row="0" column="0" row-span="1" col-span="6" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children/>
</grid>
<component id="b8384" class="javax.swing.JButton" binding="buttonCreateModif">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="122" height="30"/>
</grid>
</constraints>
<properties>
<text value="Модификация"/>
</properties>
</component>
<component id="a36c3" class="javax.swing.JComboBox" binding="comboBoxSelectorMap">
<constraints>
<grid row="2" 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/>
</component>
<hspacer id="c0027">
<constraints>
<grid row="2" column="1" row-span="1" col-span="2" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<hspacer id="7e42b">
<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>
</children>
</grid>
</children>
</grid>
</form>

159
FormMap.java Normal file
View File

@ -0,0 +1,159 @@
import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Random;
public class FormMap extends JFrame {
private AbstractMap _abstractMap;
private JPanel JPanel;
private JButton buttonDown;
private JButton buttonRight;
private JButton buttonUp;
private JToolBar statusStrip;
private JButton buttonCreate;
private JButton buttonLeft;
private JPanel GraphicsOutput;
private JButton buttonCreateModif;
public JPanel Mainpanel;
private JComboBox comboBoxSelectorMap;
private JLabel JLabelSpeed = new JLabel();
private JLabel JLabelWeight = new JLabel();
private JLabel JLabelColor = new JLabel();
private void SetData(DrawingShip ship)
{
Random random = new Random();
GraphicsOutput.removeAll();
ship.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100), GraphicsOutput.getWidth(), GraphicsOutput.getHeight());
JLabelSpeed.setText("орость: " + ship.GetWarmlyShip().GetSpeed() + " ");
JLabelWeight.setText("Вес: " + ship.GetWarmlyShip().GetWeight() + " ");
JLabelColor.setText(("Цвет: " + ship.GetWarmlyShip().GetBodyColor() + " "));
JLabel imageOfShip = new JLabel();
imageOfShip.setPreferredSize(GraphicsOutput.getSize());
imageOfShip.setMinimumSize(new Dimension(1, 1));
imageOfShip.setIcon(new ImageIcon(_abstractMap.CreateMap(GraphicsOutput.getWidth(), GraphicsOutput.getHeight(), new DrawningObjectShip(ship))));
GraphicsOutput.add(imageOfShip,BorderLayout.CENTER);
GraphicsOutput.revalidate();
GraphicsOutput.repaint();
}
private void ButtonMove_Click(String name)
{
if (_abstractMap == null) return;
Direction direction = Direction.None;
switch (name)
{
case "buttonLeft":
direction = Direction.Left;
break;
case "buttonUp":
direction = Direction.Up;
break;
case "buttonRight":
direction = Direction.Right;
break;
case "buttonDown":
direction = Direction.Down;
break;
}
GraphicsOutput.removeAll();
JLabel imageOfShip = new JLabel();
imageOfShip.setPreferredSize(GraphicsOutput.getSize());
imageOfShip.setMinimumSize(new Dimension(1, 1));
imageOfShip.setIcon(new ImageIcon(_abstractMap.MoveObject(direction)));
GraphicsOutput.add(imageOfShip,BorderLayout.CENTER);
GraphicsOutput.revalidate();
GraphicsOutput.repaint();
}
public FormMap() {
Box LabelBox = Box.createHorizontalBox();
LabelBox.setMinimumSize(new Dimension(1, 20));
LabelBox.add(JLabelSpeed);
LabelBox.add(JLabelWeight);
LabelBox.add(JLabelColor);
statusStrip.add(LabelBox);
comboBoxSelectorMap.addItem("Простая карта");
comboBoxSelectorMap.addItem("Вторая карта");
comboBoxSelectorMap.addItem("Последняя карта");
_abstractMap = new SimpleMap();
try {
Image img = ImageIO.read(FormShip.class.getResource("/Images/totop.png"));
buttonUp.setIcon(new ImageIcon(img));
img = ImageIO.read(FormShip.class.getResource("/Images/toleft.png"));
buttonLeft.setIcon(new ImageIcon(img));
img = ImageIO.read(FormShip.class.getResource("/Images/todown.png"));
buttonDown.setIcon(new ImageIcon(img));
img = ImageIO.read(FormShip.class.getResource("/Images/toright.png"));
buttonRight.setIcon(new ImageIcon(img));
} catch (Exception ex) {
System.out.println(ex);
}
buttonCreate.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Random random = new Random();
var ship = new DrawingShip(random.nextInt(100, 300), random.nextInt(1000, 2000), new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256)));
SetData(ship);
}
});
buttonUp.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
ButtonMove_Click("buttonUp");
}
});
buttonLeft.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
ButtonMove_Click("buttonLeft");
}
});
buttonDown.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
ButtonMove_Click("buttonDown");
}
});
buttonRight.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
ButtonMove_Click("buttonRight");
}
});
buttonCreateModif.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Random random = new Random();
var ship = new DrawningMotorShip(random.nextInt(100, 300), random.nextInt(1000, 3000),
new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256)),
new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256)),
random.nextBoolean(), random.nextBoolean());
SetData(ship);
}
});
comboBoxSelectorMap.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
switch (comboBoxSelectorMap.getSelectedItem().toString())
{
case "Простая карта":
_abstractMap = new SimpleMap();
break;
case "Вторая карта":
_abstractMap = new SecondMap();
break;
case "Последняя карта":
_abstractMap = new LastMap();
break;
}
}
});
}
}

156
FormMapWithSetShip.form Normal file
View File

@ -0,0 +1,156 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormMapWithSetShip">
<grid id="27dc6" binding="Mainpanel" 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="785" height="400"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<grid id="afa3d" binding="GraphicsOutput" layout-manager="FlowLayout" hgap="5" vgap="5" flow-align="1">
<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="e9a63" binding="groupBox" layout-manager="GridLayoutManager" row-count="8" 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="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
<minimum-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="f23ee" class="javax.swing.JButton" binding="buttonAddShip">
<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="2e61e" class="javax.swing.JComboBox" binding="comboBoxSelectorMap">
<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/>
</properties>
</component>
<component id="5c428" class="javax.swing.JButton" binding="buttonRemoveShip">
<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>
<text value="Удалить корабль"/>
</properties>
</component>
<component id="e24b9" class="javax.swing.JButton" binding="buttonShowStorage">
<constraints>
<grid row="4" 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="ac087" class="javax.swing.JButton" binding="buttonShowOnMap">
<constraints>
<grid row="5" 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>
<grid id="2821b" 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="7" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
<minimum-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="6d803" class="javax.swing.JButton" binding="buttonLeft">
<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">
<minimum-size width="30" height="30"/>
<preferred-size width="30" height="30"/>
<maximum-size width="30" height="30"/>
</grid>
</constraints>
<properties>
<text value=""/>
</properties>
</component>
<component id="c0db2" class="javax.swing.JButton" binding="buttonUp">
<constraints>
<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">
<minimum-size width="30" height="30"/>
<preferred-size width="30" height="30"/>
<maximum-size width="30" height="30"/>
</grid>
</constraints>
<properties>
<text value=""/>
</properties>
</component>
<component id="ca0da" class="javax.swing.JButton" binding="buttonDown">
<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">
<minimum-size width="30" height="30"/>
<preferred-size width="30" height="30"/>
<maximum-size width="30" height="30"/>
</grid>
</constraints>
<properties>
<text value=""/>
</properties>
</component>
<component id="c3e45" class="javax.swing.JButton" binding="buttonRight">
<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">
<minimum-size width="30" height="30"/>
<preferred-size width="30" height="30"/>
<maximum-size width="30" height="30"/>
</grid>
</constraints>
<properties>
<text value=""/>
</properties>
</component>
<hspacer id="1f200">
<constraints>
<grid row="1" column="4" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<hspacer id="f8b3b">
<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>
</children>
</grid>
<vspacer id="b833e">
<constraints>
<grid row="6" 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>
<component id="181ac" class="javax.swing.JTextField" binding="maskedTextBoxPosition">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" 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>
</children>
</grid>
</children>
</grid>
</form>

238
FormMapWithSetShip.java Normal file
View File

@ -0,0 +1,238 @@
import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class FormMapWithSetShip extends JFrame {
private MapWithSetShipGeneric<DrawningObjectShip, AbstractMap> _mapShipCollectionGeneric;
public boolean ShipOnMap = false;
public JPanel Mainpanel;
private JButton buttonAddShip;
private JComboBox comboBoxSelectorMap;
private JTextField maskedTextBoxPosition;
private JButton buttonRemoveShip;
private JButton buttonShowStorage;
private JButton buttonShowOnMap;
private JButton buttonUp;
private JButton buttonLeft;
private JButton buttonRight;
private JButton buttonDown;
private JPanel GraphicsOutput;
private JPanel groupBox;
private JFrame getFrame() {
JFrame frame = new JFrame();
frame.setVisible(false);
frame.setBounds(300, 100, 800, 600);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
return frame;
}
JFrame jFrame = getFrame();
private void ButtonMove_Click(String name)
{
if (_mapShipCollectionGeneric == null || !ShipOnMap) return;
Direction direction = Direction.None;
switch (name)
{
case "buttonLeft":
direction = Direction.Left;
break;
case "buttonUp":
direction = Direction.Up;
break;
case "buttonRight":
direction = Direction.Right;
break;
case "buttonDown":
direction = Direction.Down;
break;
}
GraphicsOutput.removeAll();
JLabel imageOfShip = new JLabel();
imageOfShip.setPreferredSize(GraphicsOutput.getSize());
imageOfShip.setMinimumSize(new Dimension(1, 1));
imageOfShip.setIcon(new ImageIcon(_mapShipCollectionGeneric.MoveObject(direction)));
GraphicsOutput.add(imageOfShip,BorderLayout.CENTER);
GraphicsOutput.revalidate();
GraphicsOutput.repaint();
}
public FormMapWithSetShip() {
comboBoxSelectorMap.addItem("Простая карта");
comboBoxSelectorMap.addItem("Вторая карта");
comboBoxSelectorMap.addItem("Последняя карта");
try {
Image img = ImageIO.read(FormShip.class.getResource("/Images/totop.png"));
buttonUp.setIcon(new ImageIcon(img));
img = ImageIO.read(FormShip.class.getResource("/Images/toleft.png"));
buttonLeft.setIcon(new ImageIcon(img));
img = ImageIO.read(FormShip.class.getResource("/Images/todown.png"));
buttonDown.setIcon(new ImageIcon(img));
img = ImageIO.read(FormShip.class.getResource("/Images/toright.png"));
buttonRight.setIcon(new ImageIcon(img));
} catch (Exception ex) {
System.out.println(ex);
}
comboBoxSelectorMap.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
AbstractMap map = null;
switch (comboBoxSelectorMap.getSelectedItem().toString())
{
case "Простая карта":
map = new SimpleMap();
break;
case "Вторая карта":
map = new SecondMap();
break;
case "Последняя карта":
map = new LastMap();
break;
}
if (map != null)
{
_mapShipCollectionGeneric = new MapWithSetShipGeneric<DrawningObjectShip, AbstractMap>(GraphicsOutput.getWidth(), GraphicsOutput.getHeight(), map);
}
else
{
_mapShipCollectionGeneric = null;
}
}
});
buttonAddShip.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (_mapShipCollectionGeneric == null)
{
return;
}
FormShip dialog = new FormShip();
dialog.setSize(800, 600);
dialog.setLocation(500, 200);
dialog.setModalityType(Dialog.ModalityType.APPLICATION_MODAL);
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
dialog.setVisible(true);
if (dialog.GetSelectedShip() == null) return;
DrawningObjectShip ship = new DrawningObjectShip(dialog.GetSelectedShip());
if (_mapShipCollectionGeneric.Add(ship) > -1)
{
JOptionPane.showMessageDialog(jFrame, "Объект добавлен");
GraphicsOutput.removeAll();
JLabel imageOfShip = new JLabel();
imageOfShip.setPreferredSize(GraphicsOutput.getSize());
imageOfShip.setMinimumSize(new Dimension(1, 1));
imageOfShip.setIcon(new ImageIcon(_mapShipCollectionGeneric.ShowSet()));
GraphicsOutput.add(imageOfShip,BorderLayout.CENTER);
GraphicsOutput.revalidate();
GraphicsOutput.repaint();
}
else
{
JOptionPane.showMessageDialog(jFrame, "Не удалось добавить объект");
}
}
});
buttonRemoveShip.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if(_mapShipCollectionGeneric == null) return;
String text = maskedTextBoxPosition.getText();
if(text.isEmpty()) return;
if(JOptionPane.showConfirmDialog(jFrame, "Вы действительно хотите удалить объект?", "Удаление", JOptionPane.YES_NO_OPTION) == JOptionPane.NO_OPTION) return;
try {
Integer.parseInt(text);
}
catch (Exception ex){
return;
}
int pos = Integer.parseInt(text);
if (_mapShipCollectionGeneric.Delete(pos) != null)
{
JOptionPane.showMessageDialog(jFrame, "Объект удален");
GraphicsOutput.removeAll();
JLabel imageOfShip = new JLabel();
imageOfShip.setPreferredSize(GraphicsOutput.getSize());
imageOfShip.setMinimumSize(new Dimension(1, 1));
imageOfShip.setIcon(new ImageIcon(_mapShipCollectionGeneric.ShowSet()));
GraphicsOutput.add(imageOfShip,BorderLayout.CENTER);
GraphicsOutput.revalidate();
GraphicsOutput.repaint();
}
else
{
JOptionPane.showMessageDialog(jFrame, "Не удалось удалить объект");
}
}
});
buttonShowStorage.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (_mapShipCollectionGeneric == null) return;
GraphicsOutput.removeAll();
JLabel imageOfShip = new JLabel();
imageOfShip.setPreferredSize(GraphicsOutput.getSize());
imageOfShip.setMinimumSize(new Dimension(1, 1));
imageOfShip.setIcon(new ImageIcon(_mapShipCollectionGeneric.ShowSet()));
GraphicsOutput.add(imageOfShip,BorderLayout.CENTER);
GraphicsOutput.revalidate();
GraphicsOutput.repaint();
ShipOnMap = false;
}
});
buttonShowOnMap.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (_mapShipCollectionGeneric == null) return;
GraphicsOutput.removeAll();
JLabel imageOfShip = new JLabel();
imageOfShip.setPreferredSize(GraphicsOutput.getSize());
imageOfShip.setMinimumSize(new Dimension(1, 1));
imageOfShip.setIcon(new ImageIcon(_mapShipCollectionGeneric.ShowOnMap()));
GraphicsOutput.add(imageOfShip,BorderLayout.CENTER);
GraphicsOutput.revalidate();
GraphicsOutput.repaint();
ShipOnMap = true;
}
});
buttonUp.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
ButtonMove_Click("buttonUp");
}
});
buttonLeft.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
ButtonMove_Click("buttonLeft");
}
});
buttonDown.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
ButtonMove_Click("buttonDown");
}
});
buttonRight.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
ButtonMove_Click("buttonRight");
}
});
}
}

View File

@ -0,0 +1,196 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormMapWithSetShipsGeneric">
<grid id="27dc6" binding="Mainpanel" layout-manager="GridLayoutManager" row-count="4" 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="798" height="526"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<grid id="9bb5a" binding="pictureBoxShip" layout-manager="BorderLayout" hgap="0" vgap="0">
<constraints>
<grid row="0" column="0" row-span="2" 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>
<hspacer id="b305e">
<constraints>
<grid row="3" 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="4fa91" binding="GroupBoxTools" layout-manager="GridLayoutManager" row-count="8" 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="1" row-span="3" 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="cdb80" class="javax.swing.JButton" binding="ButtonAddShip">
<constraints>
<grid row="0" 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="e5494" class="javax.swing.JTextField" binding="maskedTextBoxPosition">
<constraints>
<grid row="1" 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="8bb89" class="javax.swing.JButton" binding="ButtonDeleteShip">
<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="aa482" class="javax.swing.JButton" binding="ButtonShowStorage">
<constraints>
<grid row="3" 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="9ebdc" class="javax.swing.JButton" binding="ButtonShowMap">
<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="acbc" class="javax.swing.JButton" binding="buttonUp">
<constraints>
<grid row="6" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" 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>
<text value=""/>
</properties>
</component>
<component id="a584e" class="javax.swing.JButton" binding="buttonDown">
<constraints>
<grid row="7" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" 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>
<text value=""/>
</properties>
</component>
<component id="e9fe6" class="javax.swing.JButton" binding="buttonLeft">
<constraints>
<grid row="7" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" 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>
<text value=""/>
</properties>
</component>
<component id="25a22" class="javax.swing.JButton" binding="buttonRight">
<constraints>
<grid row="7" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" 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>
<text value=""/>
</properties>
</component>
<component id="6734a" class="javax.swing.JButton" binding="ButtonCheckDel">
<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>
</children>
</grid>
<grid id="d087c" binding="GroupBoxMaps" layout-manager="GridLayoutManager" row-count="7" 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="1" 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="124b6" class="javax.swing.JTextField" binding="textBoxNewMapName">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" 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>
<vspacer id="3ed0f">
<constraints>
<grid row="6" 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>
<component id="95ba3" class="javax.swing.JComboBox" binding="ComboBoxSelectorMap">
<constraints>
<grid row="2" 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="Карта острова"/>
<item value="Карта скалы"/>
</model>
</properties>
</component>
<component id="fb777" class="javax.swing.JButton" binding="ButtonAddMap">
<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>
<text value="Добавить карту"/>
</properties>
</component>
<component id="a358a" class="javax.swing.JButton" binding="ButtonDeleteMap">
<constraints>
<grid row="5" 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>
<vspacer id="64e67">
<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>
<component id="e221" class="javax.swing.JList" binding="ListBoxMaps" custom-create="true">
<constraints>
<grid row="4" column="0" row-span="1" col-span="1" 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>
</children>
</grid>
</children>
</grid>
</form>

View File

@ -0,0 +1,309 @@
import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;
import java.util.HashMap;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
public class FormMapWithSetShipsGeneric extends JFrame{
public JPanel Mainpanel;
private JPanel pictureBoxShip;
private JPanel GroupBoxTools;
private JComboBox ComboBoxSelectorMap;
private JButton ButtonAddShip;
private JButton ButtonDeleteShip;
private JButton ButtonShowStorage;
private JButton ButtonShowMap;
private JButton buttonLeft;
private JButton buttonDown;
private JButton buttonUp;
private JButton buttonRight;
private JTextField maskedTextBoxPosition;
private JTextField textBoxNewMapName;
private int picWidth=600;
private int picHeight=400;
private JButton ButtonAddMap;
private JList ListBoxMaps;
private JButton ButtonDeleteMap;
private JPanel GroupBoxMaps;
private JButton ButtonCheckDel;
private MapWithSetShipGeneric<DrawningObjectShip,AbstractMap> _mapShipsCollectionGeneric;
private final HashMap<String,AbstractMap> _mapsDict = new HashMap<>(){{
put("Простая карта",new SimpleMap());
put("Вторая карта",new SecondMap());
put("Последняя карта",new LastMap());
}};
private final MapsCollection _mapsCollection;
public void UpdateWindow(BufferedImage bmp)
{
pictureBoxShip.removeAll();
JLabel imageWithMapAndObject = new JLabel();
imageWithMapAndObject.setPreferredSize(pictureBoxShip.getSize());
imageWithMapAndObject.setMinimumSize(new Dimension(1, 1));
imageWithMapAndObject.setIcon(new ImageIcon(bmp));
pictureBoxShip.add(imageWithMapAndObject, BorderLayout.CENTER);
pictureBoxShip.revalidate();
}
private void ReloadMaps(){
int index = ListBoxMaps.getSelectedIndex();
DefaultListModel<String> model1 = (DefaultListModel<String>) ListBoxMaps.getModel();
model1.removeAllElements();
for(int i=0;i<_mapsCollection.Keys().size();i++)
{
model1.addElement(_mapsCollection.Keys().get(i));
}
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);
}
}
public FormMapWithSetShipsGeneric()
{
//picWidth = pictureBoxShip.getWidth();
//picHeight = pictureBoxShip.getHeight();
_mapsCollection = new MapsCollection(picWidth, picHeight);
ComboBoxSelectorMap.removeAllItems();
for (String elem : _mapsDict.keySet()) {
ComboBoxSelectorMap.addItem(elem);
}
try {
Image img = ImageIO.read(FormShip.class.getResource("/Images/totop.png"));
buttonUp.setIcon(new ImageIcon(img));
img = ImageIO.read(FormShip.class.getResource("/Images/toleft.png"));
buttonLeft.setIcon(new ImageIcon(img));
img = ImageIO.read(FormShip.class.getResource("/Images/todown.png"));
buttonDown.setIcon(new ImageIcon(img));
img = ImageIO.read(FormShip.class.getResource("/Images/toright.png"));
buttonRight.setIcon(new ImageIcon(img));
} catch (Exception ex) {
System.out.println(ex);
}
ButtonAddShip.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (ListBoxMaps.getSelectedIndex() == -1)
{
return;
}
FormShip dialog = new FormShip();
dialog.setSize(800, 600);
dialog.setLocation(500, 200);
dialog.setModalityType(Dialog.ModalityType.APPLICATION_MODAL);
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
dialog.setVisible(true);
if (dialog.GetSelectedShip() == null) return;
DrawningObjectShip ship = new DrawningObjectShip(dialog.GetSelectedShip());
if(_mapsCollection.Get(ListBoxMaps.getSelectedValue().toString()).Add(ship) != -1)
{
JOptionPane.showMessageDialog(null,"Объект добавлен");
UpdateWindow(_mapsCollection.Get(ListBoxMaps.getSelectedValue().toString()).ShowSet());
}
else
{
JOptionPane.showMessageDialog(null, "Не удалось добавить объект");
}
}
});
ListBoxMaps.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
if (ListBoxMaps.getSelectedIndex() == -1)
return;
UpdateWindow(_mapsCollection.Get(ListBoxMaps.getSelectedValue().toString()).ShowSet());
}
});
ButtonDeleteShip.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (maskedTextBoxPosition.getText().isEmpty())
{
return;
}
int result = JOptionPane.showConfirmDialog(null,"Удалить объект?","Удаление",JOptionPane.YES_NO_OPTION,JOptionPane.WARNING_MESSAGE);
if(result==JOptionPane.NO_OPTION)
{
return;
}
int pos=Integer.parseInt(maskedTextBoxPosition.getText());
if(_mapsCollection.Get(ListBoxMaps.getSelectedValue().toString()).Delete(pos)!=null)
{
JOptionPane.showMessageDialog(null, "Объект удален");
UpdateWindow(_mapsCollection.Get(ListBoxMaps.getSelectedValue().toString()).ShowSet());
}
else
{
JOptionPane.showMessageDialog(null, "Не удалось удалить объект");
}
}
});
ButtonShowStorage.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (ListBoxMaps.getSelectedIndex() == -1)
{
return;
}
UpdateWindow(_mapsCollection.Get(ListBoxMaps.getSelectedValue().toString()).ShowSet());
}
});
ButtonShowMap.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (ListBoxMaps.getSelectedIndex() == -1)
{
return;
}
UpdateWindow(_mapsCollection.Get(ListBoxMaps.getSelectedValue().toString()).ShowOnMap());
}
});
buttonUp.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (ListBoxMaps.getSelectedIndex() == -1)
{
return;
}
pictureBoxShip.removeAll();
JLabel imageWithMapAndObject = new JLabel();
imageWithMapAndObject.setPreferredSize(pictureBoxShip.getSize());
imageWithMapAndObject.setMinimumSize(new Dimension(1, 1));
imageWithMapAndObject.setIcon(new ImageIcon(_mapsCollection.Get(ListBoxMaps.getSelectedValue().toString()).MoveObject(Direction.Up)));
pictureBoxShip.add(imageWithMapAndObject, BorderLayout.CENTER);
pictureBoxShip.revalidate();
pictureBoxShip.repaint();
}
});
buttonDown.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (ListBoxMaps.getSelectedIndex() == -1)
{
return;
}
pictureBoxShip.removeAll();
JLabel imageWithMapAndObject = new JLabel();
imageWithMapAndObject.setPreferredSize(pictureBoxShip.getSize());
imageWithMapAndObject.setMinimumSize(new Dimension(1, 1));
imageWithMapAndObject.setIcon(new ImageIcon(_mapsCollection.Get(ListBoxMaps.getSelectedValue().toString()).MoveObject(Direction.Down)));
pictureBoxShip.add(imageWithMapAndObject, BorderLayout.CENTER);
pictureBoxShip.revalidate();
pictureBoxShip.repaint();
}
});
buttonRight.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (ListBoxMaps.getSelectedIndex() == -1)
{
return;
}
pictureBoxShip.removeAll();
JLabel imageWithMapAndObject = new JLabel();
imageWithMapAndObject.setPreferredSize(pictureBoxShip.getSize());
imageWithMapAndObject.setMinimumSize(new Dimension(1, 1));
imageWithMapAndObject.setIcon(new ImageIcon(_mapsCollection.Get(ListBoxMaps.getSelectedValue().toString()).MoveObject(Direction.Right)));
pictureBoxShip.add(imageWithMapAndObject, BorderLayout.CENTER);
pictureBoxShip.revalidate();
pictureBoxShip.repaint();
}
});
buttonLeft.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (ListBoxMaps.getSelectedIndex() == -1)
{
return;
}
pictureBoxShip.removeAll();
JLabel imageWithMapAndObject = new JLabel();
imageWithMapAndObject.setPreferredSize(pictureBoxShip.getSize());
imageWithMapAndObject.setMinimumSize(new Dimension(1, 1));
imageWithMapAndObject.setIcon(new ImageIcon(_mapsCollection.Get(ListBoxMaps.getSelectedValue().toString()).MoveObject(Direction.Left)));
pictureBoxShip.add(imageWithMapAndObject, BorderLayout.CENTER);
pictureBoxShip.revalidate();
pictureBoxShip.repaint();
}
});
maskedTextBoxPosition.addKeyListener(new KeyAdapter() {
@Override
public void keyTyped(KeyEvent e) {
char c = e.getKeyChar();
if ( ((c < '0') || (c > '9')) || maskedTextBoxPosition.getText().length() >= 2) {
e.consume();
}
}
});
ButtonAddMap.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (ComboBoxSelectorMap.getSelectedIndex() == -1 || textBoxNewMapName.getText().isEmpty())
{
JOptionPane.showMessageDialog(null,"Не все данные заполнены","Ошибка",JOptionPane.ERROR_MESSAGE);
return;
}
if(!_mapsDict.containsKey(ComboBoxSelectorMap.getSelectedItem()))
{
JOptionPane.showMessageDialog(null,"Нет такой карты","Ошибка",JOptionPane.ERROR_MESSAGE);
}
_mapsCollection.AddMap(textBoxNewMapName.getText(),_mapsDict.get(ComboBoxSelectorMap.getSelectedItem().toString()));
ReloadMaps();
}
});
ButtonDeleteMap.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (ListBoxMaps.getSelectedIndex() == -1)
{
return;
}
if(JOptionPane.showConfirmDialog(null,"Удалить карту"+ListBoxMaps.getSelectedValue().toString()+"?","Удаление",JOptionPane.YES_NO_OPTION)==0)
{
_mapsCollection.DelMap(ListBoxMaps.getSelectedValue().toString());
ReloadMaps();
}
}
});
ButtonCheckDel.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (ListBoxMaps.getSelectedIndex() == -1)
{
return;
}
DrawningObjectShip ship = _mapsCollection.Get(ListBoxMaps.getSelectedValue().toString()).GetShipsDeleted();
if(ship == null)
{
JOptionPane.showMessageDialog(null,"Коллекция пуста","Ошибка",JOptionPane.ERROR_MESSAGE);
return;
}
FormShip dialog = new FormShip();
dialog.setShipIn(ship);
dialog.setSize(800, 600);
dialog.setLocation(500, 200);
dialog.setModalityType(Dialog.ModalityType.APPLICATION_MODAL);
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
dialog.setVisible(true);
}
});
}
private void createUIComponents() {
DefaultListModel<String> dlm = new DefaultListModel<String>();
ListBoxMaps = new JList(dlm);
}
}

120
FormShip.form Normal file
View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormShip">
<grid id="27dc6" binding="Mainpanel" 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>
<xy x="20" y="20" width="500" height="400"/>
</constraints>
<properties>
<opaque value="true"/>
<preferredSize width="800" height="600"/>
</properties>
<border type="none"/>
<children>
<component id="2ea16" class="javax.swing.JButton" binding="buttonDown">
<constraints>
<grid row="2" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" 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>
<text value=""/>
</properties>
</component>
<component id="4eb88" class="javax.swing.JButton" binding="buttonRight">
<constraints>
<grid row="2" column="5" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" 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>
<horizontalAlignment value="0"/>
<text value=""/>
</properties>
</component>
<component id="fb937" class="javax.swing.JButton" binding="buttonUp">
<constraints>
<grid row="1" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" 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>
<text value=""/>
</properties>
</component>
<toolbar id="e747d" binding="statusStrip">
<constraints>
<grid row="3" column="0" row-span="1" col-span="6" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false">
<minimum-size width="-1" height="20"/>
<preferred-size width="-1" height="20"/>
<maximum-size width="-1" height="20"/>
</grid>
</constraints>
<properties>
<enabled value="false"/>
</properties>
<border type="none"/>
<children/>
</toolbar>
<component id="9e2ce" class="javax.swing.JButton" binding="buttonCreate">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="122" height="30"/>
</grid>
</constraints>
<properties>
<text value="Создать"/>
</properties>
</component>
<component id="4f60a" class="javax.swing.JButton" binding="buttonLeft">
<constraints>
<grid row="2" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" 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>
<text value=""/>
</properties>
</component>
<grid id="8b0ad" binding="GraphicsOutput" layout-manager="FlowLayout" hgap="5" vgap="5" flow-align="1">
<constraints>
<grid row="0" column="0" row-span="1" col-span="6" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children/>
</grid>
<component id="bbe04" class="javax.swing.JButton" binding="buttonCreateModif">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="122" height="30"/>
</grid>
</constraints>
<properties>
<text value="Модификация"/>
</properties>
</component>
<hspacer id="b7fa3">
<constraints>
<grid row="2" column="0" row-span="1" col-span="3" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<component id="faea9" class="javax.swing.JButton" binding="buttonSelectShip">
<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>
</form>

166
FormShip.java Normal file
View File

@ -0,0 +1,166 @@
import javax.imageio.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.util.*;
public class FormShip extends JDialog{
private JToolBar statusStrip;
public JPanel Mainpanel;
private DrawingShip ship;
private DrawingShip selectedShip;
public DrawingShip GetSelectedShip(){return selectedShip;} //Выбранный объект
private JButton buttonRight;
private JButton buttonCreate;
private JButton buttonLeft;
private JButton buttonUp;
private JButton buttonDown;
private JPanel GraphicsOutput;
private JButton buttonCreateModif;
private JButton buttonSelectShip;
private JLabel JLabelSpeed = new JLabel();
private JLabel JLabelWeight = new JLabel();
private JLabel JLabelColor = new JLabel();
private void Draw()
{
if (ship == null || ship.GetWarmlyShip() == null) return;
GraphicsOutput.removeAll();
BufferedImage bmp = new BufferedImage(GraphicsOutput.getWidth(), GraphicsOutput.getHeight(),BufferedImage.TYPE_INT_RGB);
Graphics g = bmp.getGraphics();
g.setColor(new Color(238, 238, 238));
g.fillRect(0, 0, GraphicsOutput.getWidth(), GraphicsOutput.getHeight());
ship.DrawTransport(g);
JLabel imageOfShip = new JLabel();
imageOfShip.setPreferredSize(GraphicsOutput.getSize());
imageOfShip.setMinimumSize(new Dimension(1, 1));
imageOfShip.setIcon(new ImageIcon(bmp));
GraphicsOutput.add(imageOfShip,BorderLayout.CENTER);
validate();
}
private void SetData()
{
Random random = new Random();
ship.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100), GraphicsOutput.getWidth(), GraphicsOutput.getHeight());
JLabelSpeed.setText("орость: " + ship.GetWarmlyShip().GetSpeed() + " ");
JLabelWeight.setText("Вес: " + ship.GetWarmlyShip().GetWeight() + " ");
JLabelColor.setText(("Цвет: " + ship.GetWarmlyShip().GetBodyColor() + " "));
}
private void ButtonMove_Click(String name)
{
if (ship == null) return;
switch (name)
{
case "buttonLeft":
ship.MoveTransport(Direction.Left);
break;
case "buttonUp":
ship.MoveTransport(Direction.Up);
break;
case "buttonRight":
ship.MoveTransport(Direction.Right);
break;
case "buttonDown":
ship.MoveTransport(Direction.Down);
break;
}
GraphicsOutput.revalidate();
Draw();
}
public void setShipIn(DrawningObjectShip ship)
{
this.ship = ship.getDrawingShip();
}
public FormShip() {
Box LabelBox = Box.createHorizontalBox();
LabelBox.setMinimumSize(new Dimension(1, 20));
LabelBox.add(JLabelSpeed);
LabelBox.add(JLabelWeight);
LabelBox.add(JLabelColor);
statusStrip.add(LabelBox);
add(Mainpanel);
try {
Image img = ImageIO.read(FormShip.class.getResource("/Images/totop.png"));
buttonUp.setIcon(new ImageIcon(img));
img = ImageIO.read(FormShip.class.getResource("/Images/toleft.png"));
buttonLeft.setIcon(new ImageIcon(img));
img = ImageIO.read(FormShip.class.getResource("/Images/todown.png"));
buttonDown.setIcon(new ImageIcon(img));
img = ImageIO.read(FormShip.class.getResource("/Images/toright.png"));
buttonRight.setIcon(new ImageIcon(img));
} catch (Exception ex) {
System.out.println(ex);
}
buttonCreate.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Random random = new Random();
ship = new DrawingShip(random.nextInt(100, 300), random.nextInt(1000, 2000), JColorChooser.showDialog(null, "Цвет", null));
SetData();
Draw();
}
});
buttonUp.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
ButtonMove_Click("buttonUp");
}
});
buttonLeft.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
ButtonMove_Click("buttonLeft");
}
});
buttonDown.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
ButtonMove_Click("buttonDown");
}
});
buttonRight.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
ButtonMove_Click("buttonRight");
}
});
GraphicsOutput.addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
super.componentResized(e);
if (ship == null || ship.GetWarmlyShip() == null) return;
ship.ChangeBorders(GraphicsOutput.getWidth(), GraphicsOutput.getHeight());
GraphicsOutput.revalidate();
Draw();
}
});
buttonCreateModif.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Random random = new Random();
ship = new DrawningMotorShip(random.nextInt(100, 300), random.nextInt(1000, 3000),
JColorChooser.showDialog(null, "Цвет", null),
JColorChooser.showDialog(null, "Цвет", null),
random.nextBoolean(), random.nextBoolean());
SetData();
Draw();
}
});
buttonSelectShip.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
selectedShip = ship;
setVisible(false);
dispose();
}
});
}
}

70
FormShipMixer.form Normal file
View File

@ -0,0 +1,70 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormShipMixer">
<grid id="27dc6" binding="Mainpanel" layout-manager="GridLayoutManager" row-count="4" 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>
<xy x="20" y="20" width="500" height="400"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<grid id="7700e" binding="pictureBox" layout-manager="BorderLayout" hgap="0" vgap="0">
<constraints>
<grid row="0" column="0" row-span="1" col-span="3" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children/>
</grid>
<component id="b960b" class="javax.swing.JButton" binding="ButtonCreate">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Создать"/>
</properties>
</component>
<component id="a44b0" class="javax.swing.JButton" binding="ButtonCreateModif">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Модификация"/>
</properties>
</component>
<component id="31e01" class="javax.swing.JLabel" binding="LabelInfo">
<constraints>
<grid row="2" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value=""/>
</properties>
</component>
<toolbar id="7a0ba" binding="StatusStrip">
<constraints>
<grid row="3" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="-1" height="20"/>
</grid>
</constraints>
<properties>
<enabled value="false"/>
</properties>
<border type="none"/>
<children/>
</toolbar>
<component id="e8cb9" class="javax.swing.JButton" binding="ButtonMix">
<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>
<hspacer id="e60aa">
<constraints>
<grid row="1" 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>

118
FormShipMixer.java Normal file
View File

@ -0,0 +1,118 @@
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.util.Random;
public class FormShipMixer extends JFrame{
public JPanel Mainpanel;
private JPanel pictureBox;
private JButton ButtonCreate;
private JButton ButtonCreateModif;
private JToolBar StatusStrip;
private JLabel LabelInfo;
private JButton ButtonMix;
private JLabel JLabelSpeed = new JLabel();
private JLabel JLabelWeight = new JLabel();
private JLabel JLabelColor = new JLabel();
private ShipsMix<EntityWarmlyShip,IDrawningDeck> _drawningEntities;
private IDrawningDeck SetData()
{
Random random = new Random();
switch (random.nextInt(3))
{
case 0:
return new DrawDeck();
case 1:
return new DrawGuns();
}
return new DrawOvalDeck();
}
private void Draw(DrawingShip _plane) {
pictureBox.removeAll();
Random random = new Random();
BufferedImage bmp = new BufferedImage(pictureBox.getWidth(), pictureBox.getHeight(),BufferedImage.TYPE_INT_RGB);
Graphics gr = bmp.getGraphics();
gr.setColor(new Color(238, 238, 238));
gr.fillRect(0, 0, pictureBox.getWidth(), pictureBox.getHeight());
if (_plane != null) {
_plane.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100),
pictureBox.getWidth(), pictureBox.getHeight());
_plane.DrawTransport(gr);
JLabelSpeed.setText("орость: " + _plane.GetWarmlyShip().GetSpeed() + " ");
JLabelWeight.setText("Вес: " + _plane.GetWarmlyShip().GetWeight() + " ");
JLabelColor.setText(("Цвет: " + _plane.GetWarmlyShip().GetBodyColor() + " "));
JLabel imageOfShip = new JLabel();
imageOfShip.setPreferredSize(pictureBox.getSize());
imageOfShip.setMinimumSize(new Dimension(1, 1));
imageOfShip.setIcon(new ImageIcon(bmp));
pictureBox.add(imageOfShip,BorderLayout.CENTER);
}
validate();
}
public FormShipMixer()
{
Box LabelBox = Box.createHorizontalBox();
LabelBox.setMinimumSize(new Dimension(1, 20));
LabelBox.add(JLabelSpeed);
LabelBox.add(JLabelWeight);
LabelBox.add(JLabelColor);
StatusStrip.add(LabelBox);
_drawningEntities = new ShipsMix<>(10,10);
ButtonCreate.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e){
Random random = new Random();
Color colorFirst = JColorChooser.showDialog(null, "Цвет", null);
EntityWarmlyShip ship = new EntityWarmlyShip(random.nextInt(100,300), random.nextInt(1000,2000),colorFirst);
IDrawningDeck deck = SetData();
int DecksCount=random.nextInt(1,4);
deck.SetDeckCount(DecksCount);
if(_drawningEntities.Insert(ship) != -1 && _drawningEntities.Insert(deck) != -1)
{
JOptionPane.showMessageDialog(null,"Объект добавлен");
Draw(_drawningEntities.MakeShipMix());
LabelInfo.setText(_drawningEntities.indexX + " " + _drawningEntities.indexY);
}
else
{
JOptionPane.showMessageDialog(null, "Не удалось добавить объект");
}
}
});
ButtonCreateModif.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Random random = new Random();
Color colorFirst = JColorChooser.showDialog(null, "Цвет", null);
Color colorSecond = JColorChooser.showDialog(null, "Цвет", null);
EntityMotorShip _ship = new EntityMotorShip(random.nextInt(100, 300), random.nextInt(1000, 2000), colorFirst, colorSecond, random.nextBoolean(), random.nextBoolean());
IDrawningDeck deck = SetData();
int DecksCount=random.nextInt(1,4);
deck.SetDeckCount(DecksCount);
if(_drawningEntities.Insert(_ship) != -1 && _drawningEntities.Insert(deck) != -1)
{
JOptionPane.showMessageDialog(null,"Объект добавлен");
Draw(_drawningEntities.MakeShipMix());
LabelInfo.setText(_drawningEntities.indexX + " " + _drawningEntities.indexY);
}
else
{
JOptionPane.showMessageDialog(null, "Не удалось добавить объект");
}
}
});
ButtonMix.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if(_drawningEntities.shipsCount == 0 || _drawningEntities.deckCount == 0) return;
Draw(_drawningEntities.MakeShipMix());
LabelInfo.setText(_drawningEntities.indexX + " " + _drawningEntities.indexY);
}
});
}
}

6
IDrawningDeck.java Normal file
View File

@ -0,0 +1,6 @@
import java.awt.*;
public interface IDrawningDeck {
void SetDeckCount(int count);
void DrawningDeck(float _startPosX, float _startPosY, int _warmlyShipWidth, Graphics2D g2d, Color bodyColor);
}

9
IDrawningObject.java Normal file
View File

@ -0,0 +1,9 @@
import java.awt.*;
public interface IDrawningObject {
float getStep();
void SetObject(int x, int y, int width, int height);
void MoveObject(Direction direction);
void DrawningObject(Graphics g);
float[] GetCurrentPosition();
}

BIN
Images/todown.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 888 B

BIN
Images/toleft.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 904 B

BIN
Images/toright.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 892 B

BIN
Images/totop.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 895 B

56
LastMap.java Normal file
View File

@ -0,0 +1,56 @@
import java.awt.*;
public class LastMap extends AbstractMap{
private Color barrierColor = Color.RED;
private Color roadColor = Color.GREEN;
@Override
protected void DrawBarrierPart(Graphics g, int i, int j)
{
Graphics2D g2d = (Graphics2D) g;
g2d.setPaint(barrierColor);
g2d.fillRect((int)Math.floor(j * _size_x), (int)Math.floor(i * _size_y),(int)Math.ceil(_size_x), (int)Math.ceil(_size_y));
}
@Override
protected void DrawRoadPart(Graphics g, int i, int j)
{
Graphics2D g2d = (Graphics2D) g;
g2d.setPaint(roadColor);
g2d.fillRect((int)Math.floor(j * _size_x), (int)Math.floor(i * _size_y),(int)Math.ceil(_size_x), (int)Math.ceil(_size_y));
}
@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 < 45)
{
int x = _random.nextInt(0, 100);
int y = _random.nextInt(0, 100);
if (_map[x][y] == _freeRoad)
{
_map[x][y] = _barrier;
if (x > 0 && y > 0 && x < _map.length - 1 && y < _map[0].length - 1)
{
_map[x - 1][y] = _barrier;
_map[x + 1][y] = _barrier;
_map[x][y - 1] = _barrier;
_map[x][y + 1] = _barrier;
}
counter++;
}
}
}
}

13
Main.java Normal file
View File

@ -0,0 +1,13 @@
import javax.swing.*;
public class Main {
public static void main(String[] args) {
JFrame frame = new JFrame("Hard №4");
frame.setContentPane(new FormMapWithSetShipsGeneric().Mainpanel);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocation(500, 200);
frame.pack();
frame.setSize(800, 600);
frame.setVisible(true);
}
}

136
MapWithSetShipGeneric.java Normal file
View File

@ -0,0 +1,136 @@
import java.awt.*;
import java.awt.image.BufferedImage;
import java.util.LinkedList;
import java.util.Queue;
public class MapWithSetShipGeneric<T extends IDrawningObject, U extends AbstractMap> {
private int _pictureWidth;
private int _pictureHeight;
private int _placeSizeWidth = 210;
private int _placeSizeHeight = 100;
private SetShipGeneric<T> _setShips;
private U _map;
private Queue<T> _deletedShips;
public MapWithSetShipGeneric(int picWidth, int picHeight, U map)
{
_deletedShips = new LinkedList<>();
int width = picWidth / _placeSizeWidth;
int height = picHeight / _placeSizeHeight;
_setShips = new SetShipGeneric<T>(width * height);
_pictureWidth = picWidth;
_pictureHeight = picHeight;
_map = map;
}
public int Add(T ship)
{
return _setShips.Insert(ship);
}
public T Delete(int position)
{
T temp = _setShips.Remove(position);
_deletedShips.add(temp);
return temp;
}
public BufferedImage ShowSet()
{
BufferedImage bmp = new BufferedImage(_pictureWidth, _pictureHeight, BufferedImage.TYPE_INT_RGB);
Graphics g = bmp.getGraphics();
DrawBackground((Graphics2D) g);
DrawShips(g);
return bmp;
}
public BufferedImage ShowOnMap()
{
//BufferedImage bmp = new BufferedImage(_pictureWidth, _pictureHeight, BufferedImage.TYPE_INT_RGB);
Shaking();
for (var ship : _setShips)
{
return _map.CreateMap(_pictureWidth,_pictureHeight,ship);
}
return new BufferedImage(_pictureWidth, _pictureHeight, BufferedImage.TYPE_INT_RGB);
}
public T GetSelectedShip(int ind){
return _setShips.Get(ind);
}
public T GetShipsDeleted()
{
if(_deletedShips.isEmpty())
{
return null;
}
return _deletedShips.remove();
}
public BufferedImage MoveObject(Direction direction)
{
BufferedImage bmp = new BufferedImage(_pictureWidth, _pictureHeight, BufferedImage.TYPE_INT_RGB);
if (_map != null)
{
return _map.MoveObject(direction);
}
return bmp;
}
private void Shaking()
{
int j = _setShips.getCount() - 1;
for (int i = 0; i < _setShips.getCount(); ++i)
{
if (_setShips.Get(i) == null)
{
for (; j > i; --j)
{
var car = _setShips.Get(j);
if (car != null)
{
_setShips.Insert(car, i);
_setShips.Remove(j);
break;
}
}
if (j <= i)
{
return;
}
}
}
}
private void DrawBackground(Graphics2D g2d)
{
g2d.setColor(Color.WHITE);
g2d.fillRect(0, 0, _pictureWidth, _pictureHeight);
g2d.setColor(new Color(150, 75, 0));
for (int i = 0; i < _pictureWidth / _placeSizeWidth; ++i)
{
for (int j = 1; j < _pictureHeight / _placeSizeHeight + 1; ++j) //линия рамзетки места
{
g2d.drawLine(i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight);
for (int k = 0; k < _placeSizeWidth / (30 * 2); ++k)
g2d.drawLine(i * _placeSizeWidth + (k + 1) * 30, j * _placeSizeHeight, i * _placeSizeWidth + (k + 1) * 30, j * _placeSizeHeight + 30);
}
g2d.drawLine(i * _placeSizeWidth, 0, i * _placeSizeWidth, (_pictureHeight / _placeSizeHeight) * _placeSizeHeight);
}
}
private void DrawShips(Graphics g)
{
int i = 0;
for (var ship: _setShips)
{
int temp = 0;
if (ship.GetCurrentPosition()[3] - ship.GetCurrentPosition()[2] < 75) temp = (int)(ship.GetCurrentPosition()[3] - ship.GetCurrentPosition()[2]);
ship.SetObject((_pictureWidth / _placeSizeWidth - (i % (_pictureWidth / _placeSizeWidth)) - 1) * _placeSizeWidth, (i / (_pictureWidth / _placeSizeWidth)) * _placeSizeHeight + temp, _pictureWidth, _pictureHeight);
ship.DrawningObject(g);
++i;
}
}
}

48
MapsCollection.java Normal file
View File

@ -0,0 +1,48 @@
import java.util.AbstractCollection;
import java.util.ArrayList;
import java.util.HashMap;
public class MapsCollection {
private final HashMap<String,MapWithSetShipGeneric<DrawningObjectShip, AbstractMap>> _mapStorages;
public ArrayList<String> Keys()
{
return new ArrayList<>(_mapStorages.keySet());
}
private final int _pictureWidth;
private final int _pictureHeight;
public MapsCollection(int pictureWidth,int pictureHeight)
{
_mapStorages = new HashMap<>();
this._pictureWidth = pictureWidth;
this._pictureHeight = pictureHeight;
}
public void AddMap(String Name, AbstractMap Map)
{
if(!_mapStorages.containsKey(Name))
{
_mapStorages.put(Name,new MapWithSetShipGeneric<>(_pictureWidth,_pictureHeight,Map));
}
}
public void DelMap(String name)
{
_mapStorages.remove(name);
}
public MapWithSetShipGeneric<DrawningObjectShip,AbstractMap> Get(String ind)
{
if(_mapStorages.containsKey(ind))
{
return _mapStorages.get(ind);
}
return null;
}
public DrawningObjectShip Get(String name, int ind)
{
if (_mapStorages.containsKey(name)) return _mapStorages.get(name).GetSelectedShip(ind);
return null;
}
}

58
SecondMap.java Normal file
View File

@ -0,0 +1,58 @@
import java.awt.*;
public class SecondMap extends AbstractMap{
private Color barrierColor = Color.ORANGE;
private Color roadColor = Color.BLACK;
@Override
protected void DrawBarrierPart(Graphics g, int i, int j)
{
Graphics2D g2d = (Graphics2D) g;
g2d.setPaint(barrierColor);
g2d.fillRect((int)Math.floor(j * _size_x), (int)Math.floor(i * _size_y),(int)Math.ceil(_size_x), (int)Math.ceil(_size_y));
}
@Override
protected void DrawRoadPart(Graphics g, int i, int j)
{
Graphics2D g2d = (Graphics2D) g;
g2d.setPaint(roadColor);
g2d.fillRect((int)Math.floor(j * _size_x), (int)Math.floor(i * _size_y),(int)Math.ceil(_size_x), (int)Math.ceil(_size_y));
}
@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;
}
}
for (int i = 0; i < _map.length; ++i)
{
_map[i][_map[0].length / 2] = _barrier;
_map[i][_map[0].length - 1] = _barrier;
}
for (int j = 0; j < _map[0].length; ++j)
{
_map[_map.length - 1][j] = _barrier;
}
while (counter < 45)
{
int x = _random.nextInt(0, 100);
int y = _random.nextInt(0, 100);
if (_map[x][y] == _freeRoad)
{
_map[x][y] = _barrier;
counter++;
}
}
}
}

54
SetShipGeneric.java Normal file
View File

@ -0,0 +1,54 @@
import java.util.*;
public class SetShipGeneric<T> implements Iterable<T> {
private ArrayList<T> _places;
private final int _maxCount;
public int getCount() {
return _places.size();
}
public SetShipGeneric(int count)
{
_maxCount = count;
_places = new ArrayList<>();
}
public int Insert(T ship)
{
return Insert(ship, 0);
}
public int Insert(T ship, int position)
{
if (position < 0 || position > getCount() || _maxCount == getCount()) return -1;
_places.add(position,ship);
return position;
}
public T Remove(int position)
{
if (position < 0 || position >= getCount()) return null;
T DelElement = (T) _places.get(position);
_places.remove(position);
return DelElement;
}
public T Get(int position)
{
if (position < 0 || position >= getCount()) return null;
return _places.get(position);
}
public void Set(int position,T value)
{
if (position < _maxCount || position >= 0)
{
Insert(value, position);
}
}
@Override
public Iterator<T> iterator() {
return _places.iterator();
}
}

56
ShipsMix.java Normal file
View File

@ -0,0 +1,56 @@
import java.util.Random;
public class ShipsMix<T extends EntityWarmlyShip, U extends IDrawningDeck>{
public T[] _ships;
public U[] _decks;
int shipsCount = 0;
int deckCount = 0;
String indexX;
String indexY;
public ShipsMix(int countE,int countI){
_ships = (T[]) new EntityWarmlyShip[countE];
_decks = (U[]) new IDrawningDeck[countI];
}
public int Insert(T ship){
if(shipsCount < _ships.length){
_ships[shipsCount] = ship;
++shipsCount;
return shipsCount - 1;
}
return -1;
}
public int Insert(U deck){
if(deckCount < _decks.length){
_decks[deckCount] = deck;
++deckCount;
return deckCount - 1;
}
return -1;
}
public void SetIndexs(int ind1, int ind2)
{
indexX = Integer.toString(ind1);
indexY = Integer.toString(ind2);
}
public DrawingShip MakeShipMix(){
Random random = new Random();
int indEnt = 0;
int indIllum = 0;
if(shipsCount - 1 != 0 && deckCount - 1 != 0){
indEnt = random.nextInt(0,shipsCount - 1);
indIllum = random.nextInt(0, deckCount - 1);
}
T plane = (T)_ships[indEnt];
U illum = (U)_decks[indIllum];
SetIndexs(indEnt,indIllum);
if(plane instanceof EntityMotorShip){
return new DrawningMotorShip(plane,illum);
}
return new DrawingShip(plane,illum);
}
}

49
SimpleMap.java Normal file
View File

@ -0,0 +1,49 @@
import java.awt.*;
public class SimpleMap extends AbstractMap{
private Color barrierColor = Color.BLACK;
private Color roadColor = Color.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(0, 100);
int y = _random.nextInt(0, 100);
if (_map[x][y] == _freeRoad)
{
_map[x][y] = _barrier;
counter++;
}
}
}
@Override
protected void DrawBarrierPart(Graphics g, int i, int j)
{
Graphics2D g2d = (Graphics2D) g;
g2d.setPaint(barrierColor);
g2d.fillRect((int)Math.floor(j * _size_x), (int)Math.floor(i * _size_y),(int)Math.ceil(_size_x), (int)Math.ceil(_size_y));
}
@Override
protected void DrawRoadPart(Graphics g, int i, int j)
{
Graphics2D g2d = (Graphics2D) g;
g2d.setPaint(roadColor);
g2d.fillRect((int)Math.floor(j * _size_x), (int)Math.floor(i * _size_y),(int)Math.ceil(_size_x), (int)Math.ceil(_size_y));
}
}