Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 30827fcb0d | |||
| ba0c2ab3b3 | |||
| 3dceb64956 | |||
| 6f45c485ee | |||
| 165855ed4b |
129
src/AbstractMap.java
Normal file
129
src/AbstractMap.java
Normal file
@@ -0,0 +1,129 @@
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.Random;
|
||||
public abstract class AbstractMap {
|
||||
private IDrawingObject _drawningObject = null;
|
||||
protected int[][] _map = null;
|
||||
protected int _width;
|
||||
protected int _height;
|
||||
protected float[] position;
|
||||
protected float _size_x;
|
||||
protected float _size_y;
|
||||
protected Random _random = new Random();
|
||||
protected int _freeRoad = 0;
|
||||
protected int _barrier = 1;
|
||||
public BufferedImage CreateMap(int width, int height, IDrawingObject drawningObject)
|
||||
{
|
||||
_width = width;
|
||||
_height = height;
|
||||
_drawningObject = drawningObject;
|
||||
GenerateMap();
|
||||
while (!SetObjectOnMap())
|
||||
{
|
||||
GenerateMap();
|
||||
}
|
||||
return DrawMapWithObject();
|
||||
}
|
||||
public BufferedImage MoveObject(Direction direction)
|
||||
{
|
||||
position = _drawningObject.GetCurrentPosition();
|
||||
for (int i = 0; i < _map.length; ++i)
|
||||
{
|
||||
for (int j = 0; j < _map[i].length; ++j)
|
||||
{
|
||||
if (_map[i][j] == _barrier)
|
||||
{
|
||||
switch (direction)
|
||||
{
|
||||
case Up:
|
||||
if(_size_y * (j+1) >= position[0] - _drawningObject.Step() && _size_y * (j+1) < position[0] && _size_x * (i + 1) > position[3]
|
||||
&& _size_x * (i + 1) <= position[1])
|
||||
{
|
||||
return DrawMapWithObject();
|
||||
}
|
||||
break;
|
||||
case Down:
|
||||
if (_size_y * j <= position[2] + _drawningObject.Step() && _size_y * j > position[2] && _size_x * (i+1) > position[3]
|
||||
&& _size_x * (i+1) <= position[1])
|
||||
{
|
||||
return DrawMapWithObject();
|
||||
}
|
||||
break;
|
||||
case Left:
|
||||
if (_size_x * (i+1) >= position[3] - _drawningObject.Step() && _size_x * (i + 1) < position[3] && _size_y * (j + 1) < position[2]
|
||||
&& _size_y * (j + 1) >= position[0])
|
||||
{
|
||||
return DrawMapWithObject();
|
||||
}
|
||||
break;
|
||||
case Right:
|
||||
if (_size_x * i <= position[1] + _drawningObject.Step() && _size_x * i > position[3] && _size_y * (j + 1) < position[2]
|
||||
&& _size_y * (j + 1) >= position[0])
|
||||
{
|
||||
return DrawMapWithObject();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
_drawningObject.MoveObject(direction);
|
||||
return DrawMapWithObject();
|
||||
}
|
||||
private boolean SetObjectOnMap()
|
||||
{
|
||||
if (_drawningObject == null || _map == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
int x = _random.nextInt( 10);
|
||||
int y = _random.nextInt( 10);
|
||||
_drawningObject.SetObject(x, y, _width, _height);
|
||||
|
||||
for (int i = 0; i < _map.length; ++i)
|
||||
{
|
||||
for (int j = 0; j < _map[0].length; ++j)
|
||||
{
|
||||
if (i * _size_x >= x && j * _size_y >= y &&
|
||||
i * _size_x <= x + _drawningObject.GetCurrentPosition()[1] &&
|
||||
j * _size_y <= j + _drawningObject.GetCurrentPosition()[2])
|
||||
{
|
||||
if (_map[i][j] == _barrier)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
private BufferedImage DrawMapWithObject()
|
||||
{
|
||||
BufferedImage bmp = new BufferedImage(_width, _height, BufferedImage.TYPE_INT_RGB);
|
||||
if (_drawningObject == 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] == _freeRoad)
|
||||
{
|
||||
DrawRoadPart(gr, i, j);
|
||||
}
|
||||
else if (_map[i][j] == _barrier)
|
||||
{
|
||||
DrawBarrierPart(gr, i, j);
|
||||
}
|
||||
}
|
||||
}
|
||||
_drawningObject.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);
|
||||
}
|
||||
@@ -1,40 +1,43 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
public class DrawingDeck extends JComponent {
|
||||
public class DrawingDeck extends JComponent implements IAdditionalDrawingObject{
|
||||
private Additional_Enum _decksEnum;
|
||||
public void SetAddEnum(Additional_Enum addEnum) {
|
||||
_decksEnum = addEnum;
|
||||
@Override
|
||||
public void SetAddEnum(int decksAmount) {
|
||||
for(Additional_Enum item : _decksEnum.values())
|
||||
{
|
||||
if(item.GetAddEnum()==decksAmount)
|
||||
{
|
||||
_decksEnum=item;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void DrawDeck(Color colorDeck, Graphics g,float _startPosX,float _startPosY)
|
||||
{
|
||||
super.paintComponent(g);
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
switch (_decksEnum.GetAddEnum())
|
||||
if(_decksEnum.GetAddEnum()>=1)
|
||||
{
|
||||
case 1:
|
||||
g2d.setPaint(colorDeck);
|
||||
g2d.fillRect((int)_startPosX+40, (int)_startPosY+15, 30*2, 5);
|
||||
g2d.setPaint(Color.BLACK);
|
||||
g2d.drawRect((int)_startPosX+40, (int)_startPosY+15, 30*2, 5);
|
||||
break;
|
||||
case 2:
|
||||
g2d.setPaint(colorDeck);
|
||||
g2d.fillRect((int)_startPosX+40, (int)_startPosY+15, 70, 5);
|
||||
g2d.fillRect((int)_startPosX+50, (int)_startPosY+10, 60, 5);
|
||||
g2d.setPaint(Color.BLACK);
|
||||
g2d.drawRect((int)_startPosX+40, (int)_startPosY+15, 70, 5);
|
||||
g2d.drawRect((int)_startPosX+50, (int)_startPosY+10, 60, 5);
|
||||
break;
|
||||
case 3:
|
||||
g2d.setPaint(colorDeck);
|
||||
g2d.fillRect((int)_startPosX+40, (int)_startPosY+15, 70, 5);
|
||||
g2d.fillRect((int)_startPosX+50, (int)_startPosY+10, 60, 5);
|
||||
g2d.fillRect((int)_startPosX+60, (int)_startPosY+5, 50, 5);
|
||||
g2d.setPaint(Color.BLACK);
|
||||
g2d.drawRect((int)_startPosX+40, (int)_startPosY+15, 70, 5);
|
||||
g2d.drawRect((int)_startPosX+50, (int)_startPosY+10, 60, 5);
|
||||
g2d.drawRect((int)_startPosX+60, (int)_startPosY+5, 50, 5);
|
||||
break;
|
||||
g2d.setPaint(colorDeck);
|
||||
g2d.fillRect((int)_startPosX+40, (int)_startPosY+15, 70, 5);
|
||||
g2d.setPaint(Color.BLACK);
|
||||
g2d.drawRect((int)_startPosX+40, (int)_startPosY+15, 70, 5);
|
||||
}
|
||||
if(_decksEnum.GetAddEnum()>=2)
|
||||
{
|
||||
g2d.setPaint(colorDeck);
|
||||
g2d.fillRect((int)_startPosX+50, (int)_startPosY+10, 60, 5);
|
||||
g2d.setPaint(Color.BLACK);
|
||||
g2d.drawRect((int)_startPosX+50, (int)_startPosY+10, 60, 5);
|
||||
}
|
||||
if(_decksEnum.GetAddEnum()>=3)
|
||||
{
|
||||
g2d.setPaint(colorDeck);
|
||||
g2d.fillRect((int)_startPosX+60, (int)_startPosY+5, 50, 5);
|
||||
g2d.setPaint(Color.BLACK);
|
||||
g2d.drawRect((int)_startPosX+60, (int)_startPosY+5, 50, 5);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
42
src/DrawingLiner.java
Normal file
42
src/DrawingLiner.java
Normal file
@@ -0,0 +1,42 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawingLiner extends DrawingShip
|
||||
{
|
||||
public DrawingLiner(int speed, float weight, Color bodyColor,Color dopColor,boolean dopDeck,boolean pool)
|
||||
{
|
||||
super(speed,weight,bodyColor,130,45);
|
||||
Ship = new EntityLiner(speed, weight, bodyColor, dopColor, dopDeck, pool);
|
||||
}
|
||||
@Override
|
||||
public void DrawTransport(Graphics gr) {
|
||||
Graphics2D g2d = (Graphics2D) gr;
|
||||
EntityLiner liner;
|
||||
if (!(GetShip() instanceof EntityLiner))
|
||||
{
|
||||
return;
|
||||
}
|
||||
liner= (EntityLiner) Ship;
|
||||
_startPosX+=10;
|
||||
_startPosY+=5;
|
||||
super.DrawTransport(gr);
|
||||
_startPosY -= 5;
|
||||
_startPosX -= 10;
|
||||
if(liner.Pool)
|
||||
{
|
||||
g2d.setPaint(liner.DopColor);
|
||||
g2d.fillRect((int)_startPosX + 15, (int)_startPosY + 25, 30, 3);
|
||||
g2d.setPaint(Color.BLACK);
|
||||
g2d.setPaint(Color.BLACK);
|
||||
g2d.drawRect((int)_startPosX + 15, (int)_startPosY + 25, 30, 3);
|
||||
gr.drawLine((int)_startPosX + 45, (int)_startPosY + 25, (int)_startPosX + 45, (int)_startPosY + 20);
|
||||
gr.drawLine((int)_startPosX + 45, (int)_startPosY + 20, (int)_startPosX + 35, (int)_startPosY + 20);
|
||||
}
|
||||
if(liner.DopDeck)
|
||||
{
|
||||
g2d.setPaint(liner.DopColor);
|
||||
g2d.fillRect((int)_startPosX + 50, (int)_startPosY + 15, 60, 5);
|
||||
g2d.setPaint(Color.BLACK);
|
||||
g2d.drawRect((int)_startPosX + 50, (int)_startPosY + 15, 60, 5);
|
||||
}
|
||||
}
|
||||
}
|
||||
35
src/DrawingObjectShip.java
Normal file
35
src/DrawingObjectShip.java
Normal file
@@ -0,0 +1,35 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawingObjectShip implements IDrawingObject {
|
||||
private DrawingShip _ship = null;
|
||||
public DrawingObjectShip(DrawingShip ship)
|
||||
{
|
||||
_ship=ship;
|
||||
}
|
||||
@Override
|
||||
public float Step() {
|
||||
if (_ship!=null && _ship.Ship != null) {
|
||||
return _ship.Ship.Step();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@Override
|
||||
public void SetObject(int x, int y, int width, int height) {
|
||||
_ship.SetPosition(x,y,width,height);
|
||||
}
|
||||
@Override
|
||||
public void MoveObject(Direction direction) {
|
||||
_ship.MoveTransport(direction);
|
||||
}
|
||||
@Override
|
||||
public void DrawingObject(Graphics g) {
|
||||
_ship.DrawTransport(g);
|
||||
}
|
||||
@Override
|
||||
public float[] GetCurrentPosition() {
|
||||
if(_ship!=null)
|
||||
return _ship.GetCurrentPosition();
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
44
src/DrawingOvalDeck.java
Normal file
44
src/DrawingOvalDeck.java
Normal file
@@ -0,0 +1,44 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawingOvalDeck extends JComponent implements IAdditionalDrawingObject{
|
||||
private Additional_Enum _decksEnum;
|
||||
@Override
|
||||
public void SetAddEnum(int decksAmount) {
|
||||
for(Additional_Enum item : _decksEnum.values())
|
||||
{
|
||||
if(item.GetAddEnum()==decksAmount)
|
||||
{
|
||||
_decksEnum=item;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void DrawDeck(Color colorDeck, Graphics g, float _startPosX, float _startPosY)
|
||||
{
|
||||
super.paintComponent(g);
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
if(_decksEnum.GetAddEnum()>=1)
|
||||
{
|
||||
g2d.setPaint(colorDeck);
|
||||
g2d.fillOval((int)_startPosX+40, (int)_startPosY+15, 70, 5);
|
||||
g2d.setPaint(Color.BLACK);
|
||||
g2d.drawOval((int)_startPosX+40, (int)_startPosY+15, 70, 5);
|
||||
}
|
||||
if(_decksEnum.GetAddEnum()>=2)
|
||||
{
|
||||
g2d.setPaint(colorDeck);
|
||||
g2d.fillOval((int)_startPosX+50, (int)_startPosY+10, 60, 5);
|
||||
g2d.setPaint(Color.BLACK);
|
||||
g2d.drawOval((int)_startPosX+50, (int)_startPosY+10, 60, 5);
|
||||
}
|
||||
if(_decksEnum.GetAddEnum()>=3)
|
||||
{
|
||||
g2d.setPaint(colorDeck);
|
||||
g2d.fillOval((int)_startPosX+60, (int)_startPosY+5, 50, 5);
|
||||
g2d.setPaint(Color.BLACK);
|
||||
g2d.drawOval((int)_startPosX+60, (int)_startPosY+5, 50, 5);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,36 +2,47 @@ import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.Random;
|
||||
public class DrawingShip extends JPanel {
|
||||
private EntityShip Ship;
|
||||
public DrawingDeck Deck;
|
||||
protected EntityShip Ship;
|
||||
public IAdditionalDrawingObject Deck;
|
||||
public void SetEnum() {
|
||||
Random r = new Random();
|
||||
int numbEnum = r.nextInt(1, 4);
|
||||
Deck.SetAddEnum(numbEnum);
|
||||
}
|
||||
public void SetFormEnum()
|
||||
{
|
||||
Random r = new Random();
|
||||
int numbEnum = r.nextInt(1, 4);
|
||||
if (numbEnum == 1) {
|
||||
Deck.SetAddEnum(Additional_Enum.One);
|
||||
Deck=new DrawingDeck();
|
||||
}
|
||||
if (numbEnum == 2) {
|
||||
Deck.SetAddEnum(Additional_Enum.Two);
|
||||
Deck = new DrawingOvalDeck();
|
||||
}
|
||||
if (numbEnum == 3) {
|
||||
Deck.SetAddEnum(Additional_Enum.Three);
|
||||
Deck=new DrawingTriangleDeck();
|
||||
}
|
||||
}
|
||||
public EntityShip GetShip() {
|
||||
return Ship;
|
||||
}
|
||||
private float _startPosX;
|
||||
private float _startPosY;
|
||||
protected float _startPosX;
|
||||
protected float _startPosY;
|
||||
private Integer _pictureWidth = null;
|
||||
private Integer _pictureHeight = null;
|
||||
protected final int _ShipWidth = 120;
|
||||
protected final int _ShipHeight = 40;
|
||||
public void Init(int speed, float weight, Color bodycolor) {
|
||||
Ship = new EntityShip();
|
||||
Ship.Init(speed, weight, bodycolor);
|
||||
Deck = new DrawingDeck();
|
||||
private int _ShipWidth = 120;
|
||||
private int _ShipHeight = 40;
|
||||
public DrawingShip(int speed, float weight, Color bodycolor) {
|
||||
Ship = new EntityShip(speed, weight, bodycolor);
|
||||
SetFormEnum();
|
||||
SetEnum();
|
||||
}
|
||||
public DrawingShip(int speed,float weight,Color bodyColor,int shipWidth,int shipHeight)
|
||||
{
|
||||
this(speed,weight,bodyColor);
|
||||
_ShipWidth = shipWidth;
|
||||
_ShipHeight = shipHeight;
|
||||
}
|
||||
public void SetPosition(int x, int y, int width, int height) {
|
||||
if (width <= _ShipWidth + x || height <= _ShipHeight + y || x < 0 || y < 0) {
|
||||
_pictureWidth = null;
|
||||
@@ -70,29 +81,21 @@ public class DrawingShip extends JPanel {
|
||||
break;
|
||||
}
|
||||
}
|
||||
public void DrawTransport() {
|
||||
if (_startPosX < 0 || _startPosY < 0 || _pictureWidth == null || _pictureHeight == null) {
|
||||
return;
|
||||
}
|
||||
repaint();
|
||||
}
|
||||
@Override
|
||||
public void paintComponent(Graphics g) {
|
||||
public void DrawTransport(Graphics gr) {
|
||||
Graphics2D g2d = (Graphics2D) gr;
|
||||
if (GetShip() == null) {
|
||||
return;
|
||||
}
|
||||
if (_startPosX < 0 || _startPosY < 0 || _pictureWidth == null || _pictureHeight == null) {
|
||||
return;
|
||||
}
|
||||
super.paintComponent(g);
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
g2d.setPaint(Ship.GetBodyColor());
|
||||
int xValues[]={(int) _startPosX,(int) _startPosX + 60 * 2,(int) _startPosX + 100,(int) _startPosX + 20};
|
||||
int yValues[]={(int) _startPosY + 20,(int) _startPosY + 20,(int) _startPosY + 20 * 2,(int) _startPosY + 40};
|
||||
g2d.fillPolygon(xValues,yValues,4);
|
||||
g2d.setPaint(Color.BLACK);
|
||||
g2d.drawPolygon(xValues,yValues,4);
|
||||
Deck.DrawDeck(Ship.GetBodyColor(), g, _startPosX, _startPosY);
|
||||
Deck.DrawDeck(Ship.GetBodyColor(), gr, _startPosX, _startPosY);
|
||||
}
|
||||
public void ChangeBorders(int width, int height) {
|
||||
_pictureWidth = width;
|
||||
@@ -109,4 +112,8 @@ public class DrawingShip extends JPanel {
|
||||
_startPosY = _pictureHeight - _ShipHeight;
|
||||
}
|
||||
}
|
||||
public float[] GetCurrentPosition()
|
||||
{
|
||||
return new float[] {/*UP*/_startPosY, /*RIGHT*/ _startPosX + _ShipWidth, /*DOWN*/ _startPosY + _ShipHeight, /*LEFT*/ _startPosX};
|
||||
}
|
||||
}
|
||||
49
src/DrawingTriangleDeck.java
Normal file
49
src/DrawingTriangleDeck.java
Normal file
@@ -0,0 +1,49 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
public class DrawingTriangleDeck extends JComponent implements IAdditionalDrawingObject{
|
||||
private Additional_Enum _decksEnum;
|
||||
@Override
|
||||
public void SetAddEnum(int decksAmount) {
|
||||
for(Additional_Enum item : _decksEnum.values())
|
||||
{
|
||||
if(item.GetAddEnum()==decksAmount)
|
||||
{
|
||||
_decksEnum=item;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void DrawDeck(Color colorDeck, Graphics g,float _startPosX,float _startPosY)
|
||||
{
|
||||
super.paintComponent(g);
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
if(_decksEnum.GetAddEnum()>=1)
|
||||
{
|
||||
g2d.setPaint(colorDeck);
|
||||
int[] xValues={(int)_startPosX+40,(int)_startPosX+40+15,(int)_startPosX+40+45,(int)_startPosX+40+60};
|
||||
int[] yValues={(int)_startPosY+15,(int)_startPosY+20,(int)_startPosY+20,(int)_startPosY+15};
|
||||
g2d.fillPolygon(xValues,yValues,4);
|
||||
g2d.setPaint(Color.BLACK);
|
||||
g2d.drawPolygon(xValues,yValues,4);
|
||||
}
|
||||
if(_decksEnum.GetAddEnum()>=2)
|
||||
{
|
||||
g2d.setPaint(colorDeck);
|
||||
int[] xValues2={(int)_startPosX+50,(int)_startPosX+50+15,(int)_startPosX+50+45,(int)_startPosX+50+60};
|
||||
int[] yValues2={(int)_startPosY+10,(int)_startPosY+15,(int)_startPosY+15,(int)_startPosY+10};
|
||||
g2d.fillPolygon(xValues2,yValues2,4);
|
||||
g2d.setPaint(Color.BLACK);
|
||||
g2d.drawPolygon(xValues2,yValues2,4);
|
||||
}
|
||||
if(_decksEnum.GetAddEnum()>=3)
|
||||
{
|
||||
g2d.setPaint(colorDeck);
|
||||
int[] xValues3_3={(int)_startPosX+50,(int)_startPosX+50+15,(int)_startPosX+50+45,(int)_startPosX+50+60};
|
||||
int[] yValues3_3={(int)_startPosY+5,(int)_startPosY+10,(int)_startPosY+10,(int)_startPosY+5};
|
||||
g2d.fillPolygon(xValues3_3,yValues3_3,4);
|
||||
g2d.setPaint(Color.BLACK);
|
||||
g2d.drawPolygon(xValues3_3,yValues3_3,4);
|
||||
}
|
||||
}
|
||||
}
|
||||
15
src/EntityLiner.java
Normal file
15
src/EntityLiner.java
Normal file
@@ -0,0 +1,15 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class EntityLiner extends EntityShip {
|
||||
public Color DopColor;
|
||||
public boolean DopDeck;
|
||||
public boolean Pool;
|
||||
public EntityLiner(int speed, float weight, Color bodyColor, Color dopColor, boolean dopDeck, boolean pool)
|
||||
{
|
||||
super(speed,weight,bodyColor);
|
||||
DopColor = dopColor;
|
||||
DopDeck = dopDeck;
|
||||
Pool = pool;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,7 +16,7 @@ public class EntityShip {
|
||||
{
|
||||
return Speed*100/Weight;
|
||||
}
|
||||
public void Init(int speed,float weight, Color bodyColor)
|
||||
public EntityShip(int speed,float weight, Color bodyColor)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight=weight;
|
||||
|
||||
118
src/FormMap.form
Normal file
118
src/FormMap.form
Normal file
@@ -0,0 +1,118 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormMap">
|
||||
<grid id="27dc6" binding="MainPanel" layout-manager="GridLayoutManager" row-count="4" column-count="6" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<xy x="20" y="20" width="500" height="400"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="4c171" binding="pictureBoxShip" layout-manager="BorderLayout" hgap="0" vgap="0">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="6" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<toolbar id="7b4c1" binding="StatusStrip">
|
||||
<constraints>
|
||||
<grid row="3" column="0" row-span="1" col-span="6" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="-1" height="20"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<enabled value="false"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</toolbar>
|
||||
<component id="d2f33" class="javax.swing.JButton" binding="ButtonCreateModif">
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Модификация"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="15603" class="javax.swing.JButton" binding="ButtonDown">
|
||||
<constraints>
|
||||
<grid row="2" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="3510" class="javax.swing.JButton" binding="ButtonRight">
|
||||
<constraints>
|
||||
<grid row="2" column="5" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="dd08b" class="javax.swing.JButton" binding="ButtonCreate">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Создать"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="37083" class="javax.swing.JButton" binding="ButtonUp">
|
||||
<constraints>
|
||||
<grid row="1" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<hspacer id="7977">
|
||||
<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="4a1" class="javax.swing.JComboBox" binding="ComboBoxSelectorMap">
|
||||
<constraints>
|
||||
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<model>
|
||||
<item value="Простая карта"/>
|
||||
<item value="Карта море"/>
|
||||
</model>
|
||||
</properties>
|
||||
</component>
|
||||
<hspacer id="ed54d">
|
||||
<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>
|
||||
<component id="87b9e" class="javax.swing.JButton" binding="ButtonLeft">
|
||||
<constraints>
|
||||
<grid row="2" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
||||
177
src/FormMap.java
Normal file
177
src/FormMap.java
Normal file
@@ -0,0 +1,177 @@
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ComponentAdapter;
|
||||
import java.awt.event.ComponentEvent;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.security.PublicKey;
|
||||
import java.util.Random;
|
||||
|
||||
public class FormMap extends JFrame{
|
||||
private JButton ButtonCreateModif;
|
||||
private JButton ButtonLeft;
|
||||
private JButton ButtonDown;
|
||||
private JButton ButtonRight;
|
||||
private JButton ButtonUp;
|
||||
private JButton ButtonCreate;
|
||||
private JComboBox ComboBoxSelectorMap;
|
||||
private AbstractMap _abstractMap;
|
||||
private JPanel pictureBoxShip;
|
||||
private JToolBar StatusStrip;
|
||||
public JPanel MainPanel;
|
||||
private Random random = new Random();
|
||||
protected DrawingShip _ship;
|
||||
|
||||
private BufferedImage bufferImg = null;
|
||||
private JLabel JLabelSpeed = new JLabel();
|
||||
private JLabel JLabelWeight = new JLabel();
|
||||
private JLabel JLabelColor = new JLabel();
|
||||
|
||||
public void Draw() {
|
||||
pictureBoxShip.removeAll();
|
||||
BufferedImage bmp = new BufferedImage(pictureBoxShip.getWidth(), pictureBoxShip.getHeight(),BufferedImage.TYPE_INT_RGB);
|
||||
Graphics gr = bmp.getGraphics();
|
||||
gr.setColor(new Color(238, 238, 238));
|
||||
gr.fillRect(0, 0, pictureBoxShip.getWidth(), pictureBoxShip.getHeight());
|
||||
if (_ship != null) {
|
||||
_ship.DrawTransport(gr);
|
||||
JLabel imageOfLoco = new JLabel();
|
||||
imageOfLoco.setPreferredSize(pictureBoxShip.getSize());
|
||||
imageOfLoco.setMinimumSize(new Dimension(1, 1));
|
||||
imageOfLoco.setIcon(new ImageIcon(bmp));
|
||||
pictureBoxShip.add(imageOfLoco,BorderLayout.CENTER);
|
||||
}
|
||||
validate();
|
||||
}
|
||||
public void SetData(DrawingShip _ship)
|
||||
{
|
||||
pictureBoxShip.removeAll();
|
||||
JLabelSpeed.setText("Cкорость: " + _ship.GetShip().GetSpeed() + " ");
|
||||
JLabelWeight.setText("Вес: " + _ship.GetShip().GetWeight() + " ");
|
||||
JLabelColor.setText(("Цвет: " + _ship.GetShip().GetBodyColor() + " "));
|
||||
JLabel imageWithMapAndObject = new JLabel();
|
||||
imageWithMapAndObject.setPreferredSize(pictureBoxShip.getSize());
|
||||
imageWithMapAndObject.setMinimumSize(new Dimension(1, 1));
|
||||
imageWithMapAndObject.setIcon(new ImageIcon(_abstractMap.CreateMap(pictureBoxShip.getWidth(),pictureBoxShip.getHeight(), new DrawingObjectShip(_ship))));
|
||||
pictureBoxShip.add(imageWithMapAndObject, BorderLayout.CENTER);
|
||||
pictureBoxShip.revalidate();
|
||||
}
|
||||
@Override
|
||||
public void paint(Graphics g) {
|
||||
super.paint(g);
|
||||
Draw();
|
||||
}
|
||||
public FormMap() {
|
||||
_abstractMap = new SimpleMap();
|
||||
Box LabelBox = Box.createHorizontalBox();
|
||||
LabelBox.setMinimumSize(new Dimension(1, 20));
|
||||
LabelBox.add(JLabelSpeed);
|
||||
LabelBox.add(JLabelWeight);
|
||||
LabelBox.add(JLabelColor);
|
||||
StatusStrip.add(LabelBox);
|
||||
try {
|
||||
Image img = ImageIO.read(FormShip.class.getResource("Images/4.png"));
|
||||
ButtonUp.setIcon(new ImageIcon(img));
|
||||
img = ImageIO.read(FormShip.class.getResource("Images/2.png"));
|
||||
ButtonDown.setIcon(new ImageIcon(img));
|
||||
img = ImageIO.read(FormShip.class.getResource("Images/1.png"));
|
||||
ButtonLeft.setIcon(new ImageIcon(img));
|
||||
img = ImageIO.read(FormShip.class.getResource("Images/3.png"));
|
||||
ButtonRight.setIcon(new ImageIcon(img));
|
||||
} catch (Exception ex) {
|
||||
System.out.println(ex);
|
||||
}
|
||||
_ship=new DrawingShip (random.nextInt(100, 300), random.nextInt(1000, 2000), new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)));
|
||||
ButtonCreate.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
var _ship=new DrawingShip(random.nextInt(100, 300), random.nextInt(1000, 2000), new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)));
|
||||
_ship.SetPosition(random.nextInt(100, 500), random.nextInt(10, 100), pictureBoxShip.getWidth(), pictureBoxShip.getHeight());
|
||||
SetData(_ship);
|
||||
}
|
||||
});
|
||||
ButtonUp.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
pictureBoxShip.removeAll();
|
||||
JLabel imageWithMapAndObject = new JLabel();
|
||||
imageWithMapAndObject.setPreferredSize(pictureBoxShip.getSize());
|
||||
imageWithMapAndObject.setMinimumSize(new Dimension(1, 1));
|
||||
imageWithMapAndObject.setIcon(new ImageIcon(_abstractMap.MoveObject(Direction.Up)));
|
||||
pictureBoxShip.add(imageWithMapAndObject, BorderLayout.CENTER);
|
||||
pictureBoxShip.revalidate();
|
||||
pictureBoxShip.repaint();
|
||||
}
|
||||
});
|
||||
ButtonDown.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
pictureBoxShip.removeAll();
|
||||
JLabel imageWithMapAndObject = new JLabel();
|
||||
imageWithMapAndObject.setPreferredSize(pictureBoxShip.getSize());
|
||||
imageWithMapAndObject.setMinimumSize(new Dimension(1, 1));
|
||||
imageWithMapAndObject.setIcon(new ImageIcon(_abstractMap.MoveObject(Direction.Down)));
|
||||
pictureBoxShip.add(imageWithMapAndObject, BorderLayout.CENTER);
|
||||
pictureBoxShip.revalidate();
|
||||
pictureBoxShip.repaint();
|
||||
}
|
||||
});
|
||||
ButtonRight.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
pictureBoxShip.removeAll();
|
||||
JLabel imageWithMapAndObject = new JLabel();
|
||||
imageWithMapAndObject.setPreferredSize(pictureBoxShip.getSize());
|
||||
imageWithMapAndObject.setMinimumSize(new Dimension(1, 1));
|
||||
imageWithMapAndObject.setIcon(new ImageIcon(_abstractMap.MoveObject(Direction.Right)));
|
||||
pictureBoxShip.add(imageWithMapAndObject, BorderLayout.CENTER);
|
||||
pictureBoxShip.revalidate();
|
||||
pictureBoxShip.repaint();
|
||||
}
|
||||
});
|
||||
ButtonLeft.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
pictureBoxShip.removeAll();
|
||||
JLabel imageWithMapAndObject = new JLabel();
|
||||
imageWithMapAndObject.setPreferredSize(pictureBoxShip.getSize());
|
||||
imageWithMapAndObject.setMinimumSize(new Dimension(1, 1));
|
||||
imageWithMapAndObject.setIcon(new ImageIcon(_abstractMap.MoveObject(Direction.Left)));
|
||||
pictureBoxShip.add(imageWithMapAndObject, BorderLayout.CENTER);
|
||||
pictureBoxShip.revalidate();
|
||||
pictureBoxShip.repaint();
|
||||
|
||||
}
|
||||
});
|
||||
ButtonCreateModif.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
_ship=new DrawingLiner(random.nextInt(100, 300), random.nextInt(1000, 2000), new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)),new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)),random.nextBoolean(),random.nextBoolean());
|
||||
_ship.SetPosition(random.nextInt(100, 500), random.nextInt(10, 100), pictureBoxShip.getWidth(), pictureBoxShip.getHeight());
|
||||
SetData(_ship);
|
||||
}
|
||||
});
|
||||
|
||||
ComboBoxSelectorMap.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
ComboBoxSelectorMap = (JComboBox)e.getSource();
|
||||
String item = (String)ComboBoxSelectorMap.getSelectedItem();
|
||||
switch (item) {
|
||||
case "Простая карта": {
|
||||
_abstractMap = new SimpleMap();
|
||||
break;
|
||||
}
|
||||
case "Карта море": {
|
||||
_abstractMap = new SeaMap();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormShip">
|
||||
<grid id="27dc6" binding="Mainpanel" layout-manager="GridLayoutManager" row-count="4" column-count="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="7" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<xy x="20" y="20" width="500" height="400"/>
|
||||
@@ -10,7 +10,7 @@
|
||||
<children>
|
||||
<component id="2ea16" 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">
|
||||
<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"/>
|
||||
@@ -22,7 +22,7 @@
|
||||
</component>
|
||||
<component id="4f60a" 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">
|
||||
<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"/>
|
||||
@@ -34,7 +34,7 @@
|
||||
</component>
|
||||
<component id="4eb88" 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">
|
||||
<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"/>
|
||||
@@ -45,15 +45,9 @@
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="9f55" class="DrawingShip" binding="PictureBoxShip">
|
||||
<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/>
|
||||
</component>
|
||||
<component id="fb937" 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">
|
||||
<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"/>
|
||||
@@ -65,7 +59,7 @@
|
||||
</component>
|
||||
<toolbar id="e747d" binding="StatusStrip">
|
||||
<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="7" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="-1" height="20"/>
|
||||
<preferred-size width="-1" height="20"/>
|
||||
<maximum-size width="-1" height="20"/>
|
||||
@@ -79,9 +73,22 @@
|
||||
</toolbar>
|
||||
<hspacer id="d6bea">
|
||||
<constraints>
|
||||
<grid row="1" column="1" row-span="1" col-span="2" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
<grid row="1" column="1" row-span="1" col-span="4" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
<hspacer id="d86ff">
|
||||
<constraints>
|
||||
<grid row="2" column="1" row-span="1" col-span="3" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
<grid id="6b0b8" binding="pictureBoxShip" layout-manager="FlowLayout" hgap="5" vgap="5" flow-align="1">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="7" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<component id="9e2ce" class="javax.swing.JButton" binding="ButtonCreate">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
@@ -90,11 +97,14 @@
|
||||
<text value="Создать"/>
|
||||
</properties>
|
||||
</component>
|
||||
<hspacer id="d86ff">
|
||||
<component id="86a62" class="javax.swing.JButton" binding="ButtonCreateModif">
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="1" col-span="2" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
<properties>
|
||||
<text value="Модификация"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
||||
|
||||
@@ -5,25 +5,40 @@ import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ComponentAdapter;
|
||||
import java.awt.event.ComponentEvent;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.Random;
|
||||
public class FormShip {
|
||||
public class FormShip extends JFrame{
|
||||
public JPanel Mainpanel;
|
||||
private Random random = new Random();
|
||||
private JButton ButtonCreate;
|
||||
private JButton ButtonLeft;
|
||||
private JButton ButtonUp;
|
||||
private JButton ButtonDown;
|
||||
private JButton ButtonRight;
|
||||
protected DrawingShip PictureBoxShip;
|
||||
private JButton ButtonCreateModif;
|
||||
protected DrawingShip _ship;
|
||||
private JPanel pictureBoxShip;
|
||||
private JToolBar StatusStrip;
|
||||
private JLabel JLabelSpeed = new JLabel();
|
||||
private JLabel JLabelWeight = new JLabel();
|
||||
private JLabel JLabelColor = new JLabel();
|
||||
public void Draw() {
|
||||
if (PictureBoxShip.GetShip() == null) {
|
||||
return;
|
||||
public void Draw(DrawingShip _ship) {
|
||||
pictureBoxShip.removeAll();
|
||||
BufferedImage bmp = new BufferedImage(pictureBoxShip.getWidth(), pictureBoxShip.getHeight(),BufferedImage.TYPE_INT_RGB);
|
||||
Graphics gr = bmp.getGraphics();
|
||||
gr.setColor(new Color(238, 238, 238));
|
||||
gr.fillRect(0, 0, pictureBoxShip.getWidth(), pictureBoxShip.getHeight());
|
||||
if (_ship != null) {
|
||||
_ship.DrawTransport(gr);
|
||||
JLabel imageOfLoco = new JLabel();
|
||||
imageOfLoco.setPreferredSize(pictureBoxShip.getSize());
|
||||
imageOfLoco.setMinimumSize(new Dimension(1, 1));
|
||||
imageOfLoco.setIcon(new ImageIcon(bmp));
|
||||
pictureBoxShip.add(imageOfLoco,BorderLayout.CENTER);
|
||||
}
|
||||
PictureBoxShip.DrawTransport();
|
||||
validate();
|
||||
}
|
||||
|
||||
public FormShip() {
|
||||
Box LabelBox = Box.createHorizontalBox();
|
||||
LabelBox.setMinimumSize(new Dimension(1, 20));
|
||||
@@ -45,50 +60,69 @@ public class FormShip {
|
||||
}
|
||||
ButtonCreate.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Random random = new Random();
|
||||
PictureBoxShip.Init(random.nextInt(100, 300), random.nextInt(1000, 2000), new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)));
|
||||
PictureBoxShip.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100), PictureBoxShip.getWidth(), PictureBoxShip.getHeight());
|
||||
JLabelSpeed.setText("Cкорость: " + PictureBoxShip.GetShip().GetSpeed() + " ");
|
||||
JLabelWeight.setText("Вес: " + PictureBoxShip.GetShip().GetWeight() + " ");
|
||||
JLabelColor.setText(("Цвет: " + PictureBoxShip.GetShip().GetBodyColor() + " "));
|
||||
Draw();
|
||||
public void actionPerformed(ActionEvent e){
|
||||
_ship=new DrawingShip(random.nextInt(100, 300), random.nextInt(1000, 2000), new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)));
|
||||
_ship.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100), pictureBoxShip.getWidth(), pictureBoxShip.getHeight());
|
||||
JLabelSpeed.setText("Cкорость: " + _ship.GetShip().GetSpeed() + " ");
|
||||
JLabelWeight.setText("Вес: " + _ship.GetShip().GetWeight() + " ");
|
||||
JLabelColor.setText(("Цвет: " + _ship.GetShip().GetBodyColor() + " "));
|
||||
Draw(_ship);
|
||||
}
|
||||
});
|
||||
PictureBoxShip.addComponentListener(new ComponentAdapter() {
|
||||
pictureBoxShip.addComponentListener(new ComponentAdapter() {
|
||||
@Override
|
||||
public void componentResized(ComponentEvent e) {
|
||||
super.componentResized(e);
|
||||
PictureBoxShip.ChangeBorders(PictureBoxShip.getWidth(), PictureBoxShip.getHeight());
|
||||
Draw();
|
||||
if(_ship!=null)
|
||||
{
|
||||
_ship.ChangeBorders(pictureBoxShip.getWidth(), pictureBoxShip.getHeight());
|
||||
pictureBoxShip.revalidate();
|
||||
Draw(_ship);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
ButtonUp.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
PictureBoxShip.MoveTransport(Direction.Up);
|
||||
Draw();
|
||||
_ship.MoveTransport(Direction.Up);
|
||||
pictureBoxShip.revalidate();
|
||||
Draw(_ship);
|
||||
}
|
||||
});
|
||||
ButtonDown.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
PictureBoxShip.MoveTransport(Direction.Down);
|
||||
Draw();
|
||||
_ship.MoveTransport(Direction.Down);
|
||||
pictureBoxShip.revalidate();
|
||||
Draw(_ship);
|
||||
}
|
||||
});
|
||||
ButtonRight.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
PictureBoxShip.MoveTransport(Direction.Right);
|
||||
Draw();
|
||||
_ship.MoveTransport(Direction.Right);
|
||||
pictureBoxShip.revalidate();
|
||||
Draw(_ship);
|
||||
}
|
||||
});
|
||||
ButtonLeft.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
PictureBoxShip.MoveTransport(Direction.Left);
|
||||
Draw();
|
||||
_ship.MoveTransport(Direction.Left);
|
||||
pictureBoxShip.revalidate();
|
||||
Draw(_ship);
|
||||
}
|
||||
});
|
||||
ButtonCreateModif.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
_ship=new DrawingLiner(random.nextInt(100, 300), random.nextInt(1000, 2000), new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)),new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)),random.nextBoolean(),random.nextBoolean());
|
||||
_ship.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100), pictureBoxShip.getWidth(), pictureBoxShip.getHeight());
|
||||
JLabelSpeed.setText("Cкорость: " + _ship.GetShip().GetSpeed() + " ");
|
||||
JLabelWeight.setText("Вес: " + _ship.GetShip().GetWeight() + " ");
|
||||
JLabelColor.setText(("Цвет: " + _ship.GetShip().GetBodyColor() + " "));
|
||||
Draw(_ship);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
6
src/IAdditionalDrawingObject.java
Normal file
6
src/IAdditionalDrawingObject.java
Normal file
@@ -0,0 +1,6 @@
|
||||
import java.awt.*;
|
||||
|
||||
public interface IAdditionalDrawingObject {
|
||||
void SetAddEnum(int decksAmount);
|
||||
void DrawDeck(Color colorDeck, Graphics g, float _startPosX, float _startPosY);
|
||||
}
|
||||
9
src/IDrawingObject.java
Normal file
9
src/IDrawingObject.java
Normal file
@@ -0,0 +1,9 @@
|
||||
import java.awt.*;
|
||||
|
||||
public interface IDrawingObject {
|
||||
public float Step();
|
||||
void SetObject(int x, int y,int width,int height);
|
||||
void MoveObject(Direction direction);
|
||||
void DrawingObject(Graphics g);
|
||||
float[] GetCurrentPosition();
|
||||
}
|
||||
@@ -3,7 +3,7 @@ import javax.swing.*;
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
JFrame frame = new JFrame("Лайнер");
|
||||
frame.setContentPane(new FormShip().Mainpanel);
|
||||
frame.setContentPane(new FormMap().MainPanel);
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
frame.setLocation(500, 200);
|
||||
frame.pack();
|
||||
|
||||
49
src/SeaMap.java
Normal file
49
src/SeaMap.java
Normal file
@@ -0,0 +1,49 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class SeaMap extends AbstractMap{
|
||||
private final Color barrierColor = Color.WHITE;
|
||||
private final Color roadColor = Color.CYAN;
|
||||
@Override
|
||||
protected void DrawBarrierPart(Graphics g, int i, int j)
|
||||
{
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
g2d.setPaint(barrierColor);
|
||||
g2d.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 g2d = (Graphics2D) g;
|
||||
g2d.setPaint(roadColor);
|
||||
g2d.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[0].length; ++j)
|
||||
{
|
||||
_map[i][j] = _freeRoad;
|
||||
}
|
||||
}
|
||||
while (counter < 25)
|
||||
{
|
||||
int x = _random.nextInt(0, 97);
|
||||
int y = _random.nextInt(0, 97);
|
||||
if (_map[x][y] == _freeRoad)
|
||||
{
|
||||
_map[x][y + 1] = _barrier;
|
||||
_map[x + 1][y + 1] = _barrier;
|
||||
_map[x + 2][y + 1] = _barrier;
|
||||
_map[x + 1][y] = _barrier;
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
45
src/SimpleMap.java
Normal file
45
src/SimpleMap.java
Normal file
@@ -0,0 +1,45 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class SimpleMap extends AbstractMap{
|
||||
private final Color barrierColor = Color.black;
|
||||
private final Color roadColor = Color.gray;
|
||||
@Override
|
||||
protected void DrawBarrierPart(Graphics g, int i, int j)
|
||||
{
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
g2d.setPaint(barrierColor);
|
||||
g2d.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 g2d = (Graphics2D) g;
|
||||
g2d.setPaint(roadColor);
|
||||
g2d.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[0].length; ++j)
|
||||
{
|
||||
_map[i][j] = _freeRoad;
|
||||
}
|
||||
}
|
||||
while (counter < 50)
|
||||
{
|
||||
int x = _random.nextInt(0, 100);
|
||||
int y = _random.nextInt(0, 100);
|
||||
if (_map[x][y] == _freeRoad)
|
||||
{
|
||||
_map[x][y] = _barrier;
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user