Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
930a436de9 | |||
deba91e044 | |||
86539b4d23 | |||
0391fff9dc | |||
2a90e0d4b0 | |||
4c43d95862 | |||
34e21f2507 | |||
973cec8de7 |
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11.0.5" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/../../../ирино, не трогат/!/!/!/!/RPP/ProjectAircraftCarrierHard/out" />
|
||||
<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" />
|
||||
</component>
|
||||
</project>
|
150
src/AbstractMap.java
Normal file
150
src/AbstractMap.java
Normal file
@ -0,0 +1,150 @@
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.Random;
|
||||
|
||||
public abstract class AbstractMap {
|
||||
private IDrawingObject _drawingObject = null;
|
||||
protected int[][] _map = null;
|
||||
protected int _width;
|
||||
protected int _height;
|
||||
protected float _size_x;
|
||||
protected float _size_y;
|
||||
protected final Random _random = new Random();
|
||||
protected final int _freeRoad = 0;
|
||||
protected final int _barrier = 1;
|
||||
|
||||
public BufferedImage CreateMap(int width, int height, IDrawingObject drawningObject)
|
||||
{
|
||||
_width = width;
|
||||
_height = height;
|
||||
_drawingObject = drawningObject;
|
||||
GenerateMap();
|
||||
while (!SetObjectOnMap())
|
||||
{
|
||||
GenerateMap();
|
||||
}
|
||||
return DrawMapWithObject();
|
||||
}
|
||||
|
||||
public BufferedImage MoveObject(Direction direction)
|
||||
{
|
||||
if(_drawingObject!=null){
|
||||
float[] cortege = _drawingObject.GetCurrentPosition();
|
||||
if (Check(cortege[0],cortege[1],cortege[2],cortege[3]) != 0)
|
||||
{
|
||||
_drawingObject.MoveObject(GetOpositDirection(direction));
|
||||
}
|
||||
if(true){
|
||||
_drawingObject.MoveObject(direction);
|
||||
}
|
||||
return DrawMapWithObject();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private Direction GetOpositDirection(Direction dir)
|
||||
{
|
||||
switch (dir)
|
||||
{
|
||||
case None:
|
||||
return Direction.None;
|
||||
case Up:
|
||||
return Direction.Down;
|
||||
case Down:
|
||||
return Direction.Up;
|
||||
case Left:
|
||||
return Direction.Right;
|
||||
case Right:
|
||||
return Direction.Left;
|
||||
}
|
||||
return Direction.None;
|
||||
}
|
||||
|
||||
private boolean SetObjectOnMap()
|
||||
{
|
||||
if (_drawingObject == null || _map == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
int x = _random.nextInt(0, 10);
|
||||
int y = _random.nextInt(0, 10);
|
||||
_drawingObject.SetObject(x, y, _width, _height);
|
||||
float[] cortege = _drawingObject.GetCurrentPosition();
|
||||
|
||||
while (Check(cortege[0], cortege[1], cortege[2], cortege[3]) != 2)
|
||||
{
|
||||
int result;
|
||||
do
|
||||
{
|
||||
result = Check(cortege[0], cortege[1], cortege[2], cortege[3]);
|
||||
if (result == 0)
|
||||
{
|
||||
_drawingObject.SetObject((int)cortege[0], (int)cortege[1], _width, _height);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
cortege[0] += _size_x;
|
||||
}
|
||||
} while (result != 2);
|
||||
cortege[0] = x;
|
||||
cortege[1] += _size_y;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private int Check(float Left, float Right, float Top, float Bottom)
|
||||
{
|
||||
int startX = (int)(Left / _size_x);
|
||||
int startY = (int)(Right / _size_y);
|
||||
int endX = (int)(Top / _size_x);
|
||||
int endY = (int)(Bottom / _size_y);
|
||||
if (startX < 0 || startY < 0 || endX >= _map[0].length || endY >= _map.length)
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
for (int i = startX; i <= endX; i++)
|
||||
{
|
||||
for (int j = startY; j <= endY; j++)
|
||||
{
|
||||
if (_map[i][j] == _barrier)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
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.length; ++j)
|
||||
{
|
||||
if (_map[i][j] == _freeRoad)
|
||||
{
|
||||
DrawRoadPart(gr, i, j);
|
||||
}
|
||||
else if (_map[i][j] == _barrier)
|
||||
{
|
||||
DrawBarrierPart(gr, i, j);
|
||||
}
|
||||
}
|
||||
}
|
||||
_drawingObject.DrawingObject(gr);
|
||||
return bmp;
|
||||
}
|
||||
|
||||
protected abstract void GenerateMap();
|
||||
protected abstract void DrawRoadPart(Graphics g, int i, int j);
|
||||
protected abstract void DrawBarrierPart(Graphics g, int i, int j);
|
||||
}
|
||||
|
13
src/BlockCount.java
Normal file
13
src/BlockCount.java
Normal file
@ -0,0 +1,13 @@
|
||||
public enum BlockCount {
|
||||
TwoBlocks(2),
|
||||
FourBlocks(4),
|
||||
SixBlocks(6);
|
||||
|
||||
private final int Value;
|
||||
BlockCount(int count){
|
||||
Value=count;
|
||||
}
|
||||
public int GetBlockCount(){
|
||||
return Value;
|
||||
}
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
public enum BlockDirection {
|
||||
TwoBlocks,
|
||||
FourBlocks,
|
||||
SixBlocks;
|
||||
}
|
9
src/BlockForm.java
Normal file
9
src/BlockForm.java
Normal file
@ -0,0 +1,9 @@
|
||||
public enum BlockForm {
|
||||
Rect(0),
|
||||
Round(1),
|
||||
RoundRectangle(2);
|
||||
public final int Value;
|
||||
BlockForm(int i) {
|
||||
Value=i;
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
public enum Direction {
|
||||
None,
|
||||
Up,
|
||||
Down,
|
||||
Left,
|
||||
|
87
src/DrawingAircraftCarrier.java
Normal file
87
src/DrawingAircraftCarrier.java
Normal file
@ -0,0 +1,87 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawingAircraftCarrier extends DrawingWarship{
|
||||
|
||||
public DrawingAircraftCarrier(int speed, float weight, Color bodyColor, Color dopColor, boolean bodyKit, boolean cabin, boolean superEngine)
|
||||
{
|
||||
super(speed, weight, bodyColor, 114, 40);
|
||||
Warship = new EntityAircraftCarrier(speed, weight, bodyColor, dopColor, bodyKit, cabin, superEngine);
|
||||
}
|
||||
|
||||
public DrawingAircraftCarrier(EntityWarship warship, IDrawingObjectBlock additionalObject) {
|
||||
super(warship, additionalObject);
|
||||
Warship = warship;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void DrawTransport(Graphics gr){
|
||||
if(!(Warship instanceof EntityAircraftCarrier))
|
||||
{
|
||||
return;
|
||||
}
|
||||
Graphics2D g2 = (Graphics2D) gr;
|
||||
EntityAircraftCarrier aircraftCarrier = (EntityAircraftCarrier) Warship;
|
||||
|
||||
if (aircraftCarrier.GetBodyKit())
|
||||
{
|
||||
//боковая площадка
|
||||
int[] pointXArea = {_startPosX + 94, _startPosX + 74, _startPosX + 24, _startPosX + 4};
|
||||
int[] pointYArea = {_startPosY + 40, _startPosY + 60, _startPosY + 60, _startPosY + 40};
|
||||
g2.setColor(Warship.GetBodyColor());
|
||||
g2.fillPolygon(pointXArea, pointYArea, 4);
|
||||
g2.setColor(Color.BLACK);
|
||||
g2.drawPolygon(pointXArea, pointYArea, 4);
|
||||
|
||||
//полоса
|
||||
int[] pointXLine = {_startPosX + 4, _startPosX + 15, _startPosX + 74, _startPosX + 59};
|
||||
int[] pointYLine = {_startPosY, _startPosY, _startPosY + 60, _startPosY + 60};
|
||||
g2.setColor(Color.GRAY);
|
||||
g2.fillPolygon(pointXLine, pointYLine, 4);
|
||||
g2.setColor(Color.BLACK);
|
||||
g2.drawPolygon(pointXLine, pointYLine, 4);
|
||||
}
|
||||
|
||||
if (aircraftCarrier.GetSuperEngine())
|
||||
{
|
||||
g2.setColor(Color.RED);
|
||||
g2.fillOval(_startPosX, _startPosY, 10, 10);
|
||||
g2.setColor(Color.BLACK);
|
||||
g2.drawOval(_startPosX, _startPosY, 10, 10);
|
||||
|
||||
g2.setColor(Color.RED);
|
||||
g2.fillOval(_startPosX, _startPosY + 10, 10, 10);
|
||||
g2.setColor(Color.BLACK);
|
||||
g2.drawOval(_startPosX, _startPosY + 10, 10, 10);
|
||||
|
||||
g2.setColor(Color.RED);
|
||||
g2.fillOval(_startPosX, _startPosY + 18, 10, 10);
|
||||
g2.setColor(Color.BLACK);
|
||||
g2.drawOval(_startPosX, _startPosY + 18, 10, 10);
|
||||
|
||||
g2.setColor(Color.RED);
|
||||
g2.fillOval(_startPosX, _startPosY + 30, 10, 10);
|
||||
g2.setColor(Color.BLACK);
|
||||
g2.drawOval(_startPosX, _startPosY + 30, 10, 10);
|
||||
}
|
||||
|
||||
super.DrawTransport(g2);
|
||||
|
||||
if (aircraftCarrier.GetCabin())
|
||||
{
|
||||
g2.setColor(Color.GRAY);
|
||||
g2.fillOval(_startPosX + 80, _startPosY + 13, 10, 14);
|
||||
g2.setColor(Color.BLACK);
|
||||
g2.drawOval(_startPosX + 80, _startPosY + 13, 10, 14);
|
||||
|
||||
g2.setColor(Color.GRAY);
|
||||
g2.fillOval(_startPosX + 90, _startPosY + 13, 10, 14);
|
||||
g2.setColor(Color.BLACK);
|
||||
g2.drawOval(_startPosX + 90, _startPosY + 13, 10, 14);
|
||||
|
||||
g2.setColor(Color.GRAY);
|
||||
g2.fillRect(_startPosX + 85, _startPosY + 13, 10, 14);
|
||||
g2.setColor(Color.BLACK);
|
||||
g2.drawRect(_startPosX + 85, _startPosY + 13, 10, 14);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,45 +1,43 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawingBlocks {
|
||||
BlockDirection blockDirection;
|
||||
public class DrawingBlocks implements IDrawingObjectBlock{
|
||||
private BlockCount _block;
|
||||
public DrawingBlocks(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 DrawBlocks(Graphics2D g2, int _startPosX, int _startPosY){
|
||||
switch(blockDirection){
|
||||
case TwoBlocks:
|
||||
g2.setColor(Color.GRAY);
|
||||
g2.fillRect(_startPosX + 15, _startPosY + 10, 10, 10);
|
||||
g2.fillRect(_startPosX + 15, _startPosY + 20, 10, 10);
|
||||
g2.setColor(Color.BLACK);
|
||||
g2.drawRect(_startPosX + 15, _startPosY + 10, 10, 10);
|
||||
g2.drawRect(_startPosX + 15, _startPosY + 20, 10, 10);
|
||||
break;
|
||||
case FourBlocks:
|
||||
g2.setColor(Color.GRAY);
|
||||
g2.fillRect(_startPosX + 15, _startPosY + 10, 10, 10);
|
||||
g2.fillRect(_startPosX + 15, _startPosY + 20, 10, 10);
|
||||
g2.fillRect(_startPosX + 25, _startPosY + 10, 10, 10);
|
||||
g2.fillRect(_startPosX + 25, _startPosY + 20, 10, 10);
|
||||
g2.setColor(Color.BLACK);
|
||||
g2.drawRect(_startPosX + 15, _startPosY + 10, 10, 10);
|
||||
g2.drawRect(_startPosX + 15, _startPosY + 20, 10, 10);
|
||||
g2.drawRect(_startPosX + 25, _startPosY + 10, 10, 10);
|
||||
g2.drawRect(_startPosX + 25, _startPosY + 20, 10, 10);
|
||||
break;
|
||||
case SixBlocks:
|
||||
g2.setColor(Color.GRAY);
|
||||
g2.fillRect(_startPosX + 15, _startPosY + 10, 10, 10);
|
||||
g2.fillRect(_startPosX + 15, _startPosY + 20, 10, 10);
|
||||
g2.fillRect(_startPosX + 25, _startPosY + 10, 10, 10);
|
||||
g2.fillRect(_startPosX + 25, _startPosY + 20, 10, 10);
|
||||
g2.fillRect(_startPosX + 35, _startPosY + 10, 10, 10);
|
||||
g2.fillRect(_startPosX + 35, _startPosY + 20, 10, 10);
|
||||
g2.setColor(Color.BLACK);
|
||||
g2.drawRect(_startPosX + 15, _startPosY + 10, 10, 10);
|
||||
g2.drawRect(_startPosX + 15, _startPosY + 20, 10, 10);
|
||||
g2.drawRect(_startPosX + 25, _startPosY + 10, 10, 10);
|
||||
g2.drawRect(_startPosX + 25, _startPosY + 20, 10, 10);
|
||||
g2.drawRect(_startPosX + 35, _startPosY + 10, 10, 10);
|
||||
g2.drawRect(_startPosX + 35, _startPosY + 20, 10, 10);
|
||||
break;
|
||||
if (_block.GetBlockCount() >= 2) {
|
||||
g2.setColor(Color.GRAY);
|
||||
g2.fillRect(_startPosX + 15, _startPosY + 10, 10, 10);
|
||||
g2.fillRect(_startPosX + 15, _startPosY + 20, 10, 10);
|
||||
g2.setColor(Color.BLACK);
|
||||
g2.drawRect(_startPosX + 15, _startPosY + 10, 10, 10);
|
||||
g2.drawRect(_startPosX + 15, _startPosY + 20, 10, 10);
|
||||
}
|
||||
if (_block.GetBlockCount() >= 4) {
|
||||
g2.setColor(Color.GRAY);
|
||||
g2.fillRect(_startPosX + 25, _startPosY + 10, 10, 10);
|
||||
g2.fillRect(_startPosX + 25, _startPosY + 20, 10, 10);
|
||||
g2.setColor(Color.BLACK);
|
||||
g2.drawRect(_startPosX + 25, _startPosY + 10, 10, 10);
|
||||
g2.drawRect(_startPosX + 25, _startPosY + 20, 10, 10);
|
||||
}
|
||||
if (_block.GetBlockCount() >= 6) {
|
||||
g2.setColor(Color.GRAY);
|
||||
g2.fillRect(_startPosX + 35, _startPosY + 10, 10, 10);
|
||||
g2.fillRect(_startPosX + 35, _startPosY + 20, 10, 10);
|
||||
g2.setColor(Color.BLACK);
|
||||
g2.drawRect(_startPosX + 35, _startPosY + 10, 10, 10);
|
||||
g2.drawRect(_startPosX + 35, _startPosY + 20, 10, 10);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,22 +0,0 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawingComponents extends JComponent {
|
||||
public DrawingWarship warship;
|
||||
public DrawingComponents(){
|
||||
super();
|
||||
}
|
||||
public void SetDrawingWarship(DrawingWarship warship){
|
||||
this.warship = warship;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paintComponent(Graphics g){
|
||||
super.paintComponent(g);
|
||||
Graphics2D g2 = (Graphics2D) g;
|
||||
if(warship != null){
|
||||
warship.DrawTransport(g2);
|
||||
}
|
||||
repaint();
|
||||
}
|
||||
}
|
37
src/DrawingObjectWarship.java
Normal file
37
src/DrawingObjectWarship.java
Normal file
@ -0,0 +1,37 @@
|
||||
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;
|
||||
}
|
||||
}
|
43
src/DrawingRoundBlocks.java
Normal file
43
src/DrawingRoundBlocks.java
Normal file
@ -0,0 +1,43 @@
|
||||
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 DrawBlocks(Graphics2D g2, int _startPosX, int _startPosY){
|
||||
if (_block.GetBlockCount() >= 2) {
|
||||
g2.setColor(Color.GRAY);
|
||||
g2.fillOval(_startPosX + 15, _startPosY + 10, 10, 10);
|
||||
g2.fillOval(_startPosX + 15, _startPosY + 20, 10, 10);
|
||||
g2.setColor(Color.BLACK);
|
||||
g2.drawOval(_startPosX + 15, _startPosY + 10, 10, 10);
|
||||
g2.drawOval(_startPosX + 15, _startPosY + 20, 10, 10);
|
||||
}
|
||||
if (_block.GetBlockCount() >= 4) {
|
||||
g2.setColor(Color.GRAY);
|
||||
g2.fillOval(_startPosX + 25, _startPosY + 10, 10, 10);
|
||||
g2.fillOval(_startPosX + 25, _startPosY + 20, 10, 10);
|
||||
g2.setColor(Color.BLACK);
|
||||
g2.drawOval(_startPosX + 25, _startPosY + 10, 10, 10);
|
||||
g2.drawOval(_startPosX + 25, _startPosY + 20, 10, 10);
|
||||
}
|
||||
if (_block.GetBlockCount() >= 6) {
|
||||
g2.setColor(Color.GRAY);
|
||||
g2.fillOval(_startPosX + 35, _startPosY + 10, 10, 10);
|
||||
g2.fillOval(_startPosX + 35, _startPosY + 20, 10, 10);
|
||||
g2.setColor(Color.BLACK);
|
||||
g2.drawOval(_startPosX + 35, _startPosY + 10, 10, 10);
|
||||
g2.drawOval(_startPosX + 35, _startPosY + 20, 10, 10);
|
||||
}
|
||||
}
|
||||
}
|
43
src/DrawingRoundRectangleBlocks.java
Normal file
43
src/DrawingRoundRectangleBlocks.java
Normal file
@ -0,0 +1,43 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawingRoundRectangleBlocks implements IDrawingObjectBlock {
|
||||
private BlockCount _block;
|
||||
public DrawingRoundRectangleBlocks(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 DrawBlocks(Graphics2D g2, int _startPosX, int _startPosY){
|
||||
if (_block.GetBlockCount() >= 2) {
|
||||
g2.setColor(Color.GRAY);
|
||||
g2.fillRoundRect(_startPosX + 15, _startPosY + 10, 10, 10, 7, 7);
|
||||
g2.fillRoundRect(_startPosX + 15, _startPosY + 20, 10, 10, 7, 7);
|
||||
g2.setColor(Color.BLACK);
|
||||
g2.drawRoundRect(_startPosX + 15, _startPosY + 10, 10, 10, 7, 7);
|
||||
g2.drawRoundRect(_startPosX + 15, _startPosY + 20, 10, 10, 7, 7);
|
||||
}
|
||||
if (_block.GetBlockCount() >= 4) {
|
||||
g2.setColor(Color.GRAY);
|
||||
g2.fillRoundRect(_startPosX + 25, _startPosY + 10, 10, 10, 7, 7);
|
||||
g2.fillRoundRect(_startPosX + 25, _startPosY + 20, 10, 10, 7, 7);
|
||||
g2.setColor(Color.BLACK);
|
||||
g2.drawRoundRect(_startPosX + 25, _startPosY + 10, 10, 10, 7, 7);
|
||||
g2.drawRoundRect(_startPosX + 25, _startPosY + 20, 10, 10, 7, 7);
|
||||
}
|
||||
if (_block.GetBlockCount() >= 6) {
|
||||
g2.setColor(Color.GRAY);
|
||||
g2.fillRoundRect(_startPosX + 35, _startPosY + 10, 10, 10, 7, 7);
|
||||
g2.fillRoundRect(_startPosX + 35, _startPosY + 20, 10, 10, 7, 7);
|
||||
g2.setColor(Color.BLACK);
|
||||
g2.drawRoundRect(_startPosX + 35, _startPosY + 10, 10, 10, 7, 7);
|
||||
g2.drawRoundRect(_startPosX + 35, _startPosY + 20, 10, 10, 7, 7);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,25 +1,69 @@
|
||||
import java.awt.*;
|
||||
import java.util.Random;
|
||||
public class DrawingWarship {
|
||||
private EntityWarship Warship;
|
||||
protected EntityWarship Warship;
|
||||
public EntityWarship GetWarship(){return Warship;}
|
||||
public DrawingBlocks Blocks;
|
||||
protected IDrawingObjectBlock Blocks;
|
||||
private BlockCount _block;
|
||||
|
||||
private int _startPosX;
|
||||
private int _startPosY;
|
||||
protected int _startPosX;
|
||||
protected int _startPosY;
|
||||
|
||||
private Integer _pictureWidth = null;
|
||||
private Integer _pictureHeight = null;
|
||||
|
||||
private final int _warshipWidth = 114;
|
||||
private final int _warshipHeight = 40;
|
||||
private int _warshipWidth = 114;
|
||||
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.Init(speed, weight, bodyColor);
|
||||
Blocks = new DrawingBlocks();
|
||||
Blocks.blockDirection = BlockRandom();
|
||||
Warship = new EntityWarship(speed, weight, bodyColor);
|
||||
Blocks = GetFormOfBlock(blockForm);
|
||||
Blocks.SetBlockCount(BlockRandom());
|
||||
}
|
||||
|
||||
protected DrawingWarship(int speed, float weight, Color bodyColor, int warshipWidth, int warshipHeight)
|
||||
{
|
||||
Warship = new EntityWarship(speed, weight, bodyColor);
|
||||
Blocks = new DrawingBlocks(_block);
|
||||
Blocks.SetBlockCount(BlockRandom());
|
||||
_warshipWidth = warshipWidth;
|
||||
_warshipHeight = warshipHeight;
|
||||
}
|
||||
|
||||
public DrawingWarship(EntityWarship warship,IDrawingObjectBlock block){
|
||||
Warship = warship;
|
||||
Blocks = block;
|
||||
}
|
||||
|
||||
public int BlockRandom(){
|
||||
Random rnd = new Random();
|
||||
int count = rnd.nextInt(0,3);
|
||||
if(count == 0) return 2;
|
||||
if(count == 1) return 4;
|
||||
if(count == 2) return 6;
|
||||
return 0;
|
||||
}
|
||||
|
||||
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 DrawingBlocks(_block);
|
||||
case Round:
|
||||
return new DrawingRoundBlocks(_block);
|
||||
case RoundRectangle:
|
||||
return new DrawingRoundRectangleBlocks(_block);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void SetPosition(int x, int y, int width, int height)
|
||||
@ -32,6 +76,7 @@ public class DrawingWarship {
|
||||
_pictureHeight = height;
|
||||
}
|
||||
}
|
||||
|
||||
public void MoveTransport(Direction direction)
|
||||
{
|
||||
if (_pictureWidth == null || _pictureHeight == null)
|
||||
@ -70,11 +115,13 @@ public class DrawingWarship {
|
||||
break;
|
||||
}
|
||||
}
|
||||
public void DrawTransport(Graphics2D g2){
|
||||
|
||||
public void DrawTransport(Graphics gr){
|
||||
if (_startPosX < 0 || _startPosY < 0 || _pictureHeight == null || _pictureWidth == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Graphics2D g2 = (Graphics2D) gr;
|
||||
//главная палуба
|
||||
int[] pointXWarship = {_startPosX + 4, _startPosX + 94, _startPosX + 114, _startPosX + 94, _startPosX + 4};
|
||||
int[] pointYWarship = {_startPosY, _startPosY, _startPosY + 20, _startPosY + 40, _startPosY + 40};
|
||||
@ -107,15 +154,6 @@ public class DrawingWarship {
|
||||
Blocks.DrawBlocks(g2,_startPosX, _startPosY);
|
||||
}
|
||||
|
||||
public BlockDirection BlockRandom(){
|
||||
Random rand = new Random();
|
||||
int resRand = rand.nextInt(3);
|
||||
if(resRand == 0) return BlockDirection.TwoBlocks;
|
||||
if(resRand == 1) return BlockDirection.FourBlocks;
|
||||
if(resRand == 2) return BlockDirection.SixBlocks;
|
||||
return null;
|
||||
}
|
||||
|
||||
public void ChangeBorders(int width, int height)
|
||||
{
|
||||
_pictureWidth = width;
|
||||
@ -135,4 +173,13 @@ public class DrawingWarship {
|
||||
_startPosY = _pictureHeight - _warshipHeight;
|
||||
}
|
||||
}
|
||||
|
||||
public float[] GetCurrentPosition(){
|
||||
float[] cortege = new float[4];
|
||||
cortege[0] = _startPosX;
|
||||
cortege[1] =_startPosY;
|
||||
cortege[2] = _startPosX + _warshipWidth;
|
||||
cortege[3] = _startPosY + _warshipHeight;
|
||||
return cortege;
|
||||
}
|
||||
}
|
||||
|
24
src/EntityAircraftCarrier.java
Normal file
24
src/EntityAircraftCarrier.java
Normal file
@ -0,0 +1,24 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class EntityAircraftCarrier extends EntityWarship {
|
||||
private Color DopColor;
|
||||
public Color GetDopColor(){return DopColor;}
|
||||
|
||||
private boolean BodyKit;
|
||||
public boolean GetBodyKit(){return BodyKit;}
|
||||
|
||||
private boolean Cabin;
|
||||
public boolean GetCabin(){return Cabin;}
|
||||
|
||||
private boolean SuperEngine;
|
||||
public boolean GetSuperEngine(){return SuperEngine;}
|
||||
|
||||
public EntityAircraftCarrier(int speed, float weight, Color bodyColor, Color dopColor, boolean bodyKit, boolean cabin, boolean superEngine)
|
||||
{
|
||||
super(speed, weight, bodyColor);
|
||||
DopColor = dopColor;
|
||||
BodyKit = bodyKit;
|
||||
Cabin = cabin;
|
||||
SuperEngine = superEngine;
|
||||
}
|
||||
}
|
@ -11,11 +11,12 @@ public class EntityWarship {
|
||||
public Color GetBodyColor (){return BodyColor;}
|
||||
|
||||
public float Step;
|
||||
public void Init(int speed, float weight, Color bodyColor)
|
||||
|
||||
public EntityWarship(int speed, float weight, Color bodyColor)
|
||||
{
|
||||
Random rnd = new Random();
|
||||
Speed = speed <= 0 ? rnd.nextInt(100) + 50 : speed;
|
||||
Weight = weight <= 0 ? rnd.nextInt(30)+40 : weight;
|
||||
Speed = speed <= 0 ? rnd.nextInt(50, 150) : speed;
|
||||
Weight = weight <= 0 ? rnd.nextInt(40, 70) : weight;
|
||||
BodyColor= bodyColor;
|
||||
Step = Speed * 100 / Weight;
|
||||
}
|
||||
|
158
src/FormMapWithSetWarships.form
Normal file
158
src/FormMapWithSetWarships.form
Normal file
@ -0,0 +1,158 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="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="20" y="20" width="884" height="479"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="ae53a" 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">
|
||||
<preferred-size width="727" height="24"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<hspacer id="815b1">
|
||||
<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">
|
||||
<preferred-size width="716" height="11"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="16c60" 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="Tools" title-justification="1" title-position="2">
|
||||
<font/>
|
||||
</border>
|
||||
<children>
|
||||
<component id="d5ebd" 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>
|
||||
<component id="9e5dd" 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="Add warship"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="16e2c" 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="Remove warship"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="1fc5b" 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="Show storage"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="3dd40" 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="Show map"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="608d7" 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>
|
||||
<component id="2ea34" class="javax.swing.JButton" binding="ButtonRight">
|
||||
<constraints>
|
||||
<grid row="10" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="daf62" class="javax.swing.JButton" binding="ButtonDown">
|
||||
<constraints>
|
||||
<grid row="10" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="76b8a" class="javax.swing.JButton" binding="ButtonLeft">
|
||||
<constraints>
|
||||
<grid row="10" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="675d4" class="javax.swing.JButton" binding="ButtonUp">
|
||||
<constraints>
|
||||
<grid row="9" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<vspacer id="aa195">
|
||||
<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>
|
||||
<vspacer id="fa6fc">
|
||||
<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="f6c4c">
|
||||
<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>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
166
src/FormMapWithSetWarships.java
Normal file
166
src/FormMapWithSetWarships.java
Normal file
@ -0,0 +1,166 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class FormMapWithSetWarships extends JFrame{
|
||||
private JPanel mainPanel;
|
||||
private JPanel PictureBox;
|
||||
private JPanel GroupBoxTools;
|
||||
private JComboBox СomboBoxSelectorMap;
|
||||
private JButton ButtonAddWarship;
|
||||
private JButton ButtonRemoveWarship;
|
||||
private JButton ButtonShowStorage;
|
||||
private JButton ButtonShowOnMap;
|
||||
private JTextField TextBoxPosition;
|
||||
private JButton ButtonRight;
|
||||
private JButton ButtonUp;
|
||||
private JButton ButtonDown;
|
||||
private JButton ButtonLeft;
|
||||
private Image bufferedImage;
|
||||
private MapWithSetWarshipsGeneric<DrawingObjectWarship, AbstractMap> _mapWarshipsCollectionGeneric;
|
||||
|
||||
public FormMapWithSetWarships(){
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paint(Graphics g) {
|
||||
super.paint(g);
|
||||
if (bufferedImage != null) {
|
||||
PictureBox.paintComponents(bufferedImage.getGraphics());
|
||||
PictureBox.getGraphics().drawImage(bufferedImage, 0, 0, null);
|
||||
}
|
||||
}
|
||||
|
||||
public void InitializeComponent(){
|
||||
setContentPane(mainPanel);
|
||||
setTitle("Warship");
|
||||
setSize(1000, 693);
|
||||
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
||||
setVisible(true);
|
||||
|
||||
Icon iconUp = new ImageIcon("src\\Images\\ArrowUp.jpg");
|
||||
ButtonUp.setIcon(iconUp);
|
||||
Icon iconDown = new ImageIcon("src\\Images\\ArrowDown.jpg");
|
||||
ButtonDown.setIcon(iconDown);
|
||||
Icon iconLeft = new ImageIcon("src\\Images\\ArrowLeft.jpg");
|
||||
ButtonLeft.setIcon(iconLeft);
|
||||
Icon iconRight = new ImageIcon("src\\Images\\ArrowRight.jpg");
|
||||
ButtonRight.setIcon(iconRight);
|
||||
|
||||
СomboBoxSelectorMap.addActionListener(e -> {
|
||||
AbstractMap map = switch (СomboBoxSelectorMap.getSelectedItem().toString()) {
|
||||
case "Простая карта" -> new SimpleMap();
|
||||
case "Преграды-линии" -> new LineMap();
|
||||
default -> null;
|
||||
};
|
||||
if( map != null){
|
||||
_mapWarshipsCollectionGeneric = new MapWithSetWarshipsGeneric<DrawingObjectWarship, AbstractMap>(
|
||||
PictureBox.getWidth(), PictureBox.getHeight(), map);
|
||||
}
|
||||
else
|
||||
{
|
||||
_mapWarshipsCollectionGeneric = null;
|
||||
}
|
||||
});
|
||||
|
||||
ButtonAddWarship.addActionListener(e -> {
|
||||
if(_mapWarshipsCollectionGeneric == null){
|
||||
return;
|
||||
}
|
||||
FormWarshipCreator warshipCreator = new FormWarshipCreator();
|
||||
warshipCreator.setSize(1200,700);
|
||||
warshipCreator.setModalityType(Dialog.ModalityType.APPLICATION_MODAL);
|
||||
warshipCreator.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
||||
warshipCreator.setVisible(true);
|
||||
if (warshipCreator.getSelectedWarship() != null) {
|
||||
DrawingObjectWarship warship = new DrawingObjectWarship(warshipCreator.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 text = TextBoxPosition.getText();
|
||||
if (text == null || _mapWarshipsCollectionGeneric == null || text.isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
int result = JOptionPane.showConfirmDialog(
|
||||
null,
|
||||
"Удалить объект?",
|
||||
"Удаление",
|
||||
JOptionPane.YES_NO_CANCEL_OPTION);
|
||||
if (result == JOptionPane.NO_OPTION)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int pos = Integer.parseInt(text);
|
||||
if (_mapWarshipsCollectionGeneric.Minus(pos) != null)
|
||||
{
|
||||
JOptionPane.showMessageDialog(this,
|
||||
"Объект удален","Успех",JOptionPane.INFORMATION_MESSAGE);
|
||||
bufferedImage = _mapWarshipsCollectionGeneric.ShowSet();
|
||||
repaint();
|
||||
}
|
||||
else
|
||||
{
|
||||
JOptionPane.showMessageDialog(this,
|
||||
"Не удалось удалить объект","Ошибка",JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
});
|
||||
|
||||
ButtonShowStorage.addActionListener(e -> {
|
||||
if(_mapWarshipsCollectionGeneric == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
bufferedImage = _mapWarshipsCollectionGeneric.ShowSet();
|
||||
repaint();
|
||||
});
|
||||
|
||||
ButtonShowOnMap.addActionListener(e -> {
|
||||
if (_mapWarshipsCollectionGeneric == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
bufferedImage = _mapWarshipsCollectionGeneric.ShowOnMap();
|
||||
repaint();
|
||||
});
|
||||
|
||||
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,41 +1,109 @@
|
||||
<?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="mainPanel" layout-manager="GridLayoutManager" row-count="4" column-count="5" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<grid id="27dc6" binding="mainPanel" layout-manager="GridLayoutManager" row-count="4" column-count="6" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<xy x="23" y="20" width="961" height="517"/>
|
||||
<xy x="49" y="20" width="935" height="482"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="80b72" class="javax.swing.JButton" binding="buttonCreate">
|
||||
<grid id="dfecd" binding="drawPanel" layout-manager="GridLayoutManager" row-count="3" column-count="7" 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="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
<grid row="0" column="0" row-span="3" col-span="6" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Create"/>
|
||||
</properties>
|
||||
</component>
|
||||
<hspacer id="3f3da">
|
||||
<constraints>
|
||||
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
<component id="32714" class="javax.swing.JButton" binding="buttonLeft">
|
||||
<constraints>
|
||||
<grid row="2" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="80b72" class="javax.swing.JButton" binding="buttonCreate">
|
||||
<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="Create"/>
|
||||
</properties>
|
||||
</component>
|
||||
<hspacer id="667bb">
|
||||
<constraints>
|
||||
<grid row="2" column="2" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
<vspacer id="e8c93">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
<component id="34645" class="javax.swing.JButton" binding="buttonCreateModif">
|
||||
<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="Modification"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="55933" class="javax.swing.JButton" binding="buttonRight">
|
||||
<constraints>
|
||||
<grid row="2" column="6" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="bb79e" class="javax.swing.JButton" binding="buttonDown">
|
||||
<constraints>
|
||||
<grid row="2" column="5" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<enabled value="true"/>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="82cc1" class="javax.swing.JButton" binding="buttonUp">
|
||||
<constraints>
|
||||
<grid row="1" column="5" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="32714" class="javax.swing.JButton" binding="buttonLeft">
|
||||
<constraints>
|
||||
<grid row="2" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="b9b11" class="javax.swing.JButton" binding="buttonSelect">
|
||||
<constraints>
|
||||
<grid row="2" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Select"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<toolbar id="3697c" binding="toolBar">
|
||||
<constraints>
|
||||
<grid row="3" column="0" row-span="1" col-span="5" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<grid row="3" column="0" row-span="1" col-span="6" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="-1" height="20"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
@ -62,51 +130,6 @@
|
||||
</component>
|
||||
</children>
|
||||
</toolbar>
|
||||
<component id="55933" class="javax.swing.JButton" binding="buttonRight">
|
||||
<constraints>
|
||||
<grid row="2" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="82cc1" class="javax.swing.JButton" binding="buttonUp">
|
||||
<constraints>
|
||||
<grid row="1" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="bb79e" class="javax.swing.JButton" binding="buttonDown">
|
||||
<constraints>
|
||||
<grid row="2" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<enabled value="true"/>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<grid id="dfecd" binding="drawPanel" layout-manager="BorderLayout" hgap="0" vgap="0">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="5" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
||||
|
@ -1,15 +1,18 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ComponentAdapter;
|
||||
import java.awt.event.ComponentEvent;
|
||||
import java.util.Random;
|
||||
|
||||
public class FormWarship extends JFrame {
|
||||
private DrawingWarship _warship;
|
||||
public DrawingComponents drawingComponents;
|
||||
public DrawingWarship selectedWarship;
|
||||
public DrawingWarship getSelectedCar(){
|
||||
return selectedWarship;
|
||||
}
|
||||
public boolean DialogResult = false;
|
||||
private JPanel mainPanel;
|
||||
private JPanel drawPanel;
|
||||
private JButton buttonCreate;
|
||||
private JButton buttonLeft;
|
||||
private JButton buttonUp;
|
||||
@ -19,19 +22,38 @@ public class FormWarship extends JFrame {
|
||||
private JLabel toolBarLabelSpeed;
|
||||
private JLabel toolBarLabelWieght;
|
||||
private JLabel toolBarLabelColor;
|
||||
private JPanel drawPanel;
|
||||
private JButton buttonCreateModif;
|
||||
private JButton buttonSelect;
|
||||
|
||||
public FormWarship(){
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void Draw(){
|
||||
drawingComponents.repaint();
|
||||
Graphics2D graphics = (Graphics2D) drawPanel.getGraphics();
|
||||
graphics.clearRect(0, 0, drawPanel.getWidth(), drawPanel.getHeight());
|
||||
drawPanel.paintComponents(graphics);
|
||||
_warship.DrawTransport(graphics);
|
||||
}
|
||||
|
||||
private void InitializeComponent(){
|
||||
private void SetData(){
|
||||
Random rnd = new Random();
|
||||
_warship.SetPosition(rnd.nextInt(10, 100), rnd.nextInt(10, 100), mainPanel.getWidth(), mainPanel.getHeight());
|
||||
toolBarLabelSpeed.setText("Color: " + _warship.GetWarship().GetSpeed() + " ");
|
||||
toolBarLabelWieght.setText("Weight: " + _warship.GetWarship().GetWeight() + " ");
|
||||
toolBarLabelColor.setText("Color: " + _warship.GetWarship().GetBodyColor().getRed() + " " +
|
||||
_warship.GetWarship().GetBodyColor().getGreen() + " " + _warship.GetWarship().GetBodyColor().getBlue());
|
||||
}
|
||||
|
||||
private void resizeWindow() {
|
||||
_warship.ChangeBorders(drawPanel.getWidth(), drawPanel.getHeight());
|
||||
Draw();
|
||||
}
|
||||
|
||||
private void InitializeComponent() {
|
||||
setContentPane(mainPanel);
|
||||
setTitle("Warship");
|
||||
setSize(900,700);
|
||||
setSize(900, 700);
|
||||
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
||||
setVisible(true);
|
||||
|
||||
@ -44,62 +66,58 @@ public class FormWarship extends JFrame {
|
||||
Icon iconRight = new ImageIcon("src\\Images\\ArrowRight.jpg");
|
||||
buttonRight.setIcon(iconRight);
|
||||
|
||||
drawingComponents = new DrawingComponents();
|
||||
drawPanel.add(drawingComponents);
|
||||
buttonCreate.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Random rnd = new Random();
|
||||
_warship = new DrawingWarship();
|
||||
_warship.Init(rnd.nextInt(200) + 100, rnd.nextInt(1000) + 1000,
|
||||
new Color(rnd.nextInt(256),rnd.nextInt(256),rnd.nextInt(256)));
|
||||
_warship.SetPosition(rnd.nextInt(90) + 10, rnd.nextInt(90) + 10, drawPanel.getWidth(), drawPanel.getHeight());
|
||||
toolBarLabelSpeed.setText("Color: " + _warship.GetWarship().GetSpeed() + " ");
|
||||
toolBarLabelWieght.setText("Weight: " + _warship.GetWarship().GetWeight() + " ");
|
||||
toolBarLabelColor.setText("Color: " + _warship.GetWarship().GetBodyColor().getRed() + " " +
|
||||
_warship.GetWarship().GetBodyColor().getGreen() + " " + _warship.GetWarship().GetBodyColor().getBlue());
|
||||
drawingComponents.SetDrawingWarship(_warship);
|
||||
Draw();
|
||||
//кнопка добавления объекта
|
||||
buttonCreate.addActionListener(e -> {
|
||||
Random rnd = new Random();
|
||||
_warship = new DrawingWarship(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000),
|
||||
new Color(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)), rnd.nextInt(3));
|
||||
SetData();
|
||||
Draw();
|
||||
});
|
||||
|
||||
//добавление модифицированного объекта
|
||||
buttonCreateModif.addActionListener(e -> {
|
||||
Random rnd = new Random();
|
||||
_warship = new DrawingAircraftCarrier(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000),
|
||||
new Color(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)),
|
||||
new Color(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)),
|
||||
rnd.nextBoolean(), rnd.nextBoolean(), rnd.nextBoolean());
|
||||
SetData();
|
||||
Draw();
|
||||
});
|
||||
|
||||
buttonSelect.addActionListener(e -> {
|
||||
if(_warship != null){
|
||||
selectedWarship =_warship;
|
||||
DialogResult = true;
|
||||
}
|
||||
});
|
||||
|
||||
buttonLeft.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if(_warship != null) _warship.MoveTransport(Direction.Left);
|
||||
Draw();
|
||||
}
|
||||
buttonLeft.addActionListener(e -> {
|
||||
if (_warship != null) _warship.MoveTransport(Direction.Left);
|
||||
Draw();
|
||||
});
|
||||
|
||||
buttonRight.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if(_warship != null) _warship.MoveTransport(Direction.Right);
|
||||
Draw();
|
||||
}
|
||||
buttonRight.addActionListener(e -> {
|
||||
if (_warship != null) _warship.MoveTransport(Direction.Right);
|
||||
Draw();
|
||||
});
|
||||
|
||||
buttonUp.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if(_warship != null) _warship.MoveTransport(Direction.Up);
|
||||
Draw();
|
||||
}
|
||||
buttonUp.addActionListener(e -> {
|
||||
if (_warship != null) _warship.MoveTransport(Direction.Up);
|
||||
Draw();
|
||||
});
|
||||
|
||||
buttonDown.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if(_warship != null) _warship.MoveTransport(Direction.Down);
|
||||
Draw();
|
||||
}
|
||||
buttonDown.addActionListener(e -> {
|
||||
if (_warship != null) _warship.MoveTransport(Direction.Down);
|
||||
Draw();
|
||||
});
|
||||
|
||||
drawPanel.addComponentListener(new ComponentAdapter() {
|
||||
mainPanel.addComponentListener(new ComponentAdapter() {
|
||||
@Override
|
||||
public void componentResized(ComponentEvent e) {
|
||||
_warship.ChangeBorders(drawPanel.getWidth(),drawPanel.getHeight());
|
||||
Draw();
|
||||
super.componentResized(e);
|
||||
resizeWindow();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
205
src/FormWarshipCreator.form
Normal file
205
src/FormWarshipCreator.form
Normal file
@ -0,0 +1,205 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormWarshipCreator">
|
||||
<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="838" height="633"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="b8cad" binding="SettingsPanel" layout-manager="GridLayoutManager" row-count="9" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<opaque value="true"/>
|
||||
</properties>
|
||||
<border type="etched" title="Settings"/>
|
||||
<children>
|
||||
<grid id="41669" binding="BlocksTypePanel" 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="6" 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="etched" title="Blocks type"/>
|
||||
<children>
|
||||
<component id="40e8a" class="javax.swing.JRadioButton" binding="RoundRectangleFormRadioButton">
|
||||
<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="Round Rectangle blocks"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="339d6" 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="Round blocks"/>
|
||||
<text value="Round blocks"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="ad164" 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="Rectangle blocks"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="15d71" 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="8" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="a819c" class="javax.swing.JButton" binding="CreateButton">
|
||||
<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="Create"/>
|
||||
<text value="Create"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="821c8" class="javax.swing.JButton" binding="SelectButton">
|
||||
<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="Select"/>
|
||||
<text value="Select"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<vspacer id="6c05e">
|
||||
<constraints>
|
||||
<grid row="7" 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="21a40" 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="4" 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="etched" title="Number of blocks"/>
|
||||
<children>
|
||||
<component id="e77e" 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="90578" 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="d9b90" 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>
|
||||
<vspacer id="f0649">
|
||||
<constraints>
|
||||
<grid row="1" 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>
|
||||
<vspacer id="18811">
|
||||
<constraints>
|
||||
<grid row="3" 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>
|
||||
<vspacer id="1084d">
|
||||
<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="7b5d7" binding="TypePanel" 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="etched" title="Type"/>
|
||||
<children>
|
||||
<component id="b0d54" class="javax.swing.JComboBox" binding="comboBoxType">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<model>
|
||||
<item value="Warship"/>
|
||||
<item value="AircraftCarrier"/>
|
||||
</model>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="5220b" binding="ModificationPanel" 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="2" 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="etched" title="Modification"/>
|
||||
<children>
|
||||
<component id="c96ee" class="javax.swing.JCheckBox" binding="EngineCheckBox">
|
||||
<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="Super engine"/>
|
||||
<text value="Super engine"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="385c6" class="javax.swing.JCheckBox" binding="CabinCheckBox">
|
||||
<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="Cabin"/>
|
||||
<text value="Cabin"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="63fa9" class="javax.swing.JCheckBox" binding="AreaCheckBox">
|
||||
<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="Landing area"/>
|
||||
<text value="Landing area"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
<hspacer id="2bb5c">
|
||||
<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>
|
||||
</form>
|
140
src/FormWarshipCreator.java
Normal file
140
src/FormWarshipCreator.java
Normal file
@ -0,0 +1,140 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.Random;
|
||||
|
||||
public class FormWarshipCreator extends JDialog{
|
||||
private JPanel PictureBox;
|
||||
private JPanel SettingsPanel;
|
||||
private JPanel BlocksTypePanel;
|
||||
private JPanel CountOfBlocksPanel;
|
||||
private JPanel ModificationPanel;
|
||||
private JPanel TypePanel;
|
||||
private JRadioButton RoundRectangleFormRadioButton;
|
||||
private JRadioButton RoundFormRadioButton;
|
||||
private JRadioButton RectangleFormRadioButton;
|
||||
private JRadioButton SixRadioButton;
|
||||
private JRadioButton FourRadioButton;
|
||||
private JRadioButton TwoRadioButton;
|
||||
private JButton CreateButton;
|
||||
private JButton SelectButton;
|
||||
private JCheckBox EngineCheckBox;
|
||||
private JCheckBox CabinCheckBox;
|
||||
private JCheckBox AreaCheckBox;
|
||||
private JComboBox comboBoxType;
|
||||
private BlockCount _block = null;
|
||||
private IDrawingObjectBlock objectBlock = null;
|
||||
private final WarshipCreatorGeneric<EntityWarship,IDrawingObjectBlock> warshipCreator =new WarshipCreatorGeneric<>(40,40);
|
||||
private DrawingWarship _warship;
|
||||
private DrawingWarship selectedWarship;
|
||||
private boolean isModified = false;
|
||||
|
||||
public FormWarshipCreator(){
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paint(Graphics g) {
|
||||
super.paint(g);
|
||||
Graphics2D g2d = (Graphics2D) PictureBox.getGraphics();
|
||||
if (_warship != null) {
|
||||
_warship.DrawTransport(g2d);
|
||||
}
|
||||
}
|
||||
|
||||
public DrawingWarship getSelectedWarship() {
|
||||
return selectedWarship;
|
||||
}
|
||||
|
||||
private void InitializeComponent(){
|
||||
setContentPane(PictureBox);
|
||||
setTitle("Warship");
|
||||
setResizable(false);
|
||||
setSize(1000, 600);
|
||||
|
||||
//Определение типа объекта
|
||||
comboBoxType.addItemListener(e -> isModified = e.getItem().toString().equals("AircraftCarrier"));
|
||||
|
||||
//количество блоков
|
||||
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;
|
||||
|
||||
objectBlock = new DrawingBlocks(_block);
|
||||
objectBlock.SetBlockCount(_block.GetBlockCount());
|
||||
warshipCreator.AddBlock(objectBlock);
|
||||
});
|
||||
|
||||
//Круглая форма блоков
|
||||
RoundFormRadioButton.addActionListener(e -> {
|
||||
if(_block ==null){
|
||||
return;
|
||||
}
|
||||
objectBlock = new DrawingRoundBlocks(_block);
|
||||
objectBlock.SetBlockCount(_block.GetBlockCount());
|
||||
warshipCreator.AddBlock(objectBlock);
|
||||
});
|
||||
|
||||
//Закруглено-квадратная форма блоков
|
||||
RoundRectangleFormRadioButton.addActionListener(e -> {
|
||||
if(_block == null){
|
||||
return;
|
||||
}
|
||||
objectBlock = new DrawingRoundBlocks(_block);
|
||||
objectBlock.SetBlockCount(_block.GetBlockCount());
|
||||
warshipCreator.AddBlock(objectBlock);
|
||||
});
|
||||
|
||||
CreateButton.addActionListener(e -> {
|
||||
Random rnd = new Random();
|
||||
if (_block != null && objectBlock != null) {
|
||||
Color color = JColorChooser.showDialog(this, "Choose color", Color.WHITE);
|
||||
|
||||
if (isModified) {
|
||||
Color additionalColor = JColorChooser.showDialog(this, "Choose color", Color.GRAY);
|
||||
|
||||
warshipCreator.AddWarship(
|
||||
new EntityAircraftCarrier(
|
||||
rnd.nextInt(10, 300),
|
||||
rnd.nextFloat(10, 3000),
|
||||
color,
|
||||
additionalColor,
|
||||
AreaCheckBox.isSelected(),
|
||||
CabinCheckBox.isSelected(),
|
||||
EngineCheckBox.isSelected()
|
||||
)
|
||||
);
|
||||
}
|
||||
else {
|
||||
warshipCreator.AddWarship(
|
||||
new EntityWarship(
|
||||
rnd.nextInt(10, 300),
|
||||
rnd.nextFloat(10, 3000),
|
||||
color)
|
||||
);
|
||||
}
|
||||
|
||||
_warship = warshipCreator.NewWarshipCreating();
|
||||
_warship.SetPosition(
|
||||
rnd.nextInt(20),
|
||||
rnd.nextInt(20),
|
||||
PictureBox.getWidth(),
|
||||
PictureBox.getHeight());
|
||||
repaint();
|
||||
}
|
||||
});
|
||||
SelectButton.addActionListener(e -> {
|
||||
selectedWarship = _warship;
|
||||
dispose();
|
||||
});
|
||||
}
|
||||
}
|
15
src/IDrawingObject.java
Normal file
15
src/IDrawingObject.java
Normal file
@ -0,0 +1,15 @@
|
||||
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);
|
||||
// Получение текущей позиции объекта
|
||||
// /Left, Right, Top, Bottom)
|
||||
float[] GetCurrentPosition();
|
||||
}
|
6
src/IDrawingObjectBlock.java
Normal file
6
src/IDrawingObjectBlock.java
Normal file
@ -0,0 +1,6 @@
|
||||
import java.awt.*;
|
||||
|
||||
public interface IDrawingObjectBlock {
|
||||
void SetBlockCount(int count);
|
||||
void DrawBlocks(Graphics2D g, int _startPosX, int _startPosY);
|
||||
}
|
53
src/LineMap.java
Normal file
53
src/LineMap.java
Normal file
@ -0,0 +1,53 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class LineMap extends AbstractMap{
|
||||
@Override
|
||||
protected void DrawBarrierPart(Graphics g, int i, int j)
|
||||
{
|
||||
Graphics2D g2 = (Graphics2D) g;
|
||||
g2.setColor(Color.gray);
|
||||
g2.fillRect((int) (i * _size_x), (int) (j * _size_y), (int) (i * (_size_x + 1)), (int) (j * (_size_y + 1)));
|
||||
}
|
||||
@Override
|
||||
protected void DrawRoadPart(Graphics g, int i, int j)
|
||||
{
|
||||
Graphics2D g2 = (Graphics2D) g;
|
||||
g2.setColor(Color.BLUE);
|
||||
g2.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] = _freeRoad;
|
||||
}
|
||||
}
|
||||
boolean flag = true;
|
||||
while (counter < 20)
|
||||
{
|
||||
int lineX = _random.nextInt(11, 89);
|
||||
int lineY = _random.nextInt(11, 89);
|
||||
|
||||
if (flag)
|
||||
{
|
||||
for (int i = lineY; i <= lineY + 10; i++)
|
||||
_map[lineX][i] = _barrier;
|
||||
flag = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = lineX; i <= lineX + 10; i++)
|
||||
_map[i][lineY] = _barrier;
|
||||
flag = true;
|
||||
}
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
new FormWarship();
|
||||
new FormMapWithSetWarships();
|
||||
}
|
||||
|
||||
}
|
||||
|
123
src/MapWithSetWarshipsGeneric.java
Normal file
123
src/MapWithSetWarshipsGeneric.java
Normal file
@ -0,0 +1,123 @@
|
||||
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> _setWarships;
|
||||
private final U _map;
|
||||
|
||||
public MapWithSetWarshipsGeneric(int picWidth, int picHeight, U map)
|
||||
{
|
||||
int width = picWidth / _placeSizeWidth;
|
||||
int height = picHeight/_placeSizeHeight;
|
||||
_setWarships = new SetWarshipsGeneric<T>(width * height);
|
||||
_pictureWidth = picWidth;
|
||||
_pictureHeight = picHeight;
|
||||
_map = map;
|
||||
}
|
||||
|
||||
public int Plus(T warship)
|
||||
{
|
||||
return _setWarships.Insert(warship);
|
||||
}
|
||||
|
||||
public T Minus(int position)
|
||||
{
|
||||
return _setWarships.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 < _setWarships.getCount(); i++)
|
||||
{
|
||||
T warship = _setWarships.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 = _setWarships.getCount() - 1;
|
||||
for (int i = 0; i < _setWarships.getCount(); i++)
|
||||
{
|
||||
if (_setWarships.Get(i) == null)
|
||||
{
|
||||
for (; j > i; j--)
|
||||
{
|
||||
var warship = _setWarships.Get(j);
|
||||
if (warship != null)
|
||||
{
|
||||
_setWarships.Insert(warship, i);
|
||||
_setWarships.Remove(j);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (j <= i)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawBackground(Graphics gr)
|
||||
{
|
||||
Graphics2D g = (Graphics2D)gr;
|
||||
|
||||
Color brush=Color.BLACK;
|
||||
Stroke penWide = new BasicStroke(3);
|
||||
|
||||
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
|
||||
{
|
||||
for (int j = 0; j <= _pictureHeight / _placeSizeHeight ; ++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 + (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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawWarship(Graphics gr)
|
||||
{
|
||||
int width = _pictureWidth / _placeSizeWidth;
|
||||
int height = _pictureHeight / _placeSizeHeight;
|
||||
|
||||
for (int i = 0; i < _setWarships.getCount(); i++)
|
||||
{
|
||||
if (_setWarships.Get(i) != null)
|
||||
{
|
||||
_setWarships.Get(i).SetObject(i % width * _placeSizeWidth, ((height - 1 - i / width) * _placeSizeHeight) + 6, _pictureWidth, _pictureHeight);
|
||||
_setWarships.Get(i).DrawingObject(gr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
57
src/SetWarshipsGeneric.java
Normal file
57
src/SetWarshipsGeneric.java
Normal file
@ -0,0 +1,57 @@
|
||||
public class SetWarshipsGeneric<T extends Object>{
|
||||
private final Object[] _places;
|
||||
|
||||
public int getCount() {
|
||||
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)
|
||||
{
|
||||
if (position < 0 || position >= getCount())
|
||||
return -1;
|
||||
|
||||
int empty = -1;
|
||||
for (int i = position + 1; i < getCount(); i++)
|
||||
{
|
||||
if (_places[i] == null)
|
||||
empty = i;
|
||||
}
|
||||
if (empty == -1)
|
||||
return 0;
|
||||
else
|
||||
{
|
||||
for (int i = empty; i > position; i--)
|
||||
_places[i] = _places[i - 1];
|
||||
}
|
||||
_places[position] = warship;
|
||||
return 1;
|
||||
}
|
||||
|
||||
public T Remove(int position)
|
||||
{
|
||||
if (position >= getCount() || position < 0 || _places[position] == null)
|
||||
return null;
|
||||
|
||||
T deleted =(T) _places[position];
|
||||
_places[position] = null;
|
||||
return deleted;
|
||||
}
|
||||
|
||||
public T Get(int position)
|
||||
{
|
||||
if (position >= getCount() || position < 0)
|
||||
return null;
|
||||
|
||||
return (T) _places[position];
|
||||
}
|
||||
}
|
43
src/SimpleMap.java
Normal file
43
src/SimpleMap.java
Normal file
@ -0,0 +1,43 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class SimpleMap extends AbstractMap{
|
||||
@Override
|
||||
protected void DrawBarrierPart(Graphics g, int i, int j)
|
||||
{
|
||||
Graphics2D g2 = (Graphics2D) g;
|
||||
g2.setColor(Color.gray);
|
||||
g2.fillRect((int) (i * _size_x), (int) (j * _size_y), (int) (i * (_size_x + 1)), (int) (j * (_size_y + 1)));
|
||||
}
|
||||
@Override
|
||||
protected void DrawRoadPart(Graphics g, int i, int j)
|
||||
{
|
||||
Graphics2D g2 = (Graphics2D) g;
|
||||
g2.setColor(Color.BLUE);
|
||||
g2.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] = _freeRoad;
|
||||
}
|
||||
}
|
||||
while (counter < 50)
|
||||
{
|
||||
int x = _random.nextInt(0, 100);
|
||||
int y = _random.nextInt(0, 100);
|
||||
if (_map[x][y] == _freeRoad)
|
||||
{
|
||||
_map[x][y] = _barrier;
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
43
src/WarshipCreatorGeneric.java
Normal file
43
src/WarshipCreatorGeneric.java
Normal file
@ -0,0 +1,43 @@
|
||||
import java.util.ArrayList;
|
||||
import java.util.Random;
|
||||
|
||||
public class WarshipCreatorGeneric <T extends EntityWarship, U extends IDrawingObjectBlock>{
|
||||
private final ArrayList<T> Warships;
|
||||
private final ArrayList<U> Blocks;
|
||||
private int WarshipsCount = 0;
|
||||
private int BlocksCount = 0;
|
||||
public WarshipCreatorGeneric(int warshipsCount, int blocksCount){
|
||||
Warships = new ArrayList<>(warshipsCount);
|
||||
Blocks = new ArrayList<>(blocksCount);
|
||||
}
|
||||
|
||||
public int AddWarship(T warship){
|
||||
if(WarshipsCount <= Warships.size()){
|
||||
Warships.add(warship);
|
||||
WarshipsCount++;
|
||||
return WarshipsCount - 1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public int AddBlock(U block){
|
||||
if(BlocksCount <= Blocks.size()){
|
||||
Blocks.add(block);
|
||||
BlocksCount++;
|
||||
return BlocksCount - 1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public DrawingWarship NewWarshipCreating()
|
||||
{
|
||||
Random rand=new Random();
|
||||
T warship = (T)Warships.get(rand.nextInt(WarshipsCount));
|
||||
U block = (U)Blocks.get(rand.nextInt(BlocksCount));
|
||||
|
||||
if(warship instanceof EntityAircraftCarrier){
|
||||
return new DrawingAircraftCarrier(warship, block);
|
||||
}
|
||||
return new DrawingWarship(warship,block);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user