Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
2a5a1d392c |
1
.idea/WarshipHard.iml
generated
1
.idea/WarshipHard.iml
generated
@ -3,7 +3,6 @@
|
|||||||
<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" />
|
||||||
|
@ -1,148 +0,0 @@
|
|||||||
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);
|
|
||||||
}
|
|
@ -1,9 +0,0 @@
|
|||||||
public enum BlockForm {
|
|
||||||
Rect(0),
|
|
||||||
Round(1),
|
|
||||||
Triangle(2);
|
|
||||||
public final int Value;
|
|
||||||
BlockForm(int i) {
|
|
||||||
Value=i;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,39 +0,0 @@
|
|||||||
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,7 +2,6 @@ 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){}
|
||||||
}
|
}
|
||||||
|
@ -1,80 +0,0 @@
|
|||||||
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, 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 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,14 +1,9 @@
|
|||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
|
||||||
public class DrawingBlock implements IDrawingObjectBlock{
|
public class DrawingBlock {
|
||||||
|
|
||||||
private BlockCount _block=null;
|
private BlockCount _block;
|
||||||
|
|
||||||
public DrawingBlock(BlockCount block) {
|
|
||||||
_block=block;
|
|
||||||
}
|
|
||||||
|
|
||||||
@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){
|
||||||
@ -16,7 +11,7 @@ public class DrawingBlock implements IDrawingObjectBlock{
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@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);
|
||||||
|
@ -2,15 +2,12 @@ import javax.swing.*;
|
|||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
public class DrawingField extends JPanel{
|
public class DrawingField extends JPanel {
|
||||||
private final FormWarship Field;
|
private final FormWarship Field;
|
||||||
private DrawingWarship _warship=null;
|
DrawingWarship _warship;
|
||||||
|
|
||||||
public DrawingWarship SelectedWarship;
|
|
||||||
public DrawingField(FormWarship field) {
|
public DrawingField(FormWarship field) {
|
||||||
Field = field;
|
this.Field = field;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void paintComponent(Graphics g) {
|
protected void paintComponent(Graphics g) {
|
||||||
super.paintComponent(g);
|
super.paintComponent(g);
|
||||||
@ -19,42 +16,42 @@ public class DrawingField extends JPanel{
|
|||||||
_warship.DrawTransport(g2);
|
_warship.DrawTransport(g2);
|
||||||
else return;
|
else return;
|
||||||
}
|
}
|
||||||
public void DirectionButtonAction(Direction side){
|
public void UpButtonAction(){
|
||||||
if(_warship == null)
|
if (_warship!=null)
|
||||||
|
_warship.MoveTransport(Direction.Up);
|
||||||
|
else
|
||||||
return;
|
return;
|
||||||
_warship.MoveTransport(side);
|
|
||||||
}
|
}
|
||||||
private void SetData() {
|
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();
|
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());
|
_warship.SetPosition(rand.nextInt(100)+10,rand.nextInt(100)+10,getWidth(),getHeight());
|
||||||
Field.SpeedLabel.setText("Скорость: "+_warship.GetWarship().GetSpeed());
|
Field.SpeedLabel.setText("Скорость: "+_warship.GetWarship().GetSpeed());
|
||||||
Field.WeightLabel.setText("Вес: "+_warship.GetWarship().GetWeight());
|
Field.WeightLabel.setText("Вес: "+_warship.GetWarship().GetWeight());
|
||||||
Field.BodyColorLabel.setText("Цвет: "+Integer.toHexString(_warship.GetWarship().GetBodyColor().getRGB()).substring(2));
|
Field.BodyColorLabel.setText("Цвет: "+Integer.toHexString(_warship.GetWarship().GetBodyColor().getRGB()).substring(2));
|
||||||
}
|
}
|
||||||
public void CreateButtonAction(){
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
public void CreateModifButtonAction(){
|
|
||||||
Random rand=new Random();
|
|
||||||
_warship = new DrawingAdvancedWarship(rand.nextInt(50) + 10, rand.nextInt(3000) + 20000, new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256)),
|
|
||||||
new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256)), rand.nextBoolean(), rand.nextBoolean(), rand.nextBoolean(),rand.nextInt(3));
|
|
||||||
SetData();
|
|
||||||
}
|
|
||||||
public void ResizeField(){
|
public void ResizeField(){
|
||||||
if (_warship!=null)
|
if (_warship!=null)
|
||||||
_warship.ChangeBorders(getWidth(),getHeight());
|
_warship.ChangeBorders(getWidth(),getHeight());
|
||||||
else return;
|
else return;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Draw(Graphics2D graphics) {
|
|
||||||
if (_warship!=null)
|
|
||||||
_warship.DrawTransport(graphics);
|
|
||||||
else return;
|
|
||||||
}
|
|
||||||
public DrawingWarship GetDrawingWarship() {
|
|
||||||
return _warship;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,39 +0,0 @@
|
|||||||
import java.awt.*;
|
|
||||||
|
|
||||||
public class DrawingObjectWarship implements IDrawingObject {
|
|
||||||
|
|
||||||
private DrawingWarship _warship=null;
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,51 +0,0 @@
|
|||||||
import java.awt.*;
|
|
||||||
|
|
||||||
public class DrawingRoundBlocks implements IDrawingObjectBlock{
|
|
||||||
private BlockCount _block;
|
|
||||||
|
|
||||||
public DrawingRoundBlocks(BlockCount block){
|
|
||||||
_block=block;
|
|
||||||
}
|
|
||||||
@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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,58 +0,0 @@
|
|||||||
import java.awt.*;
|
|
||||||
|
|
||||||
public class DrawingTriangleBlocks implements IDrawingObjectBlock{
|
|
||||||
private BlockCount _block;
|
|
||||||
|
|
||||||
public DrawingTriangleBlocks(BlockCount block){
|
|
||||||
_block=block;
|
|
||||||
}
|
|
||||||
@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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,64 +1,25 @@
|
|||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
|
||||||
public class DrawingWarship {
|
public class DrawingWarship {
|
||||||
protected EntityWarship Warship;
|
private EntityWarship Warship;
|
||||||
public EntityWarship GetWarship(){
|
public EntityWarship GetWarship(){
|
||||||
return Warship;
|
return Warship;
|
||||||
}
|
}
|
||||||
protected IDrawingObjectBlock Blocks;
|
public DrawingBlock Blocks;
|
||||||
private BlockCount _block;
|
private int _startPosX;
|
||||||
protected int _startPosX;
|
private int _startPosY;
|
||||||
protected int _startPosY;
|
|
||||||
private Integer _pictureWidth = null;
|
private Integer _pictureWidth = null;
|
||||||
private Integer _pictureHeight = null;
|
private Integer _pictureHeight = null;
|
||||||
private int _warshipWidth = 120;
|
private final int _warshipWidth = 120;
|
||||||
private int _warshipHeight = 40;
|
private final int _warshipHeight = 40;
|
||||||
|
|
||||||
public DrawingWarship(int speed, float weight, Color bodyColor, int blockForm)
|
public void Init(int speed, float weight, Color bodyColor)
|
||||||
{
|
{
|
||||||
Warship = new EntityWarship(speed, weight, bodyColor);
|
Warship = new EntityWarship();
|
||||||
Blocks= GetFormOfBlock(blockForm);
|
Warship.Init(speed, weight, bodyColor);
|
||||||
|
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(EntityWarship warship,IDrawingObjectBlock block){
|
|
||||||
Warship = warship;
|
|
||||||
Blocks = block;
|
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
@ -164,12 +125,4 @@ 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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,32 +0,0 @@
|
|||||||
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 EntityWarship(int speed, float weight, Color bodyColor)
|
public void Init(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;
|
||||||
|
@ -1,258 +0,0 @@
|
|||||||
<?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>
|
|
@ -1,132 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,146 +0,0 @@
|
|||||||
<?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="470"/>
|
|
||||||
</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="11" 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>
|
|
||||||
<component id="cd72b" class="javax.swing.JComboBox" binding="СomboBoxSelectorMap">
|
|
||||||
<constraints>
|
|
||||||
<grid row="0" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<model>
|
|
||||||
<item value="Первая карта"/>
|
|
||||||
<item value="Вторая карта"/>
|
|
||||||
</model>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
<vspacer id="b5fa4">
|
|
||||||
<constraints>
|
|
||||||
<grid row="8" 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="6" 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="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="11722" class="javax.swing.JButton" binding="ButtonDown">
|
|
||||||
<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="arrowDown.jpg"/>
|
|
||||||
<selectedIcon value="arrowDown.jpg"/>
|
|
||||||
<text value=""/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
<component id="a2c02" class="javax.swing.JButton" binding="ButtonUp">
|
|
||||||
<constraints>
|
|
||||||
<grid row="9" 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="10" 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="10" 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="5" 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>
|
|
||||||
</children>
|
|
||||||
</grid>
|
|
||||||
</children>
|
|
||||||
</grid>
|
|
||||||
</form>
|
|
@ -1,165 +0,0 @@
|
|||||||
import javax.swing.*;
|
|
||||||
import java.awt.*;
|
|
||||||
import java.awt.image.BufferedImage;
|
|
||||||
|
|
||||||
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 MapWithSetWarshipsGeneric<DrawingObjectWarship,AbstractMap> _mapWarshipsCollectionGeneric;
|
|
||||||
private Image bufferedImage;
|
|
||||||
|
|
||||||
public FormMapWithSetWarships(){
|
|
||||||
setTitle("Военный корабль");
|
|
||||||
setContentPane(MainPanel);
|
|
||||||
setResizable(false);
|
|
||||||
setSize(1000,685);
|
|
||||||
ShowWindow();
|
|
||||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
||||||
setVisible(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@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 ShowWindow(){
|
|
||||||
|
|
||||||
ButtonShowOnMap.addActionListener(e -> {
|
|
||||||
if (_mapWarshipsCollectionGeneric == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
bufferedImage = _mapWarshipsCollectionGeneric.ShowOnMap();
|
|
||||||
repaint();
|
|
||||||
});
|
|
||||||
|
|
||||||
ButtonShowStorage.addActionListener(e -> {
|
|
||||||
if (_mapWarshipsCollectionGeneric == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
bufferedImage = _mapWarshipsCollectionGeneric.ShowSet();
|
|
||||||
repaint();
|
|
||||||
});
|
|
||||||
|
|
||||||
ButtonAddWarship.addActionListener(e -> {
|
|
||||||
if (_mapWarshipsCollectionGeneric == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
FormCreater dialog=new FormCreater();
|
|
||||||
dialog.setSize(1200,700);
|
|
||||||
dialog.setModalityType(Dialog.ModalityType.APPLICATION_MODAL);
|
|
||||||
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
|
||||||
dialog.setVisible(true);
|
|
||||||
if (dialog.getSelectedWarship()!=null) {
|
|
||||||
DrawingObjectWarship warship = new DrawingObjectWarship(dialog.getSelectedWarship());
|
|
||||||
|
|
||||||
if (_mapWarshipsCollectionGeneric.plus(warship) >= 0) {
|
|
||||||
JOptionPane.showMessageDialog(this, "Объект добавлен", "Успех", JOptionPane.INFORMATION_MESSAGE);
|
|
||||||
bufferedImage = _mapWarshipsCollectionGeneric.ShowSet();
|
|
||||||
repaint();
|
|
||||||
} else {
|
|
||||||
JOptionPane.showMessageDialog(this, "Не удалось добавить объект", "Ошибка",JOptionPane.INFORMATION_MESSAGE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
ButtonRemoveWarship.addActionListener(e -> {
|
|
||||||
String txt=TextBoxPosition.getText();
|
|
||||||
if (txt==null||_mapWarshipsCollectionGeneric==null||txt.isEmpty())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
int result = JOptionPane.showConfirmDialog(
|
|
||||||
this,
|
|
||||||
"Удалить объект?",
|
|
||||||
"Удаление",
|
|
||||||
JOptionPane.YES_NO_CANCEL_OPTION);
|
|
||||||
if (result == JOptionPane.NO_OPTION)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
int pos = Integer.parseInt(txt);
|
|
||||||
if (_mapWarshipsCollectionGeneric.minus(pos) !=null)
|
|
||||||
{
|
|
||||||
JOptionPane.showMessageDialog(this,"Объект удален","Успех",JOptionPane.INFORMATION_MESSAGE);
|
|
||||||
bufferedImage = _mapWarshipsCollectionGeneric.ShowSet();
|
|
||||||
repaint();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
JOptionPane.showMessageDialog(this,"Не удалось удалить объект","Ошибка",JOptionPane.INFORMATION_MESSAGE);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
СomboBoxSelectorMap.addActionListener(e -> {
|
|
||||||
AbstractMap map = null;
|
|
||||||
|
|
||||||
switch (СomboBoxSelectorMap.getSelectedItem().toString())
|
|
||||||
{
|
|
||||||
case "Первая карта":
|
|
||||||
map = new SimpleMap();
|
|
||||||
break;
|
|
||||||
case "Вторая карта":
|
|
||||||
map = new SecondMap();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (map != null)
|
|
||||||
{
|
|
||||||
_mapWarshipsCollectionGeneric = new MapWithSetWarshipsGeneric<>(
|
|
||||||
PictureBox.getWidth(), PictureBox.getHeight(), map);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_mapWarshipsCollectionGeneric = null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
ButtonUp.addActionListener(e -> {
|
|
||||||
if (_mapWarshipsCollectionGeneric != null) {
|
|
||||||
bufferedImage = _mapWarshipsCollectionGeneric.MoveObject(Direction.Up);
|
|
||||||
repaint();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
ButtonDown.addActionListener(e -> {
|
|
||||||
if (_mapWarshipsCollectionGeneric != null) {
|
|
||||||
bufferedImage = _mapWarshipsCollectionGeneric.MoveObject(Direction.Down);
|
|
||||||
repaint();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
ButtonRight.addActionListener(e -> {
|
|
||||||
if (_mapWarshipsCollectionGeneric != null) {
|
|
||||||
bufferedImage = _mapWarshipsCollectionGeneric.MoveObject(Direction.Right);
|
|
||||||
repaint();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
ButtonLeft.addActionListener(e -> {
|
|
||||||
if (_mapWarshipsCollectionGeneric != null) {
|
|
||||||
bufferedImage = _mapWarshipsCollectionGeneric.MoveObject(Direction.Left);
|
|
||||||
repaint();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,182 +0,0 @@
|
|||||||
<?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,85 +1,136 @@
|
|||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.ComponentAdapter;
|
import java.awt.event.*;
|
||||||
import java.awt.event.ComponentEvent;
|
public class FormWarship extends JFrame{
|
||||||
|
|
||||||
public class FormWarship extends JDialog{
|
|
||||||
private int Width;
|
private int Width;
|
||||||
private int Height;
|
private int Height;
|
||||||
DrawingField field = new DrawingField(this);
|
|
||||||
DrawingWarship SelectedWarship;
|
|
||||||
private JButton ButtonDown;
|
|
||||||
private JButton ButtonRight;
|
|
||||||
private JButton ButtonLeft;
|
|
||||||
private JButton ButtonUp;
|
|
||||||
private JButton ButtonCreate;
|
|
||||||
private JButton ButtonCreateModif;
|
|
||||||
public JLabel SpeedLabel;
|
|
||||||
public JLabel WeightLabel;
|
|
||||||
public JLabel BodyColorLabel;
|
|
||||||
private JPanel PictureBox;
|
|
||||||
private JButton ButtonSelect;
|
|
||||||
|
|
||||||
public FormWarship(JFrame frame){
|
JPanel BottomPanel = new JPanel();
|
||||||
super(frame,"Военный корабль");
|
JPanel CreatePanel = new JPanel();
|
||||||
setContentPane(PictureBox);
|
JPanel BottomAndCreatePanel = new JPanel();
|
||||||
setSize(1000,700);
|
JPanel DimentionPanel = new JPanel();
|
||||||
Width = getWidth();
|
JPanel UPanel = new JPanel();
|
||||||
Height = getHeight();
|
JPanel DPanel = new JPanel();
|
||||||
|
JPanel LRPanel = new JPanel();
|
||||||
|
|
||||||
|
JLabel SpeedLabel = new JLabel("Скорость: ");
|
||||||
|
JLabel WeightLabel = new JLabel("Вес: ");
|
||||||
|
JLabel BodyColorLabel = new JLabel("Цвет: ");
|
||||||
|
|
||||||
|
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(){
|
||||||
|
super("Военный корабль");
|
||||||
|
setSize(700,400);
|
||||||
|
Width=getWidth();
|
||||||
|
Height=getHeight();
|
||||||
ShowWindow();
|
ShowWindow();
|
||||||
field.setBounds(0,0,Width,Height);
|
RefreshWindow();
|
||||||
setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
|
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
setVisible(true);
|
setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ShowWindow(){
|
public void ShowWindow(){
|
||||||
|
|
||||||
ButtonCreate.addActionListener(e -> {
|
Dimension dimen=new Dimension(30,30);
|
||||||
|
|
||||||
|
ButtonUp.setPreferredSize(dimen);
|
||||||
|
ButtonUp.addActionListener(e->{
|
||||||
|
field.UpButtonAction();
|
||||||
|
repaint();
|
||||||
|
});
|
||||||
|
|
||||||
|
ButtonDown.setPreferredSize(dimen);
|
||||||
|
ButtonDown.addActionListener(e->{
|
||||||
|
field.DownButtonAction();
|
||||||
|
repaint();
|
||||||
|
});
|
||||||
|
|
||||||
|
ButtonRight.setPreferredSize(dimen);
|
||||||
|
ButtonRight.addActionListener(e->{
|
||||||
|
field.RightButtonAction();
|
||||||
|
repaint();
|
||||||
|
});
|
||||||
|
|
||||||
|
ButtonLeft.setPreferredSize(dimen);
|
||||||
|
ButtonLeft.addActionListener(e->{
|
||||||
|
field.LeftButtonAction();
|
||||||
|
repaint();
|
||||||
|
});
|
||||||
|
|
||||||
|
LRPanel.setLayout(new FlowLayout(FlowLayout.CENTER,50,0));
|
||||||
|
LRPanel.setBackground(new Color(0,0,0,0));
|
||||||
|
LRPanel.add(ButtonLeft);
|
||||||
|
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();
|
field.CreateButtonAction();
|
||||||
ReDraw();
|
repaint();
|
||||||
});
|
|
||||||
ButtonCreateModif.addActionListener(e -> {
|
|
||||||
field.CreateModifButtonAction();
|
|
||||||
ReDraw();
|
|
||||||
});
|
|
||||||
ButtonUp.addActionListener(e -> {
|
|
||||||
field.DirectionButtonAction(Direction.Up);
|
|
||||||
ReDraw();
|
|
||||||
});
|
|
||||||
ButtonLeft.addActionListener(e -> {
|
|
||||||
field.DirectionButtonAction(Direction.Left);
|
|
||||||
ReDraw();
|
|
||||||
});
|
|
||||||
ButtonRight.addActionListener(e -> {
|
|
||||||
field.DirectionButtonAction(Direction.Right);
|
|
||||||
ReDraw();
|
|
||||||
});
|
|
||||||
ButtonDown.addActionListener(e -> {
|
|
||||||
field.DirectionButtonAction(Direction.Down);
|
|
||||||
ReDraw();
|
|
||||||
});
|
|
||||||
ButtonSelect.addActionListener(e -> {
|
|
||||||
SelectedWarship=field.GetDrawingWarship();
|
|
||||||
JOptionPane.showMessageDialog(PictureBox, "Корабль добавлен.");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
BottomPanel.setLayout(new FlowLayout());
|
||||||
|
BottomPanel.setBackground(new Color(0,0,0,0));
|
||||||
|
BottomPanel.add(SpeedLabel);
|
||||||
|
BottomPanel.add(WeightLabel);
|
||||||
|
BottomPanel.add(BodyColorLabel);
|
||||||
|
|
||||||
|
BottomAndCreatePanel.setLayout(new BoxLayout(BottomAndCreatePanel,BoxLayout.Y_AXIS));
|
||||||
|
BottomAndCreatePanel.setBackground(new Color(0,0,0,0));
|
||||||
|
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();
|
||||||
|
|
||||||
field.ResizeField();
|
field.ResizeField();
|
||||||
ReDraw();
|
repaint();
|
||||||
field.setBounds(0,0,Width,Height);
|
RefreshWindow();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
private void ReDraw() {
|
public void RefreshWindow(){
|
||||||
Graphics2D graphics = (Graphics2D) PictureBox.getGraphics();
|
field.setBounds(0,0,Width,Height);
|
||||||
graphics.clearRect(0, 0, PictureBox.getWidth(), PictureBox.getHeight());
|
BottomAndCreatePanel.setBounds(-220,Height-110,Width,80);
|
||||||
PictureBox.paintComponents(graphics);
|
DimentionPanel.setBounds(Width-170,Height-170,190,140);
|
||||||
field.Draw(graphics);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +0,0 @@
|
|||||||
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();
|
|
||||||
}
|
|
@ -1,6 +0,0 @@
|
|||||||
import java.awt.*;
|
|
||||||
|
|
||||||
public interface IDrawingObjectBlock {
|
|
||||||
void SetBlockCount(int count);
|
|
||||||
void DrawBlock(Graphics2D g, int _startPosX, int _startPosY);
|
|
||||||
}
|
|
@ -1,5 +1,6 @@
|
|||||||
public class Main {
|
public class Main {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
new FormMapWithSetWarships();
|
new FormWarship();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,126 +0,0 @@
|
|||||||
import java.awt.*;
|
|
||||||
import java.awt.image.BufferedImage;
|
|
||||||
|
|
||||||
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;
|
|
||||||
private final SetWarshipsGeneric<T> _setWarship;
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int plus(T warship)
|
|
||||||
{
|
|
||||||
return _setWarship.Insert(warship);
|
|
||||||
}
|
|
||||||
|
|
||||||
public T minus(int position)
|
|
||||||
{
|
|
||||||
return _setWarship.Remove(position);
|
|
||||||
}
|
|
||||||
|
|
||||||
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 (int i = 0; i < _setWarship.Count(); i++)
|
|
||||||
{
|
|
||||||
T warship = _setWarship.Get(i);
|
|
||||||
if (warship != null)
|
|
||||||
{
|
|
||||||
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 width = _pictureWidth / _placeSizeWidth;
|
|
||||||
int height = _pictureHeight / _placeSizeHeight;
|
|
||||||
|
|
||||||
for (int i = 0; i < _setWarship.Count(); i++)
|
|
||||||
{
|
|
||||||
if (_setWarship.Get(i) != null)
|
|
||||||
{
|
|
||||||
_setWarship.Get(i).SetObject(i % width * _placeSizeWidth, (height - 1 - i / width) * _placeSizeHeight, _pictureWidth, _pictureHeight);
|
|
||||||
_setWarship.Get(i).DrawingObject(gr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,37 +0,0 @@
|
|||||||
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)));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,68 +0,0 @@
|
|||||||
public class SetWarshipsGeneric<T extends Object> {
|
|
||||||
private final Object[] _places;
|
|
||||||
|
|
||||||
public int Count() {
|
|
||||||
return _places.length;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SetWarshipsGeneric(int count)
|
|
||||||
{
|
|
||||||
_places = new Object[count];
|
|
||||||
}
|
|
||||||
|
|
||||||
public int Insert(T warship)
|
|
||||||
{
|
|
||||||
return Insert(warship,0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int Insert(T warship, int position)
|
|
||||||
{
|
|
||||||
int EmptyEl=-1;
|
|
||||||
|
|
||||||
if (position>=Count() || position < 0)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
if (_places[position] == null)
|
|
||||||
{
|
|
||||||
_places[position] = warship;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (_places[position] != null)
|
|
||||||
{
|
|
||||||
for (int i = position + 1; i < Count(); i++)
|
|
||||||
if (_places[i] == null)
|
|
||||||
{
|
|
||||||
EmptyEl = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (EmptyEl == -1)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
for (int i = EmptyEl; i > position; i--)
|
|
||||||
_places[i] = _places[i - 1];
|
|
||||||
}
|
|
||||||
|
|
||||||
_places[position] = warship;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public T Remove(int position)
|
|
||||||
{
|
|
||||||
if (position >= Count() || position < 0 || _places[position]==null)
|
|
||||||
return null;
|
|
||||||
|
|
||||||
T deleted =(T)_places[position];
|
|
||||||
_places[position] = null;
|
|
||||||
return deleted;
|
|
||||||
}
|
|
||||||
|
|
||||||
public T Get(int position)
|
|
||||||
{
|
|
||||||
if (position >= Count() || position < 0)
|
|
||||||
return null;
|
|
||||||
|
|
||||||
return (T)_places[position];
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,36 +0,0 @@
|
|||||||
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