Compare commits
24 Commits
Author | SHA1 | Date | |
---|---|---|---|
d8f4d43245 | |||
ff9af7035a | |||
5534da4aba | |||
4f256d85cf | |||
a2bfcdafa3 | |||
0d394cfa78 | |||
0625fabea0 | |||
f997a031fb | |||
6d6d2d2121 | |||
52ec14ad06 | |||
21c99afc20 | |||
2cd1fb98f8 | |||
d16a35a31c | |||
e146a5a08e | |||
b9677dd6e4 | |||
2321881dd1 | |||
13cead9f97 | |||
45be5ff31c | |||
d61b6cf6c5 | |||
b3746ca983 | |||
a2e5535386 | |||
13eaeb49ed | |||
efbca96f66 | |||
6b1d2f4816 |
1
.idea/WarshipHard.iml
generated
1
.idea/WarshipHard.iml
generated
@ -3,6 +3,7 @@
|
|||||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||||
<exclude-output />
|
<exclude-output />
|
||||||
<content url="file://$MODULE_DIR$">
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/Resource" type="java-resource" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||||
</content>
|
</content>
|
||||||
<orderEntry type="inheritedJdk" />
|
<orderEntry type="inheritedJdk" />
|
||||||
|
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_19" default="true" project-jdk-name="openjdk-19" project-jdk-type="JavaSDK">
|
||||||
<output url="file://$PROJECT_DIR$/out" />
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
148
src/AbstractMap.java
Normal file
148
src/AbstractMap.java
Normal file
@ -0,0 +1,148 @@
|
|||||||
|
import java.awt.*;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public abstract class AbstractMap {
|
||||||
|
private IDrawingObject _drawingObject = null;
|
||||||
|
protected int[][] _map = null;
|
||||||
|
protected int _width;
|
||||||
|
protected int _height;
|
||||||
|
protected float _size_x;
|
||||||
|
protected float _size_y;
|
||||||
|
protected final Random _random = new Random();
|
||||||
|
protected final int _freeWaterArea = 0;
|
||||||
|
protected final int _land = 1;
|
||||||
|
|
||||||
|
public BufferedImage CreateMap(int width, int height, IDrawingObject drawingObject)
|
||||||
|
{
|
||||||
|
_width = width;
|
||||||
|
_height = height;
|
||||||
|
_drawingObject = drawingObject;
|
||||||
|
GenerateMap();
|
||||||
|
while (!SetObjectOnMap())
|
||||||
|
{
|
||||||
|
GenerateMap();
|
||||||
|
}
|
||||||
|
return DrawMapWithObject();
|
||||||
|
}
|
||||||
|
|
||||||
|
public BufferedImage MoveObject(Direction direction)
|
||||||
|
{
|
||||||
|
float[] dim = _drawingObject.GetCurrentPosition();
|
||||||
|
|
||||||
|
if (CheckLand(dim[0], dim[1], dim[2], dim[3]) != 0)
|
||||||
|
{
|
||||||
|
_drawingObject.MoveObject(SetOppositDirection(direction));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (true)
|
||||||
|
{
|
||||||
|
_drawingObject.MoveObject(direction);
|
||||||
|
}
|
||||||
|
return DrawMapWithObject();
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean SetObjectOnMap()
|
||||||
|
{
|
||||||
|
if (_drawingObject==null || _map == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
int x = _random.nextInt(10);
|
||||||
|
int y = _random.nextInt(10);
|
||||||
|
_drawingObject.SetObject(x, y, _width, _height);
|
||||||
|
|
||||||
|
float[] dim = _drawingObject.GetCurrentPosition();
|
||||||
|
|
||||||
|
while (CheckLand(dim[0], dim[1], dim[2], dim[3]) != 2)
|
||||||
|
{
|
||||||
|
int res;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
res = CheckLand(dim[0], dim[1], dim[2], dim[3]);
|
||||||
|
if (res == 0)
|
||||||
|
{
|
||||||
|
_drawingObject.SetObject((int)dim[0], (int)dim[1], _width, _height);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dim[0] += _size_x;
|
||||||
|
}
|
||||||
|
} while (res != 2);
|
||||||
|
dim[0] = x;
|
||||||
|
dim[1] += _size_y;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private BufferedImage DrawMapWithObject()
|
||||||
|
{
|
||||||
|
BufferedImage bmp = new BufferedImage(_width, _height,BufferedImage.TYPE_INT_RGB);
|
||||||
|
if (_drawingObject == null || _map == null)
|
||||||
|
{
|
||||||
|
return bmp;
|
||||||
|
}
|
||||||
|
Graphics gr = bmp.getGraphics();
|
||||||
|
for (int i = 0; i < _map.length; ++i)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < _map[i].length; ++j)
|
||||||
|
{
|
||||||
|
if (_map[i][j] == _freeWaterArea)
|
||||||
|
{
|
||||||
|
DrawWaterPart(gr, i, j);
|
||||||
|
}
|
||||||
|
else if (_map[i][j] == _land)
|
||||||
|
{
|
||||||
|
DrawLandPart(gr, i, j);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_drawingObject.DrawingObject(gr);
|
||||||
|
return bmp;
|
||||||
|
}
|
||||||
|
private int CheckLand(float Left, float Right, float Top, float Bottom)
|
||||||
|
{
|
||||||
|
int RUi = (int)(Left / _size_x);
|
||||||
|
int RUj = (int)(Right / _size_y);
|
||||||
|
int LDi = (int)(Top / _size_x);
|
||||||
|
int LDj = (int)(Bottom / _size_y);
|
||||||
|
|
||||||
|
if (RUi < 0 || RUj < 0 || LDi >= _map[0].length || LDj >= _map.length)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
for (int x = RUi; x <= LDi; x++)
|
||||||
|
{
|
||||||
|
for (int y = RUj; y <= LDj; y++)
|
||||||
|
{
|
||||||
|
if (_map[x][y] == _land)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
private Direction SetOppositDirection(Direction dir)
|
||||||
|
{
|
||||||
|
switch (dir)
|
||||||
|
{
|
||||||
|
case Up:
|
||||||
|
return Direction.Down;
|
||||||
|
case Down:
|
||||||
|
return Direction.Up;
|
||||||
|
case Left:
|
||||||
|
return Direction.Right;
|
||||||
|
case Right:
|
||||||
|
return Direction.Left;
|
||||||
|
case None:
|
||||||
|
return Direction.None;
|
||||||
|
}
|
||||||
|
return Direction.None;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract void GenerateMap();
|
||||||
|
protected abstract void DrawWaterPart(Graphics gr, int i, int j);
|
||||||
|
protected abstract void DrawLandPart(Graphics gr, int i, int j);
|
||||||
|
}
|
22
src/Action.java
Normal file
22
src/Action.java
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.FocusEvent;
|
||||||
|
import java.awt.event.MouseAdapter;
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
|
import java.awt.event.WindowEvent;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
public class Action<T> {
|
||||||
|
private final ArrayList<Consumer<T>> listeners = new ArrayList<>();
|
||||||
|
|
||||||
|
public void addListener(Consumer<T> listener) {
|
||||||
|
listeners.add(listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Invoke(T warship) {
|
||||||
|
for (var listener : listeners) {
|
||||||
|
listener.accept(warship);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -10,4 +10,5 @@ public enum BlockCount {
|
|||||||
public int GetBlockCount(){
|
public int GetBlockCount(){
|
||||||
return Value;
|
return Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
9
src/BlockForm.java
Normal file
9
src/BlockForm.java
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
public enum BlockForm {
|
||||||
|
Rect(0),
|
||||||
|
Round(1),
|
||||||
|
Triangle(2);
|
||||||
|
public final int Value;
|
||||||
|
BlockForm(int i) {
|
||||||
|
Value=i;
|
||||||
|
}
|
||||||
|
}
|
39
src/CreaterGeneric.java
Normal file
39
src/CreaterGeneric.java
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class CreaterGeneric<T extends EntityWarship, U extends IDrawingObjectBlock> {
|
||||||
|
ArrayList<T> Warships;
|
||||||
|
ArrayList<U> Blocks;
|
||||||
|
int WarshipsCount=0;
|
||||||
|
int BlocksCount=0;
|
||||||
|
public CreaterGeneric(int warshipsCount,int blocksCount){
|
||||||
|
Warships=new ArrayList<>(warshipsCount);
|
||||||
|
Blocks=new ArrayList<>(blocksCount);
|
||||||
|
}
|
||||||
|
public int Add(T warship){
|
||||||
|
if(WarshipsCount<=Warships.size()){
|
||||||
|
Warships.add(warship);
|
||||||
|
WarshipsCount++;
|
||||||
|
return WarshipsCount-1;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
public int Add(U block){
|
||||||
|
if(BlocksCount<=Blocks.size()){
|
||||||
|
Blocks.add(block);
|
||||||
|
BlocksCount++;
|
||||||
|
return BlocksCount-1;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
public DrawingWarship NewWarshipCreating()
|
||||||
|
{
|
||||||
|
Random rand=new Random();
|
||||||
|
T warship = Warships.get(rand.nextInt(WarshipsCount));
|
||||||
|
U block = Blocks.get(rand.nextInt(BlocksCount));
|
||||||
|
if(warship instanceof EntityAdvancedWarship){
|
||||||
|
return new DrawingAdvancedWarship(warship,block);
|
||||||
|
}
|
||||||
|
return new DrawingWarship(warship,block);
|
||||||
|
}
|
||||||
|
}
|
@ -2,6 +2,7 @@ public enum Direction {
|
|||||||
Up(1),
|
Up(1),
|
||||||
Down(2),
|
Down(2),
|
||||||
Left(3),
|
Left(3),
|
||||||
Right(4);
|
Right(4),
|
||||||
|
None(0);
|
||||||
Direction(int value){}
|
Direction(int value){}
|
||||||
}
|
}
|
||||||
|
93
src/DrawingAdvancedWarship.java
Normal file
93
src/DrawingAdvancedWarship.java
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class DrawingAdvancedWarship extends DrawingWarship {
|
||||||
|
|
||||||
|
public DrawingAdvancedWarship(int speed, float weight, Color bodyColor, Color dopColor, boolean Helipad,boolean Antenna, boolean Missile,int blockForm) {
|
||||||
|
super(speed, weight, bodyColor, 120, 50);
|
||||||
|
Warship=new EntityAdvancedWarship(speed,weight,bodyColor,dopColor,Helipad,Antenna,Missile);
|
||||||
|
Blocks= GetFormOfBlock(blockForm);
|
||||||
|
Blocks.SetBlockCount(2*(int)(Math.random()*3+1));
|
||||||
|
}
|
||||||
|
public DrawingAdvancedWarship(int speed, float weight,int countblock, Color bodyColor, Color dopColor, boolean Helipad,boolean Antenna, boolean Missile) {
|
||||||
|
super(speed, weight, bodyColor, 120, 50);
|
||||||
|
Warship=new EntityAdvancedWarship(speed,weight,bodyColor,dopColor,Helipad,Antenna,Missile);
|
||||||
|
Blocks.SetBlockCount(countblock);
|
||||||
|
}
|
||||||
|
public DrawingAdvancedWarship(int speed, float weight, Color bodyColor, Color dopColor, boolean Helipad,boolean Antenna, boolean Missile,IDrawingObjectBlock blockForm) {
|
||||||
|
super(speed, weight, bodyColor, 120, 50);
|
||||||
|
Warship=new EntityAdvancedWarship(speed,weight,bodyColor,dopColor,Helipad,Antenna,Missile);
|
||||||
|
Blocks= blockForm;
|
||||||
|
}
|
||||||
|
public DrawingAdvancedWarship(EntityWarship warship,IDrawingObjectBlock block){
|
||||||
|
super(warship,block);
|
||||||
|
Warship = warship;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void SetBodyColor(Color color){
|
||||||
|
var warship=(EntityAdvancedWarship) Warship;
|
||||||
|
Warship=new EntityAdvancedWarship(warship.GetSpeed(),warship.GetWeight(),color,warship.GetDopColor(), warship.GetHelipad(), warship.GetAntenna(), warship.GetMissile());
|
||||||
|
}
|
||||||
|
public void SetDopColor(Color color){
|
||||||
|
var warship=(EntityAdvancedWarship) Warship;
|
||||||
|
Warship=new EntityAdvancedWarship(warship.GetSpeed(),warship.GetWeight(),warship.GetBodyColor(),color, warship.GetHelipad(), warship.GetAntenna(), warship.GetMissile());
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void DrawTransport(Graphics g) {
|
||||||
|
|
||||||
|
if (! (Warship instanceof EntityAdvancedWarship))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
EntityAdvancedWarship advancedWarship = (EntityAdvancedWarship)Warship;
|
||||||
|
Graphics2D g2 = (Graphics2D) g;
|
||||||
|
|
||||||
|
int [] x1 ={_startPosX+25,_startPosX+65,_startPosX+75,_startPosX+25,_startPosX+25};
|
||||||
|
int [] y1 ={_startPosY,_startPosY,_startPosY+5,_startPosY+5,_startPosY};
|
||||||
|
int [] x2 ={_startPosX+25,_startPosX+75,_startPosX+65,_startPosX+25,_startPosX+25};
|
||||||
|
int [] y2 ={_startPosY+45,_startPosY+45,_startPosY+50,_startPosY+50,_startPosY+45};
|
||||||
|
|
||||||
|
if (advancedWarship.Missile)
|
||||||
|
{
|
||||||
|
g2.setColor(advancedWarship.GetDopColor());
|
||||||
|
g2.fillPolygon(x1,y1,5);
|
||||||
|
|
||||||
|
g2.setColor(Color.BLACK);
|
||||||
|
g.drawLine(_startPosX + 25, _startPosY + 5 - 5, _startPosX + 65, _startPosY + 5 - 5);
|
||||||
|
g.drawLine(_startPosX + 65, _startPosY + 5 - 5,_startPosX + 75, _startPosY + 10 - 5);
|
||||||
|
g.drawLine(_startPosX + 75, _startPosY + 10 - 5, _startPosX + 25, _startPosY + 10 - 5);
|
||||||
|
g.drawLine(_startPosX + 25, _startPosY + 10 - 5, _startPosX + 25, _startPosY + 5 - 5);
|
||||||
|
|
||||||
|
g2.setColor(advancedWarship.GetDopColor());
|
||||||
|
g2.fillPolygon(x2,y2,5);
|
||||||
|
|
||||||
|
g2.setColor(Color.BLACK);
|
||||||
|
g.drawLine(_startPosX + 25, _startPosY + 50 - 5,_startPosX + 75, _startPosY + 50 - 5);
|
||||||
|
g.drawLine(_startPosX + 75, _startPosY + 50 - 5,_startPosX + 65, _startPosY + 55 - 5);
|
||||||
|
g.drawLine(_startPosX + 65, _startPosY + 55 - 5,_startPosX + 25, _startPosY + 55 - 5);
|
||||||
|
g.drawLine(_startPosX + 25, _startPosY + 55 - 5,_startPosX + 25, _startPosY + 50 - 5);
|
||||||
|
}
|
||||||
|
|
||||||
|
_startPosY += 5;
|
||||||
|
super.DrawTransport(g);
|
||||||
|
_startPosY -= 5;
|
||||||
|
|
||||||
|
if (advancedWarship.Helipad)
|
||||||
|
{
|
||||||
|
g2.setColor(advancedWarship.GetDopColor());
|
||||||
|
g.fillOval(_startPosX + 85, _startPosY + 20-5, 20, 20);
|
||||||
|
|
||||||
|
g2.setColor(Color.BLACK);
|
||||||
|
g.drawOval(_startPosX + 85, _startPosY + 20-5, 20, 20);
|
||||||
|
g.drawLine(_startPosX + 90, _startPosY + 25 - 5, _startPosX + 90, _startPosY + 35 - 5);
|
||||||
|
g.drawLine(_startPosX + 90+10, _startPosY + 25 - 5, _startPosX + 90+10, _startPosY + 35 - 5);
|
||||||
|
g.drawLine(_startPosX + 90, _startPosY + 30 - 5, _startPosX + 100, _startPosY + 30 - 5);
|
||||||
|
}
|
||||||
|
if (advancedWarship.Antenna)
|
||||||
|
{
|
||||||
|
g2.setColor(Color.BLACK);
|
||||||
|
g.drawLine(_startPosX + 15, _startPosY + 20 - 5, _startPosX + 15, _startPosY + 40 - 5);
|
||||||
|
g.drawLine(_startPosX +10, _startPosY + 30 - 5, _startPosX + 20, _startPosY + 30 - 5);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,9 +1,17 @@
|
|||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
|
||||||
public class DrawingBlock {
|
public class DrawingBlock implements IDrawingObjectBlock{
|
||||||
|
|
||||||
private BlockCount _block;
|
private BlockCount _block=null;
|
||||||
|
|
||||||
|
public DrawingBlock(BlockCount block) {
|
||||||
|
_block=block;
|
||||||
|
}
|
||||||
|
public DrawingBlock(int count) {
|
||||||
|
SetBlockCount(count);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void SetBlockCount(int count){
|
public void SetBlockCount(int count){
|
||||||
for (BlockCount temp: BlockCount.values())
|
for (BlockCount temp: BlockCount.values())
|
||||||
if (temp.GetBlockCount() == count){
|
if (temp.GetBlockCount() == count){
|
||||||
@ -12,6 +20,7 @@ public class DrawingBlock {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void DrawBlock(Graphics2D g,int _startPosX, int _startPosY) {
|
public void DrawBlock(Graphics2D g,int _startPosX, int _startPosY) {
|
||||||
if (_block.GetBlockCount() >= 2) {
|
if (_block.GetBlockCount() >= 2) {
|
||||||
g.setColor(Color.GRAY);
|
g.setColor(Color.GRAY);
|
||||||
@ -44,4 +53,9 @@ public class DrawingBlock {
|
|||||||
g.drawRect(_startPosX+45,_startPosY+20,10,10);
|
g.drawRect(_startPosX+45,_startPosY+20,10,10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String GetCount() {
|
||||||
|
return Integer.toString(_block.GetBlockCount());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,57 +0,0 @@
|
|||||||
import javax.swing.*;
|
|
||||||
import java.awt.*;
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
public class DrawingField extends JPanel {
|
|
||||||
private final FormWarship Field;
|
|
||||||
DrawingWarship _warship;
|
|
||||||
public DrawingField(FormWarship field) {
|
|
||||||
this.Field = field;
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
protected void paintComponent(Graphics g) {
|
|
||||||
super.paintComponent(g);
|
|
||||||
Graphics2D g2 =(Graphics2D)g;
|
|
||||||
if (_warship!=null)
|
|
||||||
_warship.DrawTransport(g2);
|
|
||||||
else return;
|
|
||||||
}
|
|
||||||
public void UpButtonAction(){
|
|
||||||
if (_warship!=null)
|
|
||||||
_warship.MoveTransport(Direction.Up);
|
|
||||||
else
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
public void DownButtonAction(){
|
|
||||||
if (_warship!=null)
|
|
||||||
_warship.MoveTransport(Direction.Down);
|
|
||||||
else
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
public void RightButtonAction(){
|
|
||||||
if (_warship!=null)
|
|
||||||
_warship.MoveTransport(Direction.Right);
|
|
||||||
else
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
public void LeftButtonAction(){
|
|
||||||
if (_warship!=null)
|
|
||||||
_warship.MoveTransport(Direction.Left);
|
|
||||||
else
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
public void CreateButtonAction(){
|
|
||||||
Random rand=new Random();
|
|
||||||
_warship=new DrawingWarship();
|
|
||||||
_warship.Init(rand.nextInt(50)+10,rand.nextInt(3000)+20000,new Color(rand.nextInt(256),rand.nextInt(256),rand.nextInt(256)));
|
|
||||||
_warship.SetPosition(rand.nextInt(100)+10,rand.nextInt(100)+10,getWidth(),getHeight());
|
|
||||||
Field.SpeedLabel.setText("Скорость: "+_warship.GetWarship().GetSpeed());
|
|
||||||
Field.WeightLabel.setText("Вес: "+_warship.GetWarship().GetWeight());
|
|
||||||
Field.BodyColorLabel.setText("Цвет: "+Integer.toHexString(_warship.GetWarship().GetBodyColor().getRGB()).substring(2));
|
|
||||||
}
|
|
||||||
public void ResizeField(){
|
|
||||||
if (_warship!=null)
|
|
||||||
_warship.ChangeBorders(getWidth(),getHeight());
|
|
||||||
else return;
|
|
||||||
}
|
|
||||||
}
|
|
54
src/DrawingObjectWarship.java
Normal file
54
src/DrawingObjectWarship.java
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class DrawingObjectWarship implements IDrawingObject {
|
||||||
|
|
||||||
|
private DrawingWarship _warship;
|
||||||
|
|
||||||
|
public DrawingObjectWarship(DrawingWarship warship)
|
||||||
|
{
|
||||||
|
_warship= warship;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float Step() {
|
||||||
|
if(_warship != null && _warship.Warship != null)
|
||||||
|
return _warship.Warship.Step;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void SetObject(int x, int y, int width, int height) {
|
||||||
|
_warship.SetPosition(x,y,width,height);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void MoveObject(Direction direction) {
|
||||||
|
_warship.MoveTransport(direction);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void DrawingObject(Graphics g) {
|
||||||
|
_warship.DrawTransport(g);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float[] GetCurrentPosition() {
|
||||||
|
if(_warship!=null)
|
||||||
|
return _warship.GetCurrentPosition();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String GetInfo() {
|
||||||
|
if(_warship==null)
|
||||||
|
return null;
|
||||||
|
return ExtentionWarship.GetDataForSave(_warship);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IDrawingObject Create(String data){
|
||||||
|
return new DrawingObjectWarship(ExtentionWarship.CreateDrawingWarship(data));
|
||||||
|
}
|
||||||
|
|
||||||
|
public DrawingWarship GetWarship() {
|
||||||
|
return _warship;
|
||||||
|
}
|
||||||
|
}
|
59
src/DrawingRoundBlocks.java
Normal file
59
src/DrawingRoundBlocks.java
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class DrawingRoundBlocks implements IDrawingObjectBlock{
|
||||||
|
private BlockCount _block;
|
||||||
|
|
||||||
|
public DrawingRoundBlocks(BlockCount block){
|
||||||
|
_block=block;
|
||||||
|
}
|
||||||
|
public DrawingRoundBlocks(int count) {
|
||||||
|
SetBlockCount(count);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void SetBlockCount(int count) {
|
||||||
|
for (BlockCount temp: BlockCount.values())
|
||||||
|
if (temp.GetBlockCount() == count){
|
||||||
|
_block=temp;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void DrawBlock(Graphics2D g, int _startPosX, int _startPosY) {
|
||||||
|
if (_block.GetBlockCount() >= 2) {
|
||||||
|
g.setColor(Color.GRAY);
|
||||||
|
g.fillOval(_startPosX + 25, _startPosY + 10, 10, 10);
|
||||||
|
g.setColor(Color.BLACK);
|
||||||
|
g.drawOval(_startPosX + 25, _startPosY + 10, 10, 10);
|
||||||
|
g.setColor(Color.GRAY);
|
||||||
|
g.fillOval(_startPosX + 25, _startPosY + 20, 10, 10);
|
||||||
|
g.setColor(Color.BLACK);
|
||||||
|
g.drawOval(_startPosX + 25, _startPosY + 20, 10, 10);
|
||||||
|
}
|
||||||
|
if (_block.GetBlockCount() >= 4) {
|
||||||
|
g.setColor(Color.GRAY);
|
||||||
|
g.fillOval(_startPosX+35,_startPosY+10,10,10);
|
||||||
|
g.setColor(Color.BLACK);
|
||||||
|
g.drawOval(_startPosX+35,_startPosY+10,10,10);
|
||||||
|
g.setColor(Color.GRAY);
|
||||||
|
g.fillOval(_startPosX+35,_startPosY+20,10,10);
|
||||||
|
g.setColor(Color.BLACK);
|
||||||
|
g.drawOval(_startPosX+35,_startPosY+20,10,10);
|
||||||
|
}
|
||||||
|
if (_block.GetBlockCount() >= 6) {
|
||||||
|
g.setColor(Color.GRAY);
|
||||||
|
g.fillOval(_startPosX+45,_startPosY+10,10,10);
|
||||||
|
g.setColor(Color.BLACK);
|
||||||
|
g.drawOval(_startPosX+45,_startPosY+10,10,10);
|
||||||
|
g.setColor(Color.GRAY);
|
||||||
|
g.fillOval(_startPosX+45,_startPosY+20,10,10);
|
||||||
|
g.setColor(Color.BLACK);
|
||||||
|
g.drawOval(_startPosX+45,_startPosY+20,10,10);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String GetCount() {
|
||||||
|
return Integer.toString(_block.GetBlockCount());
|
||||||
|
}
|
||||||
|
}
|
66
src/DrawingTriangleBlocks.java
Normal file
66
src/DrawingTriangleBlocks.java
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class DrawingTriangleBlocks implements IDrawingObjectBlock{
|
||||||
|
private BlockCount _block;
|
||||||
|
|
||||||
|
public DrawingTriangleBlocks(BlockCount block){
|
||||||
|
_block=block;
|
||||||
|
}
|
||||||
|
public DrawingTriangleBlocks(int count) {
|
||||||
|
SetBlockCount(count);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void SetBlockCount(int count) {
|
||||||
|
for (BlockCount temp: BlockCount.values())
|
||||||
|
if (temp.GetBlockCount() == count){
|
||||||
|
_block=temp;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void DrawBlock(Graphics2D g, int _startPosX, int _startPosY) {
|
||||||
|
|
||||||
|
int[] x1={_startPosX + 30,_startPosX + 35,_startPosX + 25,_startPosX + 30};
|
||||||
|
int[] y1={_startPosY + 10,_startPosY + 20,_startPosY + 20,_startPosY + 10};
|
||||||
|
int[] x2={_startPosX + 30+10,_startPosX + 35+10,_startPosX + 25+10,_startPosX + 30+10};
|
||||||
|
int[] y2={_startPosY + 10+10,_startPosY + 20+10,_startPosY + 20+10,_startPosY + 10+10};
|
||||||
|
int[] x3={_startPosX + 30+10+10,_startPosX + 35+10+10,_startPosX + 25+10+10,_startPosX + 30+10+10};
|
||||||
|
|
||||||
|
if (_block.GetBlockCount() >= 2) {
|
||||||
|
g.setColor(Color.GRAY);
|
||||||
|
g.fillPolygon(x1,y1,4);
|
||||||
|
g.setColor(Color.BLACK);
|
||||||
|
g.drawPolygon(x1,y1,4);
|
||||||
|
g.setColor(Color.GRAY);
|
||||||
|
g.fillPolygon(x1,y2,4);
|
||||||
|
g.setColor(Color.BLACK);
|
||||||
|
g.drawPolygon(x1,y2,4);
|
||||||
|
}
|
||||||
|
if (_block.GetBlockCount() >= 4) {
|
||||||
|
g.setColor(Color.GRAY);
|
||||||
|
g.fillPolygon(x2,y1,4);
|
||||||
|
g.setColor(Color.BLACK);
|
||||||
|
g.drawPolygon(x2,y1,4);
|
||||||
|
g.setColor(Color.GRAY);
|
||||||
|
g.fillPolygon(x2,y2,4);
|
||||||
|
g.setColor(Color.BLACK);
|
||||||
|
g.drawPolygon(x2,y2,4);
|
||||||
|
}
|
||||||
|
if (_block.GetBlockCount() >= 6) {
|
||||||
|
g.setColor(Color.GRAY);
|
||||||
|
g.fillPolygon(x3,y1,4);
|
||||||
|
g.setColor(Color.BLACK);
|
||||||
|
g.drawPolygon(x3,y1,4);
|
||||||
|
g.setColor(Color.GRAY);
|
||||||
|
g.fillPolygon(x3,y2,4);
|
||||||
|
g.setColor(Color.BLACK);
|
||||||
|
g.drawPolygon(x3,y2,4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String GetCount() {
|
||||||
|
return Integer.toString(_block.GetBlockCount());
|
||||||
|
}
|
||||||
|
}
|
@ -1,25 +1,81 @@
|
|||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
|
||||||
public class DrawingWarship {
|
public class DrawingWarship {
|
||||||
private EntityWarship Warship;
|
protected EntityWarship Warship;
|
||||||
public EntityWarship GetWarship(){
|
public EntityWarship GetWarship(){
|
||||||
return Warship;
|
return Warship;
|
||||||
}
|
}
|
||||||
public DrawingBlock Blocks;
|
protected IDrawingObjectBlock Blocks;
|
||||||
private int _startPosX;
|
private BlockCount _block;
|
||||||
private int _startPosY;
|
protected int _startPosX;
|
||||||
|
protected int _startPosY;
|
||||||
private Integer _pictureWidth = null;
|
private Integer _pictureWidth = null;
|
||||||
private Integer _pictureHeight = null;
|
private Integer _pictureHeight = null;
|
||||||
private final int _warshipWidth = 120;
|
private int _warshipWidth = 120;
|
||||||
private final int _warshipHeight = 40;
|
private int _warshipHeight = 40;
|
||||||
|
|
||||||
public void Init(int speed, float weight, Color bodyColor)
|
public DrawingWarship(int speed, float weight, Color bodyColor, int blockForm)
|
||||||
{
|
{
|
||||||
Warship = new EntityWarship();
|
Warship = new EntityWarship(speed, weight, bodyColor);
|
||||||
Warship.Init(speed, weight, bodyColor);
|
Blocks= GetFormOfBlock(blockForm);
|
||||||
Blocks= new DrawingBlock();
|
|
||||||
Blocks.SetBlockCount(2*(int)(Math.random()*3+1));
|
Blocks.SetBlockCount(2*(int)(Math.random()*3+1));
|
||||||
}
|
}
|
||||||
|
public DrawingWarship(int speed, float weight, Color bodyColor, IDrawingObjectBlock blockForm)
|
||||||
|
{
|
||||||
|
Warship = new EntityWarship(speed, weight, bodyColor);
|
||||||
|
Blocks= blockForm;
|
||||||
|
}
|
||||||
|
public DrawingWarship(int speed, float weight,int countblock, Color bodyColor)
|
||||||
|
{
|
||||||
|
Warship = new EntityWarship(speed, weight, bodyColor);
|
||||||
|
Blocks= GetFormOfBlock((int)(Math.random()*3+1));
|
||||||
|
Blocks.SetBlockCount(countblock);
|
||||||
|
}
|
||||||
|
public DrawingWarship(EntityWarship warship,IDrawingObjectBlock block){
|
||||||
|
Warship = warship;
|
||||||
|
Blocks = block;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetBlocks(IDrawingObjectBlock block){
|
||||||
|
Blocks=block;
|
||||||
|
}
|
||||||
|
public IDrawingObjectBlock GetBlocks(){
|
||||||
|
return Blocks;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetBodyColor(Color color){
|
||||||
|
Warship= new EntityWarship(Warship.GetSpeed(), Warship.GetWeight(), color);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IDrawingObjectBlock GetFormOfBlock(int FormOfBlock){
|
||||||
|
BlockForm temp = null;
|
||||||
|
for (BlockForm form:BlockForm.values()) {
|
||||||
|
if(form.Value==FormOfBlock){
|
||||||
|
temp = form;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(temp==null)
|
||||||
|
return null;
|
||||||
|
switch (temp){
|
||||||
|
case Rect:
|
||||||
|
return new DrawingBlock(_block);
|
||||||
|
case Round:
|
||||||
|
return new DrawingRoundBlocks(_block);
|
||||||
|
case Triangle:
|
||||||
|
return new DrawingTriangleBlocks(_block);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected DrawingWarship(int speed, float weight, Color bodyColor,int warshipWidth, int warshipHeight)
|
||||||
|
{
|
||||||
|
Warship = new EntityWarship(speed, weight, bodyColor);
|
||||||
|
Blocks= new DrawingBlock(_block);
|
||||||
|
Blocks.SetBlockCount(2*(int)(Math.random()*3+1));
|
||||||
|
_warshipWidth=warshipWidth;
|
||||||
|
_pictureHeight=warshipHeight;
|
||||||
|
}
|
||||||
|
|
||||||
public void SetPosition(int x, int y, int width, int height)
|
public void SetPosition(int x, int y, int width, int height)
|
||||||
{
|
{
|
||||||
@ -125,4 +181,12 @@ public class DrawingWarship {
|
|||||||
_startPosY = _pictureHeight - _warshipHeight;
|
_startPosY = _pictureHeight - _warshipHeight;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public float[] GetCurrentPosition() {
|
||||||
|
float[] dim = new float[4];
|
||||||
|
dim[0] = _startPosX;
|
||||||
|
dim[1] =_startPosY;
|
||||||
|
dim[2] = _startPosX + _warshipWidth;
|
||||||
|
dim[3] = _startPosY + _warshipHeight;
|
||||||
|
return dim;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
32
src/EntityAdvancedWarship.java
Normal file
32
src/EntityAdvancedWarship.java
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class EntityAdvancedWarship extends EntityWarship{
|
||||||
|
|
||||||
|
public Color DopColor;
|
||||||
|
public Color GetDopColor() {
|
||||||
|
return DopColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean Helipad;
|
||||||
|
public boolean GetHelipad() {
|
||||||
|
return Helipad;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean Antenna;
|
||||||
|
public boolean GetAntenna() {
|
||||||
|
return Antenna;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean Missile;
|
||||||
|
public boolean GetMissile() {
|
||||||
|
return Missile;
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityAdvancedWarship(int speed, float weight, Color bodyColor, Color dopColor, boolean helipad, boolean antenna, boolean missile){
|
||||||
|
super(speed,weight,bodyColor);
|
||||||
|
DopColor = dopColor;
|
||||||
|
Helipad = helipad;
|
||||||
|
Antenna = antenna;
|
||||||
|
Missile = missile;
|
||||||
|
}
|
||||||
|
}
|
@ -19,7 +19,7 @@ public class EntityWarship {
|
|||||||
|
|
||||||
public int Step;
|
public int Step;
|
||||||
|
|
||||||
public void Init(int speed, float weight, Color bodyColor)
|
public EntityWarship(int speed, float weight, Color bodyColor)
|
||||||
{
|
{
|
||||||
Random rnd = new Random();
|
Random rnd = new Random();
|
||||||
Speed = speed <= 0 ? rnd.nextInt(60)+10 : speed;
|
Speed = speed <= 0 ? rnd.nextInt(60)+10 : speed;
|
||||||
|
41
src/ExtentionWarship.java
Normal file
41
src/ExtentionWarship.java
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class ExtentionWarship {
|
||||||
|
private static final char _separatorForObject=':';
|
||||||
|
|
||||||
|
public static DrawingWarship CreateDrawingWarship(String info){
|
||||||
|
String[] strs = info.split(Character.toString(_separatorForObject));
|
||||||
|
|
||||||
|
int spd=Integer.parseInt(strs[0]);
|
||||||
|
float wght = Float.parseFloat(strs[1]);
|
||||||
|
Color bodyClr=new Color(Integer.parseInt(strs[2]));
|
||||||
|
IDrawingObjectBlock block = switch(strs[3]) {
|
||||||
|
case "DrawingBlock" -> new DrawingBlock(Integer.parseInt(strs[4]));
|
||||||
|
case "DrawingRoundBlocks" -> new DrawingRoundBlocks(Integer.parseInt(strs[4]));
|
||||||
|
case "DrawingTriangleBlocks" -> new DrawingTriangleBlocks(Integer.parseInt(strs[4]));
|
||||||
|
default -> null;
|
||||||
|
};
|
||||||
|
if (strs.length==5){
|
||||||
|
EntityWarship ent=new EntityWarship(spd,wght,bodyClr);
|
||||||
|
return new DrawingWarship(ent,block);
|
||||||
|
}
|
||||||
|
if(strs.length==9){
|
||||||
|
Color dopClr=new Color(Integer.parseInt(strs[5]));
|
||||||
|
boolean ant=Boolean.parseBoolean(strs[6]);
|
||||||
|
boolean hlpd=Boolean.parseBoolean(strs[7]);
|
||||||
|
boolean msl=Boolean.parseBoolean(strs[8]);
|
||||||
|
EntityAdvancedWarship ent = new EntityAdvancedWarship(spd,wght,bodyClr,dopClr,hlpd,ant,msl);
|
||||||
|
return new DrawingAdvancedWarship(ent,block);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String GetDataForSave(DrawingWarship drawingWarship){
|
||||||
|
var warship = drawingWarship.Warship;
|
||||||
|
var str = ""+warship.GetSpeed()+_separatorForObject+warship.GetWeight()+_separatorForObject+warship.GetBodyColor().getRGB()+_separatorForObject+drawingWarship.GetBlocks().getClass().getSimpleName()+_separatorForObject+drawingWarship.GetBlocks().GetCount();
|
||||||
|
if(!(warship instanceof EntityAdvancedWarship adv)){
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
return str+_separatorForObject+adv.GetDopColor().getRGB()+_separatorForObject+adv.GetAntenna()+_separatorForObject+adv.GetHelipad()+_separatorForObject+adv.GetMissile();
|
||||||
|
}
|
||||||
|
}
|
258
src/FormCreater.form
Normal file
258
src/FormCreater.form
Normal file
@ -0,0 +1,258 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormCreater">
|
||||||
|
<grid id="27dc6" binding="PictureBox" 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="630" height="629"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children>
|
||||||
|
<grid id="27a9" binding="PropertiesPanel" layout-manager="GridLayoutManager" row-count="8" 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>
|
||||||
|
<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>
|
||||||
|
<opaque value="true"/>
|
||||||
|
</properties>
|
||||||
|
<border type="etched" title="Настройки"/>
|
||||||
|
<children>
|
||||||
|
<vspacer id="c17c4">
|
||||||
|
<constraints>
|
||||||
|
<grid row="7" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
</vspacer>
|
||||||
|
<grid id="e26e" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||||
|
<margin top="0" left="0" bottom="0" right="0"/>
|
||||||
|
<constraints>
|
||||||
|
<grid row="2" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="etched" title="Тип корабля:"/>
|
||||||
|
<children>
|
||||||
|
<component id="beec9" class="javax.swing.JRadioButton" binding="BasicRadioButton">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Обычный корабль"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="5837d" class="javax.swing.JRadioButton" binding="AdvancedRadioButton">
|
||||||
|
<constraints>
|
||||||
|
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Продвинутый корабль"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
<grid id="d8b7b" 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>
|
||||||
|
<grid row="0" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="etched" title="Характеристики корабля:"/>
|
||||||
|
<children>
|
||||||
|
<component id="9e0cc" class="javax.swing.JTextField" binding="WeightTextField">
|
||||||
|
<constraints>
|
||||||
|
<grid row="1" column="1" 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>
|
||||||
|
<component id="67385" class="javax.swing.JTextField" binding="SpeedTextField">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="1" 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>
|
||||||
|
<component id="77c84" class="javax.swing.JLabel" binding="SetWeightLabel">
|
||||||
|
<constraints>
|
||||||
|
<grid row="1" 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="ff8c4" class="javax.swing.JLabel" binding="SetSpeedLabel">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Скорость"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
<grid id="d3b9d" binding="CargoPanel" layout-manager="GridLayoutManager" row-count="3" 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="4" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="etched" title="Характеристики груза:"/>
|
||||||
|
<children>
|
||||||
|
<component id="fd3ec" class="javax.swing.JRadioButton" binding="TriangleFormRadioButton">
|
||||||
|
<constraints>
|
||||||
|
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Треугольные ящики"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="d03eb" class="javax.swing.JRadioButton" binding="RoundFormRadioButton">
|
||||||
|
<constraints>
|
||||||
|
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<label value="Круглые ящики"/>
|
||||||
|
<text value="Круглые ящики"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="5048f" class="javax.swing.JRadioButton" binding="RectangleFormRadioButton">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Прямоугольные ящики"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
<grid id="e7910" binding="CountOfBlocksPanel" layout-manager="GridLayoutManager" row-count="3" 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="3" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="etched" title="Количество ящиков:"/>
|
||||||
|
<children>
|
||||||
|
<component id="f4e43" class="javax.swing.JRadioButton" binding="SixRadioButton">
|
||||||
|
<constraints>
|
||||||
|
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="6"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="38916" class="javax.swing.JRadioButton" binding="FourRadioButton">
|
||||||
|
<constraints>
|
||||||
|
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="4"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="538af" class="javax.swing.JRadioButton" binding="TwoRadioButton">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="2"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
<grid id="ded4" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||||
|
<margin top="0" left="0" bottom="0" right="0"/>
|
||||||
|
<constraints>
|
||||||
|
<grid row="6" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children>
|
||||||
|
<component id="413bc" class="javax.swing.JButton" binding="ShowWarshipButton">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" 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>
|
||||||
|
<label value="Показать"/>
|
||||||
|
<text value="Показать"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="8cb53" class="javax.swing.JButton" binding="ChooseButton">
|
||||||
|
<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>
|
||||||
|
<label value="Выбрать"/>
|
||||||
|
<text value="Выбрать"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
<vspacer id="106a9">
|
||||||
|
<constraints>
|
||||||
|
<grid row="5" 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>
|
||||||
|
<grid id="fc97" layout-manager="GridLayoutManager" row-count="3" 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="1" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="etched" title="Улучшения:"/>
|
||||||
|
<children>
|
||||||
|
<component id="fca4f" class="javax.swing.JCheckBox" binding="MissileCheckBox">
|
||||||
|
<constraints>
|
||||||
|
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<label value="Боевые ракеты"/>
|
||||||
|
<text value="Боевые ракеты"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="a7f46" class="javax.swing.JCheckBox" binding="AntennaCheckBox">
|
||||||
|
<constraints>
|
||||||
|
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<label value="Антенна"/>
|
||||||
|
<text value="Антенна"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="632da" class="javax.swing.JCheckBox" binding="HelipadCheckBox">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<label value="Вертолетная площадка"/>
|
||||||
|
<text value="Вертолетная площадка"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
<hspacer id="ca2ae">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" 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>
|
||||||
|
<buttonGroups>
|
||||||
|
<group name="Entity">
|
||||||
|
<member id="beec9"/>
|
||||||
|
<member id="5837d"/>
|
||||||
|
</group>
|
||||||
|
<group name="Form">
|
||||||
|
<member id="5048f"/>
|
||||||
|
<member id="d03eb"/>
|
||||||
|
<member id="fd3ec"/>
|
||||||
|
</group>
|
||||||
|
<group name="Count">
|
||||||
|
<member id="f4e43"/>
|
||||||
|
<member id="38916"/>
|
||||||
|
<member id="538af"/>
|
||||||
|
</group>
|
||||||
|
</buttonGroups>
|
||||||
|
</form>
|
132
src/FormCreater.java
Normal file
132
src/FormCreater.java
Normal file
@ -0,0 +1,132 @@
|
|||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class FormCreater extends JDialog{
|
||||||
|
private JLabel SetSpeedLabel;
|
||||||
|
private JPanel PropertiesPanel;
|
||||||
|
private JTextField SpeedTextField;
|
||||||
|
private JLabel SetWeightLabel;
|
||||||
|
private JTextField WeightTextField;
|
||||||
|
private JRadioButton BasicRadioButton;
|
||||||
|
private JRadioButton AdvancedRadioButton;
|
||||||
|
private JCheckBox MissileCheckBox;
|
||||||
|
private JCheckBox AntennaCheckBox;
|
||||||
|
private JCheckBox HelipadCheckBox;
|
||||||
|
private JPanel CargoPanel;
|
||||||
|
private JRadioButton TriangleFormRadioButton;
|
||||||
|
private JRadioButton RoundFormRadioButton;
|
||||||
|
private JRadioButton RectangleFormRadioButton;
|
||||||
|
private JPanel CountOfBlocksPanel;
|
||||||
|
private JRadioButton SixRadioButton;
|
||||||
|
private JRadioButton FourRadioButton;
|
||||||
|
private JRadioButton TwoRadioButton;
|
||||||
|
private JButton ShowWarshipButton;
|
||||||
|
private JButton ChooseButton;
|
||||||
|
private JPanel PictureBox;
|
||||||
|
BlockCount block=null;
|
||||||
|
IDrawingObjectBlock fblock=null;
|
||||||
|
private final CreaterGeneric<EntityWarship,IDrawingObjectBlock> createrGeneric=new CreaterGeneric<>(40,40);
|
||||||
|
private DrawingWarship _warship;
|
||||||
|
private DrawingWarship selectedWarship;
|
||||||
|
|
||||||
|
public FormCreater(){
|
||||||
|
setTitle("Военный корабль");
|
||||||
|
setContentPane(PictureBox);
|
||||||
|
setResizable(false);
|
||||||
|
setSize(1000,500);
|
||||||
|
ShowWindow();
|
||||||
|
setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void paint(Graphics g) {
|
||||||
|
super.paint(g);
|
||||||
|
Graphics2D g2d = (Graphics2D) PictureBox.getGraphics();
|
||||||
|
if (_warship != null) {
|
||||||
|
_warship.DrawTransport(g2d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void ShowWindow(){
|
||||||
|
|
||||||
|
TwoRadioButton.addActionListener(e -> {
|
||||||
|
block=BlockCount.TwoBlocks;
|
||||||
|
});
|
||||||
|
FourRadioButton.addActionListener(e -> {
|
||||||
|
block=BlockCount.FourBlocks;
|
||||||
|
});
|
||||||
|
SixRadioButton.addActionListener(e -> {
|
||||||
|
block=BlockCount.SixBlocks;
|
||||||
|
});
|
||||||
|
|
||||||
|
RectangleFormRadioButton.addActionListener(e -> {
|
||||||
|
if(block==null){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
fblock=new DrawingBlock(block);
|
||||||
|
if(fblock==null)
|
||||||
|
return;
|
||||||
|
fblock.SetBlockCount(block.GetBlockCount());
|
||||||
|
createrGeneric.Add(fblock);
|
||||||
|
});
|
||||||
|
|
||||||
|
RoundFormRadioButton.addActionListener(e -> {
|
||||||
|
if(block==null){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
fblock=new DrawingRoundBlocks(block);
|
||||||
|
if(fblock==null)
|
||||||
|
return;
|
||||||
|
fblock.SetBlockCount(block.GetBlockCount());
|
||||||
|
createrGeneric.Add(fblock);
|
||||||
|
});
|
||||||
|
|
||||||
|
TriangleFormRadioButton.addActionListener(e -> {
|
||||||
|
if(block==null){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
fblock=new DrawingTriangleBlocks(block);
|
||||||
|
if(fblock==null)
|
||||||
|
return;
|
||||||
|
fblock.SetBlockCount(block.GetBlockCount());
|
||||||
|
createrGeneric.Add(fblock);
|
||||||
|
});
|
||||||
|
|
||||||
|
BasicRadioButton.addActionListener(e -> {
|
||||||
|
Color color=JColorChooser.showDialog(this,"Выберите цвет корпуса корабля",Color.WHITE);
|
||||||
|
if(Integer.parseInt(SpeedTextField.getText())==0 || Integer.parseInt(WeightTextField.getText())==0 || color==null){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
createrGeneric.Add(new EntityWarship(Integer.parseInt(SpeedTextField.getText()),Integer.parseInt(WeightTextField.getText()),color));
|
||||||
|
});
|
||||||
|
|
||||||
|
AdvancedRadioButton.addActionListener(e -> {
|
||||||
|
Color color1=JColorChooser.showDialog(this,"Выберите цвет корпуса корабля",Color.WHITE);
|
||||||
|
if(Integer.parseInt(SpeedTextField.getText())==0 || Integer.parseInt(WeightTextField.getText())==0 || color1==null){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Color color2=JColorChooser.showDialog(this,"Выберите цвет модификаций корабля",Color.WHITE);
|
||||||
|
if(color2==null){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
createrGeneric.Add(new EntityAdvancedWarship(Integer.parseInt(SpeedTextField.getText()),Integer.parseInt(WeightTextField.getText()),
|
||||||
|
color1,color2,HelipadCheckBox.isSelected(),AntennaCheckBox.isSelected(),MissileCheckBox.isSelected()));
|
||||||
|
});
|
||||||
|
|
||||||
|
ShowWarshipButton.addActionListener(e -> {
|
||||||
|
Random rand=new Random();
|
||||||
|
_warship=createrGeneric.NewWarshipCreating();
|
||||||
|
_warship.SetPosition(rand.nextInt(100),rand.nextInt(100),getWidth(),getHeight());
|
||||||
|
repaint();
|
||||||
|
});
|
||||||
|
ChooseButton.addActionListener(e -> {
|
||||||
|
selectedWarship=_warship;
|
||||||
|
dispose();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
public DrawingWarship getSelectedWarship() {
|
||||||
|
return selectedWarship;
|
||||||
|
}
|
||||||
|
}
|
198
src/FormMapWithSetWarships.form
Normal file
198
src/FormMapWithSetWarships.form
Normal file
@ -0,0 +1,198 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormMapWithSetWarships">
|
||||||
|
<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="8" y="20" width="691" height="602"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children>
|
||||||
|
<grid id="7fa54" binding="PictureBox" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||||
|
<margin top="0" left="0" bottom="0" right="0"/>
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children>
|
||||||
|
<hspacer id="53f34">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="7" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
</hspacer>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
<grid id="4ec10" binding="GroupBoxTools" layout-manager="GridLayoutManager" row-count="12" 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="1" col-span="1" vsize-policy="3" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="bevel-lowered" title="Инструменты" title-justification="1" title-position="2">
|
||||||
|
<font/>
|
||||||
|
</border>
|
||||||
|
<children>
|
||||||
|
<vspacer id="b5fa4">
|
||||||
|
<constraints>
|
||||||
|
<grid row="9" column="1" 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="5312c" class="javax.swing.JButton" binding="ButtonAddWarship">
|
||||||
|
<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="d2569" class="javax.swing.JButton" binding="ButtonRemoveWarship">
|
||||||
|
<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="a8d48" class="javax.swing.JButton" binding="ButtonShowStorage">
|
||||||
|
<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="c5558" class="javax.swing.JButton" binding="ButtonShowOnMap">
|
||||||
|
<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="11722" class="javax.swing.JButton" binding="ButtonDown">
|
||||||
|
<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>
|
||||||
|
<icon value="arrowDown.jpg"/>
|
||||||
|
<selectedIcon value="arrowDown.jpg"/>
|
||||||
|
<text value=""/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="a2c02" class="javax.swing.JButton" binding="ButtonUp">
|
||||||
|
<constraints>
|
||||||
|
<grid row="10" 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="arrowUp.jpg"/>
|
||||||
|
<selectedIcon value="arrowUp.jpg"/>
|
||||||
|
<text value=""/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="2380f" class="javax.swing.JButton" binding="ButtonLeft">
|
||||||
|
<constraints>
|
||||||
|
<grid row="11" 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="arrowLeft.jpg"/>
|
||||||
|
<selectedIcon value="arrowLeft.jpg"/>
|
||||||
|
<text value=""/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="de75d" class="javax.swing.JButton" binding="ButtonRight">
|
||||||
|
<constraints>
|
||||||
|
<grid row="11" 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="arrowRight.jpg"/>
|
||||||
|
<selectedIcon value="arrowRight.jpg"/>
|
||||||
|
<text value=""/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="b49b1" class="javax.swing.JTextField" binding="TextBoxPosition">
|
||||||
|
<constraints>
|
||||||
|
<grid row="3" 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>
|
||||||
|
<vspacer id="d7861">
|
||||||
|
<constraints>
|
||||||
|
<grid row="6" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
</vspacer>
|
||||||
|
<vspacer id="42f1e">
|
||||||
|
<constraints>
|
||||||
|
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
</vspacer>
|
||||||
|
<grid id="93fdf" binding="MapPanel" layout-manager="GridLayoutManager" row-count="5" 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="3" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<name value=""/>
|
||||||
|
</properties>
|
||||||
|
<border type="bevel-lowered" title="Карты" title-justification="1" title-position="2"/>
|
||||||
|
<children>
|
||||||
|
<component id="cd72b" class="javax.swing.JComboBox" binding="СomboBoxSelectorMap">
|
||||||
|
<constraints>
|
||||||
|
<grid row="1" 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="Вторая карта"/>
|
||||||
|
</model>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="19c2f" class="javax.swing.JTextField" binding="TextFieldMap">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" 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>
|
||||||
|
<component id="ac509" class="javax.swing.JButton" binding="CreateMapButton">
|
||||||
|
<constraints>
|
||||||
|
<grid row="2" 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="bf9c2" class="javax.swing.JButton" binding="DeleteMapButton">
|
||||||
|
<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="2aa62" class="javax.swing.JList" binding="ListBoxMaps">
|
||||||
|
<constraints>
|
||||||
|
<grid row="3" 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>
|
||||||
|
<component id="2934d" class="javax.swing.JButton" binding="ButtonShowDeleted">
|
||||||
|
<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>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
</form>
|
308
src/FormMapWithSetWarships.java
Normal file
308
src/FormMapWithSetWarships.java
Normal file
@ -0,0 +1,308 @@
|
|||||||
|
import javax.swing.*;
|
||||||
|
import javax.swing.filechooser.FileNameExtensionFilter;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public class FormMapWithSetWarships extends JFrame{
|
||||||
|
|
||||||
|
private JComboBox СomboBoxSelectorMap;
|
||||||
|
private JButton ButtonAddWarship;
|
||||||
|
private JTextField TextBoxPosition;
|
||||||
|
private JButton ButtonRemoveWarship;
|
||||||
|
private JButton ButtonShowStorage;
|
||||||
|
private JButton ButtonShowOnMap;
|
||||||
|
private JButton ButtonDown;
|
||||||
|
private JButton ButtonUp;
|
||||||
|
private JButton ButtonLeft;
|
||||||
|
private JButton ButtonRight;
|
||||||
|
private JPanel PictureBox;
|
||||||
|
private JPanel MainPanel;
|
||||||
|
private JPanel GroupBoxTools;
|
||||||
|
private JTextField TextFieldMap;
|
||||||
|
private JButton CreateMapButton;
|
||||||
|
private JButton DeleteMapButton;
|
||||||
|
private JList ListBoxMaps;
|
||||||
|
private JPanel MapPanel;
|
||||||
|
private JButton ButtonShowDeleted;
|
||||||
|
private JMenuBar MenuBar;
|
||||||
|
private Image bufferedImage;
|
||||||
|
private MapsCollection _mapsCollection;
|
||||||
|
private final HashMap<String,AbstractMap> _mapsDict=new HashMap<String,AbstractMap>(){
|
||||||
|
{
|
||||||
|
put("Первая карта",new SimpleMap());
|
||||||
|
put("Вторая карта",new SecondMap());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public FormMapWithSetWarships(){
|
||||||
|
setTitle("Военный корабль");
|
||||||
|
setContentPane(MainPanel);
|
||||||
|
setResizable(false);
|
||||||
|
setSize(1000,685);
|
||||||
|
ShowWindow();
|
||||||
|
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
setVisible(true);
|
||||||
|
_mapsCollection=new MapsCollection(getWidth(),getHeight());
|
||||||
|
СomboBoxSelectorMap.removeAllItems();
|
||||||
|
for(String elem:_mapsDict.keySet()){
|
||||||
|
СomboBoxSelectorMap.addItem(elem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void paint(Graphics g) {
|
||||||
|
super.paint(g);
|
||||||
|
|
||||||
|
if (bufferedImage != null) {
|
||||||
|
PictureBox.paintComponents(bufferedImage.getGraphics());
|
||||||
|
PictureBox.getGraphics().drawImage(bufferedImage, 0, 0, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ReloadMaps()
|
||||||
|
{
|
||||||
|
int index = ListBoxMaps.getSelectedIndex();
|
||||||
|
ListBoxMaps.setListData(_mapsCollection.Keys().toArray(new String[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);
|
||||||
|
}
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ShowWindow(){
|
||||||
|
|
||||||
|
MenuBar=new JMenuBar();
|
||||||
|
|
||||||
|
JMenu fileMenu =new JMenu("Файл");
|
||||||
|
MenuBar.add(fileMenu);
|
||||||
|
|
||||||
|
JMenuItem SaveMenuItem = new JMenuItem("Сохранить");
|
||||||
|
SaveMenuItem.addActionListener(e -> {
|
||||||
|
JFileChooser dialog = new JFileChooser();
|
||||||
|
dialog.setFileFilter(new FileNameExtensionFilter("txt", "txt"));
|
||||||
|
dialog.showSaveDialog(this);
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (_mapsCollection.SaveData(dialog.getSelectedFile().getAbsolutePath())) {
|
||||||
|
JOptionPane.showMessageDialog(this, "Сохранение прошло успешно", "Итог", JOptionPane.INFORMATION_MESSAGE);
|
||||||
|
} else {
|
||||||
|
JOptionPane.showMessageDialog(this, "Не сохранилось", "Итог", JOptionPane.ERROR_MESSAGE);
|
||||||
|
}
|
||||||
|
} catch (IOException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
fileMenu.add(SaveMenuItem);
|
||||||
|
|
||||||
|
JMenuItem LoadMenuItem = new JMenuItem("Загрузить");
|
||||||
|
LoadMenuItem.addActionListener(e -> {
|
||||||
|
JFileChooser dialog = new JFileChooser();
|
||||||
|
dialog.setFileFilter(new FileNameExtensionFilter("txt", "txt"));
|
||||||
|
dialog.showOpenDialog(this);
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (_mapsCollection.LoadData(dialog.getSelectedFile().getAbsolutePath())) {
|
||||||
|
ReloadMaps();
|
||||||
|
JOptionPane.showMessageDialog(this, "Загрузка прошла успешно", "Итог", JOptionPane.INFORMATION_MESSAGE);
|
||||||
|
} else {
|
||||||
|
JOptionPane.showMessageDialog(this, "Не загрузилось", "Итог", JOptionPane.ERROR_MESSAGE);
|
||||||
|
}
|
||||||
|
} catch (IOException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
fileMenu.add(LoadMenuItem);
|
||||||
|
|
||||||
|
JMenuItem SaveMapMenuItem = new JMenuItem("Сохранить карту");
|
||||||
|
SaveMapMenuItem.addActionListener(e -> {
|
||||||
|
JFileChooser dialog = new JFileChooser();
|
||||||
|
dialog.setFileFilter(new FileNameExtensionFilter("txt", "txt"));
|
||||||
|
dialog.showSaveDialog(this);
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (_mapsCollection.SaveMap((String) Optional.ofNullable(ListBoxMaps.getSelectedValue()).orElse(""), dialog.getSelectedFile().getAbsolutePath())) {
|
||||||
|
JOptionPane.showMessageDialog(this, "Сохранение прошло успешно", "Итог", JOptionPane.INFORMATION_MESSAGE);
|
||||||
|
} else {
|
||||||
|
JOptionPane.showMessageDialog(this, "Не сохранилось", "Итог", JOptionPane.ERROR_MESSAGE);
|
||||||
|
}
|
||||||
|
} catch (IOException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
fileMenu.add(SaveMapMenuItem);
|
||||||
|
|
||||||
|
JMenuItem LoadMapMenuItem = new JMenuItem("Загрузить карту");
|
||||||
|
LoadMapMenuItem.addActionListener(e -> {
|
||||||
|
JFileChooser dialog = new JFileChooser();
|
||||||
|
dialog.setFileFilter(new FileNameExtensionFilter("txt", "txt"));
|
||||||
|
dialog.showOpenDialog(this);
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (_mapsCollection.LoadMap(dialog.getSelectedFile().getAbsolutePath())) {
|
||||||
|
ReloadMaps();
|
||||||
|
JOptionPane.showMessageDialog(this, "Загрузка прошла успешно", "Итог", JOptionPane.INFORMATION_MESSAGE);
|
||||||
|
} else {
|
||||||
|
JOptionPane.showMessageDialog(this, "Не загрузилось", "Итог", JOptionPane.ERROR_MESSAGE);
|
||||||
|
}
|
||||||
|
} catch (IOException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
fileMenu.add(LoadMapMenuItem);
|
||||||
|
|
||||||
|
setJMenuBar(MenuBar);
|
||||||
|
|
||||||
|
ListBoxMaps.addListSelectionListener(e -> {
|
||||||
|
if(ListBoxMaps.getSelectedIndex()==-1)
|
||||||
|
return;
|
||||||
|
bufferedImage = _mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).ShowSet();
|
||||||
|
repaint();
|
||||||
|
});
|
||||||
|
|
||||||
|
DeleteMapButton.addActionListener(e -> {
|
||||||
|
if (ListBoxMaps.getSelectedIndex() == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(JOptionPane.showConfirmDialog(this,"Удалить карту "+ListBoxMaps.getSelectedValue().toString()+"?",
|
||||||
|
"Удаление",JOptionPane.YES_NO_OPTION)==0)
|
||||||
|
{
|
||||||
|
_mapsCollection.DelMap(ListBoxMaps.getSelectedValue().toString());
|
||||||
|
ReloadMaps();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
CreateMapButton.addActionListener(e -> {
|
||||||
|
if (СomboBoxSelectorMap.getSelectedIndex() == -1 || TextFieldMap.getText()==null || TextFieldMap.getText().equals(""))
|
||||||
|
{
|
||||||
|
JOptionPane.showMessageDialog(this,"Не все данные заполнены","Ошибка",JOptionPane.ERROR_MESSAGE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!_mapsDict.containsKey(СomboBoxSelectorMap.getSelectedItem()))
|
||||||
|
{
|
||||||
|
JOptionPane.showMessageDialog(this,"Нет такой карты","Ошибка",JOptionPane.ERROR_MESSAGE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_mapsCollection.AddMap(TextFieldMap.getText(), _mapsDict.get(СomboBoxSelectorMap.getSelectedItem().toString()));
|
||||||
|
ReloadMaps();
|
||||||
|
});
|
||||||
|
|
||||||
|
ButtonShowOnMap.addActionListener(e -> {
|
||||||
|
if (ListBoxMaps.getSelectedIndex() ==-1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
bufferedImage = _mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).ShowOnMap();
|
||||||
|
repaint();
|
||||||
|
});
|
||||||
|
|
||||||
|
ButtonShowStorage.addActionListener(e -> {
|
||||||
|
if (ListBoxMaps.getSelectedIndex() ==-1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
bufferedImage = _mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).ShowSet();
|
||||||
|
repaint();
|
||||||
|
});
|
||||||
|
|
||||||
|
ButtonAddWarship.addActionListener(e -> {
|
||||||
|
if (ListBoxMaps.getSelectedIndex() ==-1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
FormWarshipConfig dialog=new FormWarshipConfig();
|
||||||
|
dialog.addListener(obj -> {
|
||||||
|
if (obj!=null) {
|
||||||
|
DrawingObjectWarship warship = new DrawingObjectWarship(obj);
|
||||||
|
|
||||||
|
if (_mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).plus(warship)>=0) {
|
||||||
|
JOptionPane.showMessageDialog(this, "Объект добавлен", "Успех", JOptionPane.INFORMATION_MESSAGE);
|
||||||
|
bufferedImage = _mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).ShowSet();
|
||||||
|
repaint();
|
||||||
|
} else {
|
||||||
|
JOptionPane.showMessageDialog(this, "Не удалось добавить объект", "Ошибка",JOptionPane.INFORMATION_MESSAGE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
dialog.setVisible(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
ButtonRemoveWarship.addActionListener(e -> {
|
||||||
|
String txt=TextBoxPosition.getText();
|
||||||
|
if (txt==null||ListBoxMaps.getSelectedIndex() ==-1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int result = JOptionPane.showConfirmDialog(
|
||||||
|
this,
|
||||||
|
"Удалить объект?",
|
||||||
|
"Удаление",
|
||||||
|
JOptionPane.YES_NO_CANCEL_OPTION);
|
||||||
|
if (result!=0)
|
||||||
|
return;
|
||||||
|
int pos = Integer.parseInt(txt);
|
||||||
|
if(_mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).minus(pos)!=null){
|
||||||
|
JOptionPane.showMessageDialog(this, "Объект удален", "Успех", JOptionPane.INFORMATION_MESSAGE);
|
||||||
|
bufferedImage = _mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).ShowSet();
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
JOptionPane.showMessageDialog(this,"Не удалось удалить объект","Ошибка",JOptionPane.INFORMATION_MESSAGE);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
ButtonShowDeleted.addActionListener(e -> {
|
||||||
|
if (ListBoxMaps.getSelectedIndex()==-1)
|
||||||
|
return;
|
||||||
|
DrawingObjectWarship warship=(DrawingObjectWarship)_mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).GetWarshipInDeleted();
|
||||||
|
if(warship!=null){
|
||||||
|
FormWarship dialog=new FormWarship();
|
||||||
|
dialog.SetDrawingWarship(warship.GetWarship());
|
||||||
|
dialog.setSize(1200,700);
|
||||||
|
dialog.setModalityType(Dialog.ModalityType.APPLICATION_MODAL);
|
||||||
|
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
||||||
|
dialog.setVisible(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
ButtonUp.addActionListener(e -> {
|
||||||
|
if (ListBoxMaps.getSelectedIndex() !=-1) {
|
||||||
|
bufferedImage = _mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).MoveObject(Direction.Up);
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
ButtonDown.addActionListener(e -> {
|
||||||
|
if (ListBoxMaps.getSelectedIndex() !=-1) {
|
||||||
|
bufferedImage = _mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).MoveObject(Direction.Down);
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
ButtonRight.addActionListener(e -> {
|
||||||
|
if (ListBoxMaps.getSelectedIndex() !=-1) {
|
||||||
|
bufferedImage = _mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).MoveObject(Direction.Right);
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
ButtonLeft.addActionListener(e -> {
|
||||||
|
if (ListBoxMaps.getSelectedIndex() !=-1) {
|
||||||
|
bufferedImage = _mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).MoveObject(Direction.Left);
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
182
src/FormWarship.form
Normal file
182
src/FormWarship.form
Normal file
@ -0,0 +1,182 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormWarship">
|
||||||
|
<grid id="27dc6" binding="PictureBox" layout-manager="GridLayoutManager" row-count="3" 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="660" height="507"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children>
|
||||||
|
<grid id="11e3d" layout-manager="GridLayoutManager" row-count="1" 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="2" 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>
|
||||||
|
<component id="d468f" class="javax.swing.JLabel" binding="SpeedLabel">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Скорость: "/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<hspacer id="321ab">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="3" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
</hspacer>
|
||||||
|
<component id="d033b" class="javax.swing.JLabel" binding="WeightLabel">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Вес: "/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="ba46a" class="javax.swing.JLabel" binding="BodyColorLabel">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Цвет: "/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
<grid id="ba3a6" layout-manager="GridLayoutManager" row-count="2" 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="4" 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="f38f9" class="javax.swing.JButton" binding="ButtonLeft">
|
||||||
|
<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>
|
||||||
|
<icon value="arrowLeft.jpg"/>
|
||||||
|
<text value=""/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="ab65" class="javax.swing.JButton" binding="ButtonDown">
|
||||||
|
<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>
|
||||||
|
<icon value="arrowDown.jpg"/>
|
||||||
|
<text value=""/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="ae569" class="javax.swing.JButton" binding="ButtonRight">
|
||||||
|
<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="arrowRight.jpg"/>
|
||||||
|
<text value=""/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="8e604" class="javax.swing.JButton" binding="ButtonUp">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" 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="arrowUp.jpg"/>
|
||||||
|
<text value=""/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
<grid id="98f8a" 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>
|
||||||
|
<grid row="1" 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="6de46" class="javax.swing.JButton" binding="ButtonCreate">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" 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="e329e" class="javax.swing.JButton" binding="ButtonCreateModif">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" 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>
|
||||||
|
<hspacer id="73825">
|
||||||
|
<constraints>
|
||||||
|
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
</hspacer>
|
||||||
|
<vspacer id="5a84c">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
</vspacer>
|
||||||
|
<grid id="e85d9" 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="1" column="5" 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>
|
||||||
|
<hspacer id="e5ed3">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" 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>
|
||||||
|
<grid id="a3aed" 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="1" 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>
|
||||||
|
<hspacer id="c4971">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" 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>
|
||||||
|
<grid id="c2e3" 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="1" column="3" 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="f6508" class="javax.swing.JButton" binding="ButtonSelect">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" 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>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
</form>
|
@ -1,136 +1,117 @@
|
|||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.*;
|
import java.awt.event.ComponentAdapter;
|
||||||
public class FormWarship extends JFrame{
|
import java.awt.event.ComponentEvent;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class FormWarship extends JDialog{
|
||||||
private int Width;
|
private int Width;
|
||||||
private int Height;
|
private int Height;
|
||||||
|
DrawingWarship SelectedWarship;
|
||||||
JPanel BottomPanel = new JPanel();
|
private JButton ButtonDown;
|
||||||
JPanel CreatePanel = new JPanel();
|
private JButton ButtonRight;
|
||||||
JPanel BottomAndCreatePanel = new JPanel();
|
private JButton ButtonLeft;
|
||||||
JPanel DimentionPanel = new JPanel();
|
private JButton ButtonUp;
|
||||||
JPanel UPanel = new JPanel();
|
private JButton ButtonCreate;
|
||||||
JPanel DPanel = new JPanel();
|
private JButton ButtonCreateModif;
|
||||||
JPanel LRPanel = new JPanel();
|
public JLabel SpeedLabel;
|
||||||
|
public JLabel WeightLabel;
|
||||||
JLabel SpeedLabel = new JLabel("Скорость: ");
|
public JLabel BodyColorLabel;
|
||||||
JLabel WeightLabel = new JLabel("Вес: ");
|
private JPanel PictureBox;
|
||||||
JLabel BodyColorLabel = new JLabel("Цвет: ");
|
private JButton ButtonSelect;
|
||||||
|
private DrawingWarship _warship=null;
|
||||||
DrawingField field = new DrawingField(this);
|
|
||||||
|
|
||||||
JButton ButtonCreate=new JButton("Создать");
|
|
||||||
|
|
||||||
Icon iconUp = new ImageIcon("Resource\\arrowUp.jpg");
|
|
||||||
JButton ButtonUp=new JButton(iconUp);
|
|
||||||
|
|
||||||
Icon iconDown = new ImageIcon("Resource\\arrowDown.jpg");
|
|
||||||
JButton ButtonDown=new JButton(iconDown);
|
|
||||||
|
|
||||||
Icon iconRight = new ImageIcon("Resource\\arrowRight.jpg");
|
|
||||||
JButton ButtonRight=new JButton(iconRight);
|
|
||||||
|
|
||||||
Icon iconLeft = new ImageIcon("Resource\\arrowLeft.jpg");
|
|
||||||
JButton ButtonLeft=new JButton(iconLeft);
|
|
||||||
|
|
||||||
|
|
||||||
public FormWarship(){
|
public FormWarship(){
|
||||||
super("Военный корабль");
|
setTitle("Военный корабль");
|
||||||
setSize(700,400);
|
setContentPane(PictureBox);
|
||||||
Width=getWidth();
|
setSize(1000,500);
|
||||||
Height=getHeight();
|
setResizable(false);
|
||||||
ShowWindow();
|
ShowWindow();
|
||||||
RefreshWindow();
|
setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
|
||||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
||||||
setVisible(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ShowWindow(){
|
private void SetData() {
|
||||||
|
Random rand=new Random();
|
||||||
|
_warship.SetPosition(rand.nextInt(100)+10,rand.nextInt(100)+10,getWidth(),getHeight());
|
||||||
|
SpeedLabel.setText("Скорость: "+_warship.GetWarship().GetSpeed());
|
||||||
|
WeightLabel.setText("Вес: "+_warship.GetWarship().GetWeight());
|
||||||
|
BodyColorLabel.setText("Цвет: "+Integer.toHexString(_warship.GetWarship().GetBodyColor().getRGB()).substring(2));
|
||||||
|
}
|
||||||
|
|
||||||
Dimension dimen=new Dimension(30,30);
|
@Override
|
||||||
|
public void paint(Graphics g) {
|
||||||
|
super.paint(g);
|
||||||
|
|
||||||
ButtonUp.setPreferredSize(dimen);
|
if (_warship != null) {
|
||||||
ButtonUp.addActionListener(e->{
|
PictureBox.paintComponents(PictureBox.getGraphics());
|
||||||
field.UpButtonAction();
|
_warship.DrawTransport(g);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ShowWindow(){
|
||||||
|
|
||||||
|
ButtonCreate.addActionListener(e -> {
|
||||||
|
Random rand=new Random();
|
||||||
|
_warship=new DrawingWarship(rand.nextInt(50)+10,rand.nextInt(3000)+20000,new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256)),rand.nextInt(3));
|
||||||
|
SetData();
|
||||||
repaint();
|
repaint();
|
||||||
});
|
});
|
||||||
|
ButtonCreateModif.addActionListener(e -> {
|
||||||
ButtonDown.setPreferredSize(dimen);
|
Random rand=new Random();
|
||||||
ButtonDown.addActionListener(e->{
|
_warship = new DrawingAdvancedWarship(rand.nextInt(50) + 10, rand.nextInt(3000) + 20000, new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256)),
|
||||||
field.DownButtonAction();
|
new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256)), rand.nextBoolean(), rand.nextBoolean(), rand.nextBoolean(),rand.nextInt(3));
|
||||||
|
SetData();
|
||||||
repaint();
|
repaint();
|
||||||
});
|
});
|
||||||
|
ButtonUp.addActionListener(e -> {
|
||||||
ButtonRight.setPreferredSize(dimen);
|
if(_warship == null)
|
||||||
ButtonRight.addActionListener(e->{
|
return;
|
||||||
field.RightButtonAction();
|
_warship.MoveTransport(Direction.Up);
|
||||||
repaint();
|
repaint();
|
||||||
});
|
});
|
||||||
|
ButtonLeft.addActionListener(e -> {
|
||||||
ButtonLeft.setPreferredSize(dimen);
|
if(_warship == null)
|
||||||
ButtonLeft.addActionListener(e->{
|
return;
|
||||||
field.LeftButtonAction();
|
_warship.MoveTransport(Direction.Left);
|
||||||
repaint();
|
repaint();
|
||||||
});
|
});
|
||||||
|
ButtonRight.addActionListener(e -> {
|
||||||
LRPanel.setLayout(new FlowLayout(FlowLayout.CENTER,50,0));
|
if(_warship == null)
|
||||||
LRPanel.setBackground(new Color(0,0,0,0));
|
return;
|
||||||
LRPanel.add(ButtonLeft);
|
_warship.MoveTransport(Direction.Right);
|
||||||
LRPanel.add(ButtonRight);
|
|
||||||
|
|
||||||
UPanel.setLayout(new FlowLayout());
|
|
||||||
UPanel.setBackground(new Color(0,0,0,0));
|
|
||||||
UPanel.add(ButtonUp);
|
|
||||||
|
|
||||||
DPanel.setLayout(new FlowLayout());
|
|
||||||
DPanel.setBackground(new Color(0,0,0,0));
|
|
||||||
DPanel.add(ButtonDown);
|
|
||||||
|
|
||||||
DimentionPanel.setLayout(new BoxLayout(DimentionPanel,BoxLayout.Y_AXIS));
|
|
||||||
DimentionPanel.setBackground(new Color(0,0,0,0));
|
|
||||||
DimentionPanel.add(UPanel);
|
|
||||||
DimentionPanel.add(LRPanel);
|
|
||||||
DimentionPanel.add(DPanel);
|
|
||||||
add(DimentionPanel);
|
|
||||||
|
|
||||||
CreatePanel.setLayout(new FlowLayout());
|
|
||||||
CreatePanel.setBackground(new Color(0,0,0,0));
|
|
||||||
CreatePanel.add(ButtonCreate);
|
|
||||||
ButtonCreate.addActionListener(e->{
|
|
||||||
field.CreateButtonAction();
|
|
||||||
repaint();
|
repaint();
|
||||||
});
|
});
|
||||||
|
ButtonDown.addActionListener(e -> {
|
||||||
BottomPanel.setLayout(new FlowLayout());
|
if(_warship == null)
|
||||||
BottomPanel.setBackground(new Color(0,0,0,0));
|
return;
|
||||||
BottomPanel.add(SpeedLabel);
|
_warship.MoveTransport(Direction.Down);
|
||||||
BottomPanel.add(WeightLabel);
|
repaint();
|
||||||
BottomPanel.add(BodyColorLabel);
|
});
|
||||||
|
ButtonSelect.addActionListener(e -> {
|
||||||
BottomAndCreatePanel.setLayout(new BoxLayout(BottomAndCreatePanel,BoxLayout.Y_AXIS));
|
SelectedWarship=GetDrawingWarship();
|
||||||
BottomAndCreatePanel.setBackground(new Color(0,0,0,0));
|
JOptionPane.showMessageDialog(PictureBox, "Корабль добавлен.");
|
||||||
BottomAndCreatePanel.add(CreatePanel);
|
});
|
||||||
BottomAndCreatePanel.add(BottomPanel);
|
|
||||||
|
|
||||||
add(BottomAndCreatePanel);
|
|
||||||
add(field);
|
|
||||||
|
|
||||||
addComponentListener(new ComponentAdapter() {
|
addComponentListener(new ComponentAdapter() {
|
||||||
@Override
|
@Override
|
||||||
public void componentResized(ComponentEvent e) {
|
public void componentResized(ComponentEvent e){
|
||||||
super.componentResized(e);
|
super.componentResized(e);
|
||||||
Width=getWidth();
|
Width=getWidth();
|
||||||
Height=getHeight();
|
Height=getHeight();
|
||||||
|
if (_warship!=null)
|
||||||
field.ResizeField();
|
_warship.ChangeBorders(getWidth(),getHeight());
|
||||||
|
else return;
|
||||||
repaint();
|
repaint();
|
||||||
RefreshWindow();
|
setBounds(0,0,Width,Height);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
public void RefreshWindow(){
|
public DrawingWarship GetDrawingWarship() {
|
||||||
field.setBounds(0,0,Width,Height);
|
return _warship;
|
||||||
BottomAndCreatePanel.setBounds(-220,Height-110,Width,80);
|
}
|
||||||
DimentionPanel.setBounds(Width-170,Height-170,190,140);
|
public void SetDrawingWarship(DrawingWarship warship) {
|
||||||
|
_warship=warship;
|
||||||
|
SetData();
|
||||||
|
repaint();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
328
src/FormWarshipConfig.form
Normal file
328
src/FormWarshipConfig.form
Normal file
@ -0,0 +1,328 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormWarshipConfig">
|
||||||
|
<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="709" height="400"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children>
|
||||||
|
<grid id="aa600" binding="GroupBoxConfig" layout-manager="GridLayoutManager" row-count="6" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||||
|
<margin top="0" left="0" bottom="0" right="0"/>
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="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="bevel-lowered" title="Параметры"/>
|
||||||
|
<children>
|
||||||
|
<component id="e68a" class="javax.swing.JLabel" binding="SpeedLabel">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Скорость: "/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="1a58c" class="javax.swing.JSpinner" binding="SpinnerSpeed">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
</component>
|
||||||
|
<component id="e34d" class="javax.swing.JLabel" binding="WeightLabel">
|
||||||
|
<constraints>
|
||||||
|
<grid row="1" 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="f70c0" class="javax.swing.JSpinner" binding="SpinnerWeight">
|
||||||
|
<constraints>
|
||||||
|
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
</component>
|
||||||
|
<component id="558f5" class="javax.swing.JCheckBox" binding="CheckBoxAntenna">
|
||||||
|
<constraints>
|
||||||
|
<grid row="2" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Наличие Антенны"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="86810" class="javax.swing.JCheckBox" binding="CheckBoxHelipad">
|
||||||
|
<constraints>
|
||||||
|
<grid row="3" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Наличие Вертолетной Площадки"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="45d13" class="javax.swing.JCheckBox" binding="CheckBoxMissile">
|
||||||
|
<constraints>
|
||||||
|
<grid row="4" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Наличие Боевых Ракет"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<grid id="5cb60" binding="ColorPanel" 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="0" column="2" row-span="5" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="bevel-lowered" title="Цвета"/>
|
||||||
|
<children>
|
||||||
|
<grid id="8627c" binding="RedPanel" 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="7" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||||
|
<preferred-size width="60" height="24"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<background color="-65536"/>
|
||||||
|
</properties>
|
||||||
|
<border type="none"/>
|
||||||
|
<children/>
|
||||||
|
</grid>
|
||||||
|
<grid id="a4fe8" binding="OrangePanel" 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="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||||
|
<preferred-size width="60" height="24"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<background color="-35072"/>
|
||||||
|
</properties>
|
||||||
|
<border type="none"/>
|
||||||
|
<children/>
|
||||||
|
</grid>
|
||||||
|
<grid id="cec8c" binding="YellowPanel" 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="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||||
|
<preferred-size width="60" height="24"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<background color="-1536"/>
|
||||||
|
</properties>
|
||||||
|
<border type="none"/>
|
||||||
|
<children/>
|
||||||
|
</grid>
|
||||||
|
<grid id="d0a7" binding="CianPanel" 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="1" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||||
|
<preferred-size width="60" height="24"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<background color="-16711687"/>
|
||||||
|
</properties>
|
||||||
|
<border type="none"/>
|
||||||
|
<children/>
|
||||||
|
</grid>
|
||||||
|
<grid id="ef34" binding="PinkPanel" 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="1" column="2" row-span="1" col-span="1" vsize-policy="3" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||||
|
<preferred-size width="60" height="24"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<background color="-65327"/>
|
||||||
|
</properties>
|
||||||
|
<border type="none"/>
|
||||||
|
<children/>
|
||||||
|
</grid>
|
||||||
|
<grid id="b9f70" binding="GreenPanel" 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="2" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||||
|
<preferred-size width="60" height="24"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<background color="-15859968"/>
|
||||||
|
</properties>
|
||||||
|
<border type="none"/>
|
||||||
|
<children/>
|
||||||
|
</grid>
|
||||||
|
<grid id="a648b" binding="BluePanel" 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="3" row-span="1" col-span="1" vsize-policy="3" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||||
|
<preferred-size width="60" height="24"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<background color="-16767489"/>
|
||||||
|
</properties>
|
||||||
|
<border type="none"/>
|
||||||
|
<children/>
|
||||||
|
</grid>
|
||||||
|
<grid id="9a3a" binding="GrayPanel" 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="1" column="3" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||||
|
<preferred-size width="60" height="24"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<background color="-8814719"/>
|
||||||
|
</properties>
|
||||||
|
<border type="none"/>
|
||||||
|
<children/>
|
||||||
|
</grid>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
<component id="b1cf4" class="javax.swing.JLabel" binding="BaseWarshipLabel">
|
||||||
|
<constraints>
|
||||||
|
<grid row="5" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<background color="-1247489"/>
|
||||||
|
<requestFocusEnabled value="false"/>
|
||||||
|
<text value="Обычный корабль"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="86067" class="javax.swing.JLabel" binding="AdvancedWarshipLabel">
|
||||||
|
<constraints>
|
||||||
|
<grid row="5" 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>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
<grid id="f4894" layout-manager="GridLayoutManager" row-count="1" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||||
|
<margin top="0" left="0" bottom="0" right="0"/>
|
||||||
|
<constraints>
|
||||||
|
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="bevel-lowered" title="Ящики"/>
|
||||||
|
<children>
|
||||||
|
<component id="4f296" class="javax.swing.JLabel" binding="CountBlockLabel">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Количество ящиков"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="c34e2" class="javax.swing.JSpinner" binding="SpinnerBlock">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<requestFocusEnabled value="true"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<grid id="d475" binding="TypeBlock" layout-manager="GridLayoutManager" row-count="1" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||||
|
<margin top="0" left="0" bottom="0" right="0"/>
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="2" 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="bevel-lowered" title="Форма ящиков"/>
|
||||||
|
<children>
|
||||||
|
<component id="43b49" class="javax.swing.JLabel" binding="RoundBlockLabel">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false">
|
||||||
|
<preferred-size width="68" height="16"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Круглые"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="c2216" class="javax.swing.JLabel" binding="TriangleBlockLabel">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Треугольные"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="405bd" class="javax.swing.JLabel" binding="SquareBlockLabel">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Квадратные"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
<grid id="10355" binding="PreviewPanel" layout-manager="GridLayoutManager" row-count="3" 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>
|
||||||
|
<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/>
|
||||||
|
<border type="bevel-lowered" title="Предварительный просмотр"/>
|
||||||
|
<children>
|
||||||
|
<component id="5be86" class="javax.swing.JLabel" binding="BodyColorLabel">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false">
|
||||||
|
<preferred-size width="74" height="49"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Цвет корпуса"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="b5fda" class="javax.swing.JLabel" binding="DopColorLabel">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false">
|
||||||
|
<preferred-size width="107" height="49"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Цвет модификаций"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<grid id="e8c69" binding="PictureBox" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||||
|
<margin top="0" left="0" bottom="0" right="0"/>
|
||||||
|
<constraints>
|
||||||
|
<grid row="1" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||||
|
<minimum-size width="200" height="200"/>
|
||||||
|
<preferred-size width="200" height="251"/>
|
||||||
|
<maximum-size width="200" height="200"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="bevel-lowered" title="Корабль"/>
|
||||||
|
<children/>
|
||||||
|
</grid>
|
||||||
|
<component id="687fc" class="javax.swing.JButton" binding="ButtonAdd">
|
||||||
|
<constraints>
|
||||||
|
<grid row="2" 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="47914" class="javax.swing.JButton" binding="ButtonCancel">
|
||||||
|
<constraints>
|
||||||
|
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Отмена"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
</form>
|
151
src/FormWarshipConfig.java
Normal file
151
src/FormWarshipConfig.java
Normal file
@ -0,0 +1,151 @@
|
|||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.FocusEvent;
|
||||||
|
import java.awt.event.MouseAdapter;
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
|
import java.awt.event.WindowEvent;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
public class FormWarshipConfig extends JFrame {
|
||||||
|
private final Action<DrawingWarship> event = new Action<>();
|
||||||
|
private DrawingWarship warship;
|
||||||
|
BlockCount block;
|
||||||
|
private IDrawingObjectBlock _block=null;
|
||||||
|
private JPanel MainPanel;
|
||||||
|
private JPanel GroupBoxConfig;
|
||||||
|
private JSpinner SpinnerSpeed;
|
||||||
|
private JSpinner SpinnerWeight;
|
||||||
|
private JCheckBox CheckBoxAntenna;
|
||||||
|
private JCheckBox CheckBoxHelipad;
|
||||||
|
private JCheckBox CheckBoxMissile;
|
||||||
|
private JLabel SpeedLabel;
|
||||||
|
private JLabel WeightLabel;
|
||||||
|
private JPanel ColorPanel;
|
||||||
|
private JPanel RedPanel;
|
||||||
|
private JPanel OrangePanel;
|
||||||
|
private JPanel GreenPanel;
|
||||||
|
private JPanel BluePanel;
|
||||||
|
private JPanel YellowPanel;
|
||||||
|
private JPanel CianPanel;
|
||||||
|
private JPanel PinkPanel;
|
||||||
|
private JPanel GrayPanel;
|
||||||
|
private JLabel CountBlockLabel;
|
||||||
|
private JSpinner SpinnerBlock;
|
||||||
|
private JPanel TypeBlock;
|
||||||
|
private JLabel SquareBlockLabel;
|
||||||
|
private JLabel TriangleBlockLabel;
|
||||||
|
private JLabel RoundBlockLabel;
|
||||||
|
private JPanel PreviewPanel;
|
||||||
|
private JLabel BodyColorLabel;
|
||||||
|
private JLabel DopColorLabel;
|
||||||
|
private JLabel BaseWarshipLabel;
|
||||||
|
private JLabel AdvancedWarshipLabel;
|
||||||
|
private JButton ButtonAdd;
|
||||||
|
private JButton ButtonCancel;
|
||||||
|
private JPanel PictureBox;
|
||||||
|
|
||||||
|
public FormWarshipConfig(){
|
||||||
|
this.setTitle("Создание объекта");
|
||||||
|
this.setSize(900,500);
|
||||||
|
this.setContentPane(MainPanel);
|
||||||
|
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
|
||||||
|
|
||||||
|
SquareBlockLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
|
||||||
|
TriangleBlockLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
|
||||||
|
RoundBlockLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
|
||||||
|
BodyColorLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
|
||||||
|
DopColorLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
|
||||||
|
BaseWarshipLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
|
||||||
|
AdvancedWarshipLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
|
||||||
|
|
||||||
|
SpinnerBlock.setModel(new SpinnerNumberModel(2, 2, 6, 2));
|
||||||
|
SpinnerSpeed.setModel(new SpinnerNumberModel(100, 100, 1000, 10));
|
||||||
|
SpinnerWeight.setModel(new SpinnerNumberModel(10000, 10000, 20000, 100));
|
||||||
|
|
||||||
|
var dragAdapter = new MouseAdapter() {
|
||||||
|
@Override
|
||||||
|
public void mousePressed(MouseEvent e) {
|
||||||
|
super.mouseReleased(e);
|
||||||
|
setCursor(new Cursor(Cursor.HAND_CURSOR));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseReleased(MouseEvent e) {
|
||||||
|
super.mouseReleased(e);
|
||||||
|
dispatchDrop((JComponent) e.getSource());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
RedPanel.addMouseListener(dragAdapter);
|
||||||
|
GreenPanel.addMouseListener(dragAdapter);
|
||||||
|
BluePanel.addMouseListener(dragAdapter);
|
||||||
|
YellowPanel.addMouseListener(dragAdapter);
|
||||||
|
OrangePanel.addMouseListener(dragAdapter);
|
||||||
|
GrayPanel.addMouseListener(dragAdapter);
|
||||||
|
CianPanel.addMouseListener(dragAdapter);
|
||||||
|
PinkPanel.addMouseListener(dragAdapter);
|
||||||
|
|
||||||
|
BaseWarshipLabel.addMouseListener(dragAdapter);
|
||||||
|
AdvancedWarshipLabel.addMouseListener(dragAdapter);
|
||||||
|
SquareBlockLabel.addMouseListener(dragAdapter);
|
||||||
|
TriangleBlockLabel.addMouseListener(dragAdapter);
|
||||||
|
RoundBlockLabel.addMouseListener(dragAdapter);
|
||||||
|
|
||||||
|
ButtonAdd.addActionListener(e -> {
|
||||||
|
event.Invoke(warship);
|
||||||
|
dispose();
|
||||||
|
});
|
||||||
|
ButtonCancel.addActionListener(e -> dispose());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addListener(Consumer<DrawingWarship> listener) {
|
||||||
|
event.addListener(listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void dispatchDrop(JComponent droppedComponent) {
|
||||||
|
setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
|
||||||
|
if (droppedComponent == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (droppedComponent instanceof JPanel panel) {
|
||||||
|
if (BodyColorLabel.getMousePosition() != null) {
|
||||||
|
warship.SetBodyColor(panel.getBackground());
|
||||||
|
}
|
||||||
|
if (DopColorLabel.getMousePosition() != null && warship instanceof DrawingAdvancedWarship advanced) {
|
||||||
|
advanced.SetDopColor(panel.getBackground());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (droppedComponent instanceof JLabel label && PictureBox.getMousePosition() != null) {
|
||||||
|
int speed = (Integer) SpinnerSpeed.getValue();
|
||||||
|
int weight = (Integer) SpinnerWeight.getValue();
|
||||||
|
int countBlock = (Integer) SpinnerBlock.getValue();
|
||||||
|
boolean antenna = CheckBoxAntenna.isSelected();
|
||||||
|
boolean helipad = CheckBoxHelipad.isSelected();
|
||||||
|
boolean missile = CheckBoxMissile.isSelected();
|
||||||
|
|
||||||
|
if (label == BaseWarshipLabel) {
|
||||||
|
warship = new DrawingWarship(speed, weight, countBlock,Color.WHITE);
|
||||||
|
} else if (label == AdvancedWarshipLabel) {
|
||||||
|
warship = new DrawingAdvancedWarship(speed, weight,countBlock, Color.WHITE, Color.WHITE, helipad, antenna,missile);
|
||||||
|
} else if (warship != null && label == SquareBlockLabel) {
|
||||||
|
warship.SetBlocks(new DrawingBlock(countBlock));
|
||||||
|
} else if (warship != null && label == TriangleBlockLabel) {
|
||||||
|
warship.SetBlocks(new DrawingTriangleBlocks(countBlock));
|
||||||
|
} else if (warship != null && label == RoundBlockLabel) {
|
||||||
|
warship.SetBlocks(new DrawingRoundBlocks(countBlock));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void paint(Graphics g) {
|
||||||
|
super.paint(g);
|
||||||
|
if (warship != null) {
|
||||||
|
g = PictureBox.getGraphics();
|
||||||
|
warship.SetPosition(10, 10, PictureBox.getWidth(), PictureBox.getHeight());
|
||||||
|
warship.DrawTransport((Graphics2D) g);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
10
src/IDrawingObject.java
Normal file
10
src/IDrawingObject.java
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public interface IDrawingObject {
|
||||||
|
public float Step=0;
|
||||||
|
void SetObject(int x, int y, int width, int height);
|
||||||
|
void MoveObject(Direction direction);
|
||||||
|
void DrawingObject(Graphics g);
|
||||||
|
float[] GetCurrentPosition();
|
||||||
|
String GetInfo();
|
||||||
|
}
|
8
src/IDrawingObjectBlock.java
Normal file
8
src/IDrawingObjectBlock.java
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public interface IDrawingObjectBlock {
|
||||||
|
void SetBlockCount(int count);
|
||||||
|
void DrawBlock(Graphics2D g, int _startPosX, int _startPosY);
|
||||||
|
|
||||||
|
String GetCount();
|
||||||
|
}
|
@ -1,6 +1,5 @@
|
|||||||
public class Main {
|
public class Main {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
new FormWarship();
|
new FormMapWithSetWarships();
|
||||||
}
|
}
|
||||||
}
|
}
|
157
src/MapWithSetWarshipsGeneric.java
Normal file
157
src/MapWithSetWarshipsGeneric.java
Normal file
@ -0,0 +1,157 @@
|
|||||||
|
import java.awt.*;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
|
||||||
|
public class MapWithSetWarshipsGeneric<T extends IDrawingObject,U extends AbstractMap> {
|
||||||
|
private final int _pictureWidth;
|
||||||
|
private final int _pictureHeight;
|
||||||
|
private final int _placeSizeWidth = 120;
|
||||||
|
private final int _placeSizeHeight = 50;
|
||||||
|
public final SetWarshipsGeneric<T> _setWarship;
|
||||||
|
private final LinkedList<T> DeletedWarships;
|
||||||
|
private final U _map;
|
||||||
|
|
||||||
|
public MapWithSetWarshipsGeneric(int picWidth,int picHeight, U map)
|
||||||
|
{
|
||||||
|
int width = picWidth / _placeSizeWidth;
|
||||||
|
int height = picHeight/_placeSizeHeight;
|
||||||
|
_setWarship = new SetWarshipsGeneric<T>(width * height);
|
||||||
|
_pictureWidth = picWidth;
|
||||||
|
_pictureHeight = picHeight;
|
||||||
|
_map = map;
|
||||||
|
DeletedWarships=new LinkedList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public U GetMap(){
|
||||||
|
return _map;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int plus(T warship)
|
||||||
|
{
|
||||||
|
return _setWarship.Insert(warship);
|
||||||
|
}
|
||||||
|
|
||||||
|
public T minus(int position)
|
||||||
|
{
|
||||||
|
T warship=_setWarship.Remove(position);
|
||||||
|
DeletedWarships.push(warship);
|
||||||
|
return warship;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Image ShowSet()
|
||||||
|
{
|
||||||
|
BufferedImage bmp = new BufferedImage(_pictureWidth, _pictureWidth,BufferedImage.TYPE_INT_ARGB);
|
||||||
|
Graphics gr = bmp.getGraphics();
|
||||||
|
DrawBackground(gr);
|
||||||
|
DrawWarship(gr);
|
||||||
|
return bmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Image ShowOnMap()
|
||||||
|
{
|
||||||
|
Shaking();
|
||||||
|
for (IDrawingObject warship : _setWarship)
|
||||||
|
{
|
||||||
|
return _map.CreateMap(_pictureWidth, _pictureHeight, warship);
|
||||||
|
}
|
||||||
|
return new BufferedImage(_pictureWidth, _pictureHeight,1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Image MoveObject(Direction direction)
|
||||||
|
{
|
||||||
|
if (_map != null)
|
||||||
|
{
|
||||||
|
return _map.MoveObject(direction);
|
||||||
|
}
|
||||||
|
return new BufferedImage(_pictureWidth, _pictureHeight,1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Shaking()
|
||||||
|
{
|
||||||
|
int j = _setWarship.Count() - 1;
|
||||||
|
for (int i = 0; i < _setWarship.Count(); i++)
|
||||||
|
{
|
||||||
|
if (_setWarship.Get(i) == null)
|
||||||
|
{
|
||||||
|
for (; j > i; j--)
|
||||||
|
{
|
||||||
|
T warship = _setWarship.Get(j);
|
||||||
|
if (warship != null)
|
||||||
|
{
|
||||||
|
_setWarship.Insert(warship, i);
|
||||||
|
_setWarship.Remove(j);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (j <= i)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DrawBackground(Graphics gr)
|
||||||
|
{
|
||||||
|
Graphics2D g=(Graphics2D)gr;
|
||||||
|
|
||||||
|
Color brush=Color.BLACK;
|
||||||
|
Stroke penWide = new BasicStroke(5);
|
||||||
|
Stroke penThin = new BasicStroke(1);
|
||||||
|
|
||||||
|
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
|
||||||
|
{
|
||||||
|
g.setColor(brush);
|
||||||
|
g.setStroke(penWide);
|
||||||
|
g.drawLine(i * _placeSizeWidth + 20, j * _placeSizeHeight+2, i * _placeSizeWidth + (int)(_placeSizeWidth*0.8), j * _placeSizeHeight+2);
|
||||||
|
g.drawLine(i * _placeSizeWidth + 20, j * _placeSizeHeight + _placeSizeHeight/2+2, i * _placeSizeWidth + (int)(_placeSizeWidth * 0.8), j * _placeSizeHeight + _placeSizeHeight/2+2);
|
||||||
|
g.drawLine(i * _placeSizeWidth + (int)(_placeSizeWidth * 0.8), j * _placeSizeHeight + 2, i * _placeSizeWidth + _placeSizeWidth, j * _placeSizeHeight + _placeSizeHeight/2);
|
||||||
|
g.drawLine(i * _placeSizeWidth + _placeSizeWidth, j * _placeSizeHeight + _placeSizeHeight / 2, i * _placeSizeWidth+ (int)(_placeSizeWidth * 0.8), j * _placeSizeHeight + _placeSizeHeight);
|
||||||
|
g.setStroke(penThin);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DrawWarship(Graphics gr)
|
||||||
|
{
|
||||||
|
int i=0;
|
||||||
|
int width = _pictureWidth / _placeSizeWidth;
|
||||||
|
int height = _pictureHeight / _placeSizeHeight;
|
||||||
|
|
||||||
|
for (IDrawingObject warship : _setWarship)
|
||||||
|
{
|
||||||
|
if (warship==null)
|
||||||
|
return;
|
||||||
|
_setWarship.Get(i).SetObject(i % width * _placeSizeWidth, (height - 1 - i / width) * _placeSizeHeight, _pictureWidth, _pictureHeight);
|
||||||
|
_setWarship.Get(i).DrawingObject(gr);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public T GetWarshipInList(int i){
|
||||||
|
return _setWarship.Get(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
public T GetWarshipInDeleted() {
|
||||||
|
if(DeletedWarships.isEmpty())
|
||||||
|
return null;
|
||||||
|
return DeletedWarships.pop();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String GetData(char separatorType,char separatorData){
|
||||||
|
String data=""+_map.getClass().getSimpleName()+separatorType;
|
||||||
|
for (var warship : _setWarship){
|
||||||
|
data+=warship.GetInfo()+separatorData;
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public void LoadData(String[] records){
|
||||||
|
for (int i=records.length-1;i>=0;i--){
|
||||||
|
_setWarship.Insert((T) DrawingObjectWarship.Create(records[i]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
162
src/MapsCollection.java
Normal file
162
src/MapsCollection.java
Normal file
@ -0,0 +1,162 @@
|
|||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
public class MapsCollection {
|
||||||
|
|
||||||
|
private final HashMap<String,MapWithSetWarshipsGeneric<DrawingObjectWarship,AbstractMap>> _mapStorages;
|
||||||
|
private final int _pictureWidth;
|
||||||
|
private final int _pictureHeight;
|
||||||
|
private final char separatorDict='|';
|
||||||
|
private final char separatorData=';';
|
||||||
|
|
||||||
|
public MapsCollection(int pictureWidth,int pictureHeight){
|
||||||
|
_mapStorages=new HashMap<>();
|
||||||
|
_pictureWidth=pictureWidth;
|
||||||
|
_pictureHeight=pictureHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<String> Keys(){
|
||||||
|
return new ArrayList<>(_mapStorages.keySet());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddMap(String name, AbstractMap map){
|
||||||
|
if (_mapStorages.containsKey(name)){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
_mapStorages.put(name,new MapWithSetWarshipsGeneric<>(_pictureWidth,_pictureHeight,map));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DelMap(String name){
|
||||||
|
_mapStorages.remove(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MapWithSetWarshipsGeneric<DrawingObjectWarship,AbstractMap> get(String name){
|
||||||
|
if (_mapStorages.containsKey(name)){
|
||||||
|
return _mapStorages.get(name);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DrawingObjectWarship get(String name,int i) {
|
||||||
|
if (_mapStorages.containsKey(name))
|
||||||
|
{
|
||||||
|
return _mapStorages.get(name).GetWarshipInList(i);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||||
|
public boolean SaveData(String filename) throws IOException {
|
||||||
|
|
||||||
|
File file = new File(filename);
|
||||||
|
|
||||||
|
if (file.exists())
|
||||||
|
file.delete();
|
||||||
|
|
||||||
|
file.createNewFile();
|
||||||
|
|
||||||
|
try (PrintWriter writer = new PrintWriter(file)) {
|
||||||
|
writer.println("MapsCollection");
|
||||||
|
|
||||||
|
for (var storage : _mapStorages.entrySet()) {
|
||||||
|
writer.println(String.format("%s%c%s", storage.getKey(), separatorDict, storage.getValue().GetData(separatorDict, separatorData)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean LoadData(String filename) throws IOException {
|
||||||
|
|
||||||
|
File file = new File(filename);
|
||||||
|
|
||||||
|
if (!file.exists())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
|
||||||
|
String currentLine = reader.readLine();
|
||||||
|
|
||||||
|
if (currentLine == null || !currentLine.contains("MapsCollection"))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
_mapStorages.clear();
|
||||||
|
|
||||||
|
while ((currentLine = reader.readLine()) != null) {
|
||||||
|
var elements = currentLine.split(String.format("\\%c", separatorDict));
|
||||||
|
AbstractMap map = switch (elements[1]) {
|
||||||
|
case "SimpleMap" -> new SimpleMap();
|
||||||
|
case "SecondMap" -> new SecondMap();
|
||||||
|
default -> null;
|
||||||
|
};
|
||||||
|
_mapStorages.put(elements[0], new MapWithSetWarshipsGeneric<>(_pictureWidth, _pictureHeight, map));
|
||||||
|
_mapStorages.get(elements[0]).LoadData(elements[2].split(separatorData + "\n?"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||||
|
public boolean SaveMap(String mapName, String filename) throws IOException {
|
||||||
|
File file = new File(filename);
|
||||||
|
|
||||||
|
if (file.exists())
|
||||||
|
file.delete();
|
||||||
|
|
||||||
|
file.createNewFile();
|
||||||
|
|
||||||
|
MapWithSetWarshipsGeneric<DrawingObjectWarship, AbstractMap> map = _mapStorages.getOrDefault(mapName, null);
|
||||||
|
|
||||||
|
if (map == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
try (PrintWriter writer = new PrintWriter(file)) {
|
||||||
|
writer.println("Map");
|
||||||
|
writer.println(mapName);
|
||||||
|
writer.println(map.GetMap().getClass().getSimpleName());
|
||||||
|
for (var warship : map._setWarship.GetWarship()) {
|
||||||
|
writer.println(warship.GetInfo());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean LoadMap(String filename) throws IOException {
|
||||||
|
File file = new File(filename);
|
||||||
|
|
||||||
|
if (!file.exists())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
|
||||||
|
String currentLine = reader.readLine();
|
||||||
|
|
||||||
|
if (currentLine == null || !currentLine.contains("Map"))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
String mapName = reader.readLine();
|
||||||
|
|
||||||
|
MapWithSetWarshipsGeneric<DrawingObjectWarship, AbstractMap> map;
|
||||||
|
if (_mapStorages.containsKey(mapName)) {
|
||||||
|
map = _mapStorages.get(mapName);
|
||||||
|
if (!map.GetMap().getClass().getSimpleName().equals(reader.readLine())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
map._setWarship.Clear();
|
||||||
|
} else {
|
||||||
|
map = switch (reader.readLine()) {
|
||||||
|
case "SimpleMap" -> new MapWithSetWarshipsGeneric<>(_pictureWidth, _pictureHeight, new SimpleMap());
|
||||||
|
case "SecondMap" -> new MapWithSetWarshipsGeneric<>(_pictureWidth, _pictureHeight, new SecondMap());
|
||||||
|
default -> null;
|
||||||
|
};
|
||||||
|
_mapStorages.put(mapName, map);
|
||||||
|
}
|
||||||
|
while ((currentLine = reader.readLine()) != null) {
|
||||||
|
map._setWarship.Insert((DrawingObjectWarship) DrawingObjectWarship.Create(currentLine));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
37
src/SecondMap.java
Normal file
37
src/SecondMap.java
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class SecondMap extends AbstractMap{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void GenerateMap() {
|
||||||
|
_map = new int[60][60];
|
||||||
|
_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[i].length; ++j) {
|
||||||
|
_map[i][j] = _freeWaterArea;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (counter < 20) {
|
||||||
|
int x = _random.nextInt(59);
|
||||||
|
int y = _random.nextInt(59);
|
||||||
|
if (_map[x][y] == _freeWaterArea) {
|
||||||
|
_map[x][y] = _land;
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void DrawWaterPart(Graphics gr, int i, int j) {
|
||||||
|
gr.setColor(new Color(0xFFFFFF));
|
||||||
|
gr.fillRect((int) (i * _size_x), (int) (j * _size_y), (int) (i * (_size_x + 1)), (int) (j * (_size_y + 1)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void DrawLandPart(Graphics gr, int i, int j) {
|
||||||
|
gr.setColor(new Color(0x050303));
|
||||||
|
gr.fillRect((int) (i * _size_x), (int) (j * _size_y), (int) (i * (_size_x + 1)), (int) (j * (_size_y + 1)));
|
||||||
|
}
|
||||||
|
}
|
72
src/SetWarshipsGeneric.java
Normal file
72
src/SetWarshipsGeneric.java
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public class SetWarshipsGeneric<T extends Object> implements Iterable<T>{
|
||||||
|
private final ArrayList<T> _places;
|
||||||
|
|
||||||
|
public int Count() {
|
||||||
|
return _places.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
private final int _maxCount;
|
||||||
|
|
||||||
|
public void Clear(){
|
||||||
|
_places.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public SetWarshipsGeneric(int count)
|
||||||
|
{
|
||||||
|
_maxCount=count;
|
||||||
|
_places = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Insert(T warship)
|
||||||
|
{
|
||||||
|
if (_places.size()+1>=_maxCount)
|
||||||
|
return -1;
|
||||||
|
_places.add(0,warship);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Insert(T warship, int position)
|
||||||
|
{
|
||||||
|
if (position>=_maxCount||position<0)
|
||||||
|
return -1;
|
||||||
|
if (_places.size()+1>=_maxCount)
|
||||||
|
return -1;
|
||||||
|
_places.add(position,warship);
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
|
||||||
|
public T Remove(int position)
|
||||||
|
{
|
||||||
|
if (position>=_maxCount||position<0)
|
||||||
|
return null;
|
||||||
|
T deleted=_places.get(position);
|
||||||
|
_places.remove(position);
|
||||||
|
return deleted;
|
||||||
|
}
|
||||||
|
|
||||||
|
public T Get(int position)
|
||||||
|
{
|
||||||
|
if (position>=_maxCount||position<0)
|
||||||
|
return null;
|
||||||
|
return _places.get(position);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Set(int position,T warship){
|
||||||
|
if (position >= _maxCount||position<0)
|
||||||
|
return;
|
||||||
|
Insert(warship,position);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterator<T> iterator(){
|
||||||
|
return _places.iterator();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Iterable<T> GetWarship(){
|
||||||
|
return ()-> _places.stream().filter(Objects::nonNull).iterator();
|
||||||
|
}
|
||||||
|
}
|
36
src/SimpleMap.java
Normal file
36
src/SimpleMap.java
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class SimpleMap extends AbstractMap {
|
||||||
|
@Override
|
||||||
|
protected void DrawWaterPart(Graphics gr, int i, int j) {
|
||||||
|
gr.setColor(new Color(0x5285B6));
|
||||||
|
gr.fillRect((int) (i * _size_x), (int) (j * _size_y), (int) (i * (_size_x + 1)), (int) (j * (_size_y + 1)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void DrawLandPart(Graphics gr, int i, int j) {
|
||||||
|
gr.setColor(new Color(0x422A1D));
|
||||||
|
gr.fillRect((int) (i * _size_x), (int) (j * _size_y), (int) (i * (_size_x + 1)), (int) (j * (_size_y + 1)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@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[i].length; ++j) {
|
||||||
|
_map[i][j] = _freeWaterArea;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (counter < 50) {
|
||||||
|
int x = _random.nextInt(99);
|
||||||
|
int y = _random.nextInt(99);
|
||||||
|
if (_map[x][y] == _freeWaterArea) {
|
||||||
|
_map[x][y] = _land;
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user