Вторая усложненная лабораторная работа.
This commit is contained in:
parent
af8b91a1a4
commit
da3355686d
123
ContainerShip/src/containership/AbstractMap.java
Normal file
123
ContainerShip/src/containership/AbstractMap.java
Normal file
@ -0,0 +1,123 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package containership;
|
||||
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ateks
|
||||
*/
|
||||
public abstract class AbstractMap {
|
||||
private IDrawingObject _drawningObject = null;
|
||||
protected int[][] _map = null;
|
||||
protected int _width;
|
||||
protected int _height;
|
||||
protected int _size_x;
|
||||
protected int _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;
|
||||
_drawningObject = drawningObject;
|
||||
GenerateMap();
|
||||
while (!SetObjectOnMap())
|
||||
{
|
||||
GenerateMap();
|
||||
}
|
||||
return DrawMapWithObject();
|
||||
}
|
||||
public BufferedImage MoveObject(Direction direction)
|
||||
{
|
||||
if (_drawningObject == null) return DrawMapWithObject();
|
||||
boolean canMove = true;
|
||||
switch (direction)
|
||||
{
|
||||
case LEFT:
|
||||
if (!checkForBarriers(0, -1 * _drawningObject.getStep(), -1 * _drawningObject.getStep(), 0)) canMove = false;
|
||||
break;
|
||||
case RIGHT:
|
||||
if (!checkForBarriers(0, _drawningObject.getStep(), _drawningObject.getStep(), 0)) canMove = false;
|
||||
break;
|
||||
case UP:
|
||||
if (!checkForBarriers(-1 * _drawningObject.getStep(), 0, 0, -1 * _drawningObject.getStep())) canMove = false;
|
||||
break;
|
||||
case DOWN:
|
||||
if (!checkForBarriers(_drawningObject.getStep(), 0, 0, _drawningObject.getStep())) canMove = false;
|
||||
break;
|
||||
}
|
||||
if (canMove)
|
||||
{
|
||||
_drawningObject.MoveObject(direction);
|
||||
}
|
||||
return DrawMapWithObject();
|
||||
}
|
||||
private boolean SetObjectOnMap()
|
||||
{
|
||||
if (_drawningObject == null || _map == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
int x = _random.nextInt(0, 10);
|
||||
int y = _random.nextInt(0, 10);
|
||||
_drawningObject.SetObject(x, y, _width, _height);
|
||||
if (!checkForBarriers(0,0,0,0)) return false;
|
||||
return true;
|
||||
}
|
||||
private BufferedImage DrawMapWithObject()
|
||||
{
|
||||
BufferedImage bmp = new BufferedImage(_width, _height, BufferedImage.TYPE_INT_ARGB);
|
||||
if (_drawningObject == null || _map == null)
|
||||
{
|
||||
return bmp;
|
||||
}
|
||||
Graphics2D gr = bmp.createGraphics();
|
||||
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;
|
||||
}
|
||||
|
||||
private boolean checkForBarriers(float topOffset, float rightOffset, float leftOffset, float bottomOffset)
|
||||
{
|
||||
float[] position = _drawningObject.GetCurrentPosition();
|
||||
int top = (int)((position[1] + topOffset) / _size_y);
|
||||
int right = (int)((position[2] + rightOffset) / _size_x);
|
||||
int left = (int)((position[0] + leftOffset) / _size_x);
|
||||
int bottom = (int)((position[3] + bottomOffset) / _size_y);
|
||||
if (top < 0 || left < 0 || right >= _map[0].length || bottom >= _map.length) return false;
|
||||
for (int i = top; i <= bottom; i++)
|
||||
{
|
||||
for (int j = left; j <= right; j++)
|
||||
{
|
||||
if (_map[j][i] == 1) return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
protected abstract void GenerateMap();
|
||||
protected abstract void DrawRoadPart(Graphics g, int i, int j);
|
||||
protected abstract void DrawBarrierPart(Graphics g, int i, int j);
|
||||
}
|
15
ContainerShip/src/containership/DecksType.java
Normal file
15
ContainerShip/src/containership/DecksType.java
Normal file
@ -0,0 +1,15 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package containership;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ateks
|
||||
*/
|
||||
public enum DecksType {
|
||||
RECTANGLE,
|
||||
TROPEC,
|
||||
REVERSEDTR
|
||||
}
|
@ -12,5 +12,6 @@ public enum Direction {
|
||||
UP,
|
||||
DOWN,
|
||||
LEFT,
|
||||
RIGHT
|
||||
RIGHT,
|
||||
NONE
|
||||
}
|
55
ContainerShip/src/containership/DrawingContainerShip.java
Normal file
55
ContainerShip/src/containership/DrawingContainerShip.java
Normal file
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package containership;
|
||||
import java.awt.*;
|
||||
/**
|
||||
*
|
||||
* @author ateks
|
||||
*/
|
||||
public class DrawingContainerShip extends DrawingShip {
|
||||
public DrawingContainerShip(int speed, float weight, Color bodyColor, DecksType decksType, int numberOfDecks, Color dopColor, boolean containers, boolean crane)
|
||||
{
|
||||
super(speed, weight, bodyColor, decksType, numberOfDecks, 135, 55);
|
||||
Ship = new EntityContainerShip(speed, weight, bodyColor, dopColor, containers, crane);
|
||||
this.dopColor = dopColor;
|
||||
}
|
||||
Color dopColor;
|
||||
|
||||
@Override
|
||||
public void DrawTransport(Graphics2D g)
|
||||
{
|
||||
if (!(Ship instanceof EntityContainerShip containerShip))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (containerShip.getCrane())
|
||||
{
|
||||
g.setColor(dopColor);
|
||||
g.drawLine((int)(_startPosX), (int)(_startPosY+10), (int)(_startPosX+25), (int)(_startPosY+20));
|
||||
g.drawLine((int)(_startPosX), (int)(_startPosY+10), (int)(_startPosX), (int)(_startPosY+22));
|
||||
g.drawLine((int)(_startPosX), (int)(_startPosY+10), (int)(_startPosX), (int)(_startPosY+22));
|
||||
g.drawLine((int)(_startPosX), (int)(_startPosY+10), (int)(_startPosX+25), (int)(_startPosY+10));
|
||||
g.drawLine((int)(_startPosX+25), (int)(_startPosY+10), (int)(_startPosX+25), (int)(_startPosY+30));
|
||||
g.setColor(Color.BLACK);
|
||||
}
|
||||
|
||||
super.DrawTransport(g);
|
||||
|
||||
if (containerShip.getContainers())
|
||||
{
|
||||
g.setColor(dopColor);
|
||||
g.fillRect((int)(_startPosX+35), (int)(_startPosY+20), 10, 10);
|
||||
g.fillRect((int)(_startPosX+55), (int)(_startPosY+20), 20, 10);
|
||||
g.fillRect((int)(_startPosX+75), (int)(_startPosY+15), 25, 15);
|
||||
g.fillRect((int)(_startPosX+100), (int)(_startPosY+20), 25, 10);
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawRect((int)(_startPosX+35), (int)(_startPosY+20), 10, 10);
|
||||
g.drawRect((int)(_startPosX+55), (int)(_startPosY+20), 20, 10);
|
||||
g.drawRect((int)(_startPosX+75), (int)(_startPosY+15), 25, 15);
|
||||
g.drawRect((int)(_startPosX+100), (int)(_startPosY+20), 25, 10);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -11,15 +11,17 @@ import java.awt.Color;
|
||||
*
|
||||
* @author ateks
|
||||
*/
|
||||
public class DrawingDecks {
|
||||
public class DrawingDecks implements IDrawingObjectAdd {
|
||||
|
||||
private Decks decks = null;
|
||||
private int numberOfDecks;
|
||||
|
||||
@Override
|
||||
public int getNumberOfDecks() {
|
||||
return numberOfDecks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNumberOfDecks(int numberOfDecks) {
|
||||
if (numberOfDecks != 1 && numberOfDecks != 2 && numberOfDecks != 3) {
|
||||
return;
|
||||
@ -38,27 +40,15 @@ public class DrawingDecks {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawBottomDeck(Graphics2D g, int _startPosX, int _startPosY, Color bodyColor) {
|
||||
int[] curcuitY
|
||||
= {
|
||||
_startPosY + 30,
|
||||
_startPosY + 30,
|
||||
_startPosY + 55,
|
||||
_startPosY + 55,
|
||||
_startPosY + 30,};
|
||||
int[] curcuitX
|
||||
= {
|
||||
_startPosX + 100,
|
||||
_startPosX + 135,
|
||||
_startPosX + 115,
|
||||
_startPosX + 20,
|
||||
_startPosX,};
|
||||
g.setColor(bodyColor);
|
||||
g.fillPolygon(curcuitX, curcuitY, curcuitX.length);
|
||||
g.fillRect(_startPosX, _startPosY + 30, 135, 25);
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawPolygon(curcuitX, curcuitY, curcuitX.length);
|
||||
g.drawRect(_startPosX, _startPosY + 30, 135, 25);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawMiddleDeck(Graphics2D g, int _startPosX, int _startPosY, Color bodyColor) {
|
||||
g.setColor(bodyColor);
|
||||
g.fillRect(_startPosX+30, _startPosY+15, 70, 15);
|
||||
@ -66,6 +56,7 @@ public class DrawingDecks {
|
||||
g.drawRect(_startPosX+30, _startPosY+15, 70, 15 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawUpperDeck(Graphics2D g, int _startPosX, int _startPosY, Color bodyColor) {
|
||||
g.setColor(bodyColor);
|
||||
g.fillRect(_startPosX+50, _startPosY, 45, 15 );
|
||||
@ -75,6 +66,7 @@ public class DrawingDecks {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void drawDecks(Graphics2D g, int _startPosX, int _startPosY, Color bodyColor) {
|
||||
if (decks == null) {
|
||||
return;
|
||||
@ -88,6 +80,5 @@ public class DrawingDecks {
|
||||
drawBottomDeck(g, _startPosX, _startPosY, bodyColor);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
123
ContainerShip/src/containership/DrawingDecksReversedTr.java
Normal file
123
ContainerShip/src/containership/DrawingDecksReversedTr.java
Normal file
@ -0,0 +1,123 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package containership;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ateks
|
||||
*/
|
||||
public class DrawingDecksReversedTr implements IDrawingObjectAdd {
|
||||
|
||||
private Decks decks = null;
|
||||
private int numberOfDecks;
|
||||
|
||||
@Override
|
||||
public int getNumberOfDecks() {
|
||||
return numberOfDecks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNumberOfDecks(int numberOfDecks) {
|
||||
if (numberOfDecks != 1 && numberOfDecks != 2 && numberOfDecks != 3){
|
||||
return;
|
||||
}
|
||||
this.numberOfDecks = numberOfDecks;
|
||||
switch (this.numberOfDecks) {
|
||||
case 1:
|
||||
decks = Decks.ONE;
|
||||
break;
|
||||
case 2:
|
||||
decks = Decks.TWO;
|
||||
break;
|
||||
case 3:
|
||||
decks = Decks.THREE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawDecks(Graphics2D g, int _startPosX, int _startPosY, Color bodyColor) {
|
||||
if (decks == null) {
|
||||
return;
|
||||
}
|
||||
switch (decks) {
|
||||
case THREE:
|
||||
drawUpperDeck(g, _startPosX, _startPosY, bodyColor);
|
||||
case TWO:
|
||||
drawMiddleDeck(g, _startPosX, _startPosY, bodyColor);
|
||||
case ONE:
|
||||
drawBottomDeck(g, _startPosX, _startPosY, bodyColor);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawBottomDeck(Graphics2D g, int _startPosX, int _startPosY, Color bodyColor) {
|
||||
int[] curcuitY
|
||||
= {
|
||||
_startPosY + 30,
|
||||
_startPosY + 30,
|
||||
_startPosY + 55,
|
||||
_startPosY + 55,};
|
||||
int[] curcuitX
|
||||
= {
|
||||
_startPosX + 5,
|
||||
_startPosX + 130,
|
||||
_startPosX + 135,
|
||||
_startPosX,};
|
||||
g.setColor(bodyColor);
|
||||
g.fillPolygon(curcuitX, curcuitY, curcuitX.length);
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawPolygon(curcuitX, curcuitY, curcuitX.length);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawMiddleDeck(Graphics2D g, int _startPosX, int _startPosY, Color bodyColor) {
|
||||
g.setColor(bodyColor);
|
||||
int[] curcuitY
|
||||
= {
|
||||
_startPosY + 30,
|
||||
_startPosY + 15,
|
||||
_startPosY + 15,
|
||||
_startPosY + 30,
|
||||
} ;
|
||||
int[] curcuitX
|
||||
= {
|
||||
_startPosX + 30,
|
||||
_startPosX + 40,
|
||||
_startPosX + 90,
|
||||
_startPosX + 100,
|
||||
} ;
|
||||
g.fillPolygon(curcuitX, curcuitY, curcuitX.length);
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawPolygon(curcuitX, curcuitY, curcuitX.length);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawUpperDeck(Graphics2D g, int _startPosX, int _startPosY, Color bodyColor) {
|
||||
g.setColor(bodyColor);
|
||||
int[] curcuitY
|
||||
= {
|
||||
_startPosY + 15,
|
||||
_startPosY,
|
||||
_startPosY,
|
||||
_startPosY + 15,
|
||||
} ;
|
||||
int[] curcuitX
|
||||
= {
|
||||
_startPosX + 50,
|
||||
_startPosX + 55,
|
||||
_startPosX + 80,
|
||||
_startPosX + 85,
|
||||
} ;
|
||||
g.fillPolygon(curcuitX, curcuitY, curcuitX.length);
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawPolygon(curcuitX, curcuitY, curcuitX.length);
|
||||
}
|
||||
|
||||
}
|
125
ContainerShip/src/containership/DrawingDecksTropec.java
Normal file
125
ContainerShip/src/containership/DrawingDecksTropec.java
Normal file
@ -0,0 +1,125 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package containership;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ateks
|
||||
*/
|
||||
public class DrawingDecksTropec implements IDrawingObjectAdd {
|
||||
|
||||
private Decks decks = null;
|
||||
private int numberOfDecks;
|
||||
|
||||
@Override
|
||||
public int getNumberOfDecks() {
|
||||
return numberOfDecks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNumberOfDecks(int numberOfDecks) {
|
||||
if (numberOfDecks != 1 && numberOfDecks != 2 && numberOfDecks != 3){
|
||||
return;
|
||||
}
|
||||
this.numberOfDecks = numberOfDecks;
|
||||
switch (this.numberOfDecks) {
|
||||
case 1:
|
||||
decks = Decks.ONE;
|
||||
break;
|
||||
case 2:
|
||||
decks = Decks.TWO;
|
||||
break;
|
||||
case 3:
|
||||
decks = Decks.THREE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawDecks(Graphics2D g, int _startPosX, int _startPosY, Color bodyColor) {
|
||||
if (decks == null) {
|
||||
return;
|
||||
}
|
||||
switch (decks) {
|
||||
case THREE:
|
||||
drawUpperDeck(g, _startPosX, _startPosY, bodyColor);
|
||||
case TWO:
|
||||
drawMiddleDeck(g, _startPosX, _startPosY, bodyColor);
|
||||
case ONE:
|
||||
drawBottomDeck(g, _startPosX, _startPosY, bodyColor);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawBottomDeck(Graphics2D g, int _startPosX, int _startPosY, Color bodyColor) {
|
||||
int[] curcuitY
|
||||
= {
|
||||
_startPosY + 30,
|
||||
_startPosY + 30,
|
||||
_startPosY + 55,
|
||||
_startPosY + 55,
|
||||
_startPosY + 30,};
|
||||
int[] curcuitX
|
||||
= {
|
||||
_startPosX + 100,
|
||||
_startPosX + 135,
|
||||
_startPosX + 115,
|
||||
_startPosX + 20,
|
||||
_startPosX,};
|
||||
g.setColor(bodyColor);
|
||||
g.fillPolygon(curcuitX, curcuitY, curcuitX.length);
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawPolygon(curcuitX, curcuitY, curcuitX.length);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawMiddleDeck(Graphics2D g, int _startPosX, int _startPosY, Color bodyColor) {
|
||||
g.setColor(bodyColor);
|
||||
int[] curcuitY
|
||||
= {
|
||||
_startPosY + 15,
|
||||
_startPosY + 30,
|
||||
_startPosY + 30,
|
||||
_startPosY + 15,
|
||||
} ;
|
||||
int[] curcuitX
|
||||
= {
|
||||
_startPosX + 30,
|
||||
_startPosX + 40,
|
||||
_startPosX + 90,
|
||||
_startPosX + 100,
|
||||
} ;
|
||||
g.fillPolygon(curcuitX, curcuitY, curcuitX.length);
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawPolygon(curcuitX, curcuitY, curcuitX.length);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawUpperDeck(Graphics2D g, int _startPosX, int _startPosY, Color bodyColor) {
|
||||
g.setColor(bodyColor);
|
||||
int[] curcuitY
|
||||
= {
|
||||
_startPosY,
|
||||
_startPosY + 15,
|
||||
_startPosY + 15,
|
||||
_startPosY,
|
||||
} ;
|
||||
int[] curcuitX
|
||||
= {
|
||||
_startPosX + 50,
|
||||
_startPosX + 55,
|
||||
_startPosX + 90,
|
||||
_startPosX + 95,
|
||||
} ;
|
||||
g.fillPolygon(curcuitX, curcuitY, curcuitX.length);
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawPolygon(curcuitX, curcuitY, curcuitX.length);
|
||||
}
|
||||
|
||||
}
|
58
ContainerShip/src/containership/DrawingObjectShip.java
Normal file
58
ContainerShip/src/containership/DrawingObjectShip.java
Normal file
@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package containership;
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ateks
|
||||
*/
|
||||
public class DrawingObjectShip implements IDrawingObject {
|
||||
private DrawingShip _ship = null;
|
||||
|
||||
public DrawingObjectShip(DrawingShip ship)
|
||||
{
|
||||
_ship = ship;
|
||||
Step = _ship.Ship.Step;
|
||||
}
|
||||
|
||||
public float Step;
|
||||
@Override
|
||||
public float getStep(){
|
||||
return Step;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float[] GetCurrentPosition()
|
||||
{
|
||||
if (_ship == null) return null;
|
||||
return _ship.GetCurrentPosition();
|
||||
}
|
||||
@Override
|
||||
public void MoveObject(Direction direction)
|
||||
{
|
||||
_ship.MoveTransport(direction);
|
||||
}
|
||||
@Override
|
||||
public void SetObject(int x, int y, int width, int height)
|
||||
{
|
||||
_ship.SetPosition(x, y, width, height);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void DrawingObject(Graphics2D g)
|
||||
{
|
||||
if (_ship == null) return;
|
||||
if (_ship instanceof DrawingContainerShip containerShip)
|
||||
{
|
||||
containerShip.DrawTransport(g);
|
||||
}
|
||||
else
|
||||
{
|
||||
_ship.DrawTransport(g);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,22 +10,47 @@ import java.util.Random;
|
||||
* @author ateks
|
||||
*/
|
||||
public class DrawingShip {
|
||||
private EntityShip Ship;
|
||||
public EntityShip Ship;
|
||||
//отрисовка палуб
|
||||
public DrawingDecks drawingDecks;
|
||||
public IDrawingObjectAdd drawingDecks;
|
||||
public float _startPosX;
|
||||
public float _startPosY;
|
||||
private Integer _pictureWidth = null;
|
||||
private Integer _pictureHeight = null;
|
||||
private static final int _shipWidth = 135;
|
||||
private static final int _shipHeight = 40;
|
||||
private static int _shipWidth = 135;
|
||||
private static int _shipHeight = 55;
|
||||
|
||||
public void Init(int speed, float weight, Color bodyColor, int numberOfDecks){
|
||||
Ship = new EntityShip();
|
||||
// мметод прорисовки палуб
|
||||
drawingDecks = new DrawingDecks();
|
||||
Ship.Init(speed, weight, bodyColor);
|
||||
drawingDecks.setNumberOfDecks(numberOfDecks);/////// палубы
|
||||
public DrawingShip(int speed, float weight, Color bodyColor, DecksType decksType, int numberOfDecks){
|
||||
Ship = new EntityShip(speed, weight, bodyColor);
|
||||
switch(decksType){
|
||||
case RECTANGLE:
|
||||
drawingDecks = new DrawingDecks();
|
||||
break;
|
||||
case TROPEC:
|
||||
drawingDecks = new DrawingDecksTropec();
|
||||
break;
|
||||
case REVERSEDTR:
|
||||
drawingDecks = new DrawingDecksReversedTr();
|
||||
break;
|
||||
}
|
||||
drawingDecks.setNumberOfDecks(numberOfDecks);//палубы
|
||||
}
|
||||
public DrawingShip(int speed, float weight, Color bodyColor, DecksType decksType, int numberOfDecks, int width, int height){
|
||||
Ship = new EntityShip(speed, weight, bodyColor);
|
||||
_shipWidth = width;
|
||||
_shipHeight = height;
|
||||
switch(decksType){
|
||||
case RECTANGLE:
|
||||
drawingDecks = new DrawingDecks();
|
||||
break;
|
||||
case TROPEC:
|
||||
drawingDecks = new DrawingDecksTropec();
|
||||
break;
|
||||
case REVERSEDTR:
|
||||
drawingDecks = new DrawingDecksReversedTr();
|
||||
break;
|
||||
}
|
||||
drawingDecks.setNumberOfDecks(numberOfDecks);//палубы
|
||||
}
|
||||
|
||||
public EntityShip getShip() {
|
||||
@ -109,4 +134,13 @@ public class DrawingShip {
|
||||
_startPosY = _pictureHeight - _shipHeight;
|
||||
}
|
||||
}
|
||||
}
|
||||
public float [] GetCurrentPosition()
|
||||
{
|
||||
float[] pos = new float[4];
|
||||
pos[0] = _startPosX;
|
||||
pos[1] = _startPosY;
|
||||
pos[2] = _startPosX + _shipWidth;
|
||||
pos[3] = _startPosY + _shipHeight;
|
||||
return pos;
|
||||
}
|
||||
}
|
36
ContainerShip/src/containership/EntityContainerShip.java
Normal file
36
ContainerShip/src/containership/EntityContainerShip.java
Normal file
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package containership;
|
||||
import java.awt.*;
|
||||
/**
|
||||
*
|
||||
* @author ateks
|
||||
*/
|
||||
public class EntityContainerShip extends EntityShip {
|
||||
private Color DopColor;
|
||||
private boolean containers;
|
||||
private boolean crane;
|
||||
|
||||
|
||||
public Color getDopColor() {
|
||||
return DopColor;
|
||||
}
|
||||
|
||||
public boolean getContainers(){
|
||||
return containers;
|
||||
}
|
||||
|
||||
public boolean getCrane(){
|
||||
return crane;
|
||||
}
|
||||
|
||||
public EntityContainerShip(int speed, float weight, Color bodyColor, Color dopColor, boolean containers, boolean crane)
|
||||
{
|
||||
super(speed, weight, bodyColor);
|
||||
DopColor = dopColor;
|
||||
this.containers = containers;
|
||||
this.crane = crane;
|
||||
}
|
||||
}
|
@ -30,9 +30,7 @@ public class EntityShip {
|
||||
return BodyColor;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void Init(int speed, float weight, Color bodyColor){
|
||||
public EntityShip(int speed, float weight, Color bodyColor){
|
||||
Random rnd = new Random();
|
||||
Speed = speed <= 0 ? rnd.nextInt(50, 150) : speed;
|
||||
Weight = weight <= 0 ? rnd.nextInt(40, 70) : weight;
|
||||
|
40
ContainerShip/src/containership/IDrawingObject.java
Normal file
40
ContainerShip/src/containership/IDrawingObject.java
Normal file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Interface.java to edit this template
|
||||
*/
|
||||
package containership;
|
||||
import java.awt.*;
|
||||
/**
|
||||
*
|
||||
* @author ateks
|
||||
*/
|
||||
public interface IDrawingObject {
|
||||
/// <summary>
|
||||
/// Шаг перемещения объекта
|
||||
/// </summary>
|
||||
public float getStep();
|
||||
/// <summary>
|
||||
/// Установка позиции объекта
|
||||
/// </summary>
|
||||
/// <param name="x">Координата X</param>
|
||||
/// <param name="y">Координата Y</param>
|
||||
/// <param name="width">Ширина полотна</param>
|
||||
/// <param name="height">Высота полотна</param>
|
||||
void SetObject(int x, int y, int width, int height);
|
||||
/// <summary>
|
||||
/// Изменение направления пермещения объекта
|
||||
/// </summary>
|
||||
/// <param name="direction">Направление</param>
|
||||
/// <returns></returns>
|
||||
void MoveObject(Direction direction);
|
||||
/// <summary>
|
||||
/// Отрисовка объекта
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
void DrawingObject(Graphics2D g);
|
||||
/// <summary>
|
||||
/// Получение текущей позиции объекта
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
float[] GetCurrentPosition();
|
||||
}
|
18
ContainerShip/src/containership/IDrawingObjectAdd.java
Normal file
18
ContainerShip/src/containership/IDrawingObjectAdd.java
Normal file
@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Interface.java to edit this template
|
||||
*/
|
||||
package containership;
|
||||
import java.awt.*;
|
||||
/**
|
||||
*
|
||||
* @author ateks
|
||||
*/
|
||||
public interface IDrawingObjectAdd {
|
||||
public int getNumberOfDecks();
|
||||
void setNumberOfDecks(int numberOfDecks);
|
||||
void drawDecks(Graphics2D g, int _startPosX, int _startPosY, Color bodyColor);
|
||||
public void drawBottomDeck(Graphics2D g, int _startPosX, int _startPosY, Color bodyColor);
|
||||
public void drawMiddleDeck(Graphics2D g, int _startPosX, int _startPosY, Color bodyColor);
|
||||
public void drawUpperDeck(Graphics2D g, int _startPosX, int _startPosY, Color bodyColor);
|
||||
}
|
228
ContainerShip/src/containership/JFrame_Map.form
Normal file
228
ContainerShip/src/containership/JFrame_Map.form
Normal file
@ -0,0 +1,228 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
|
||||
<Properties>
|
||||
<Property name="defaultCloseOperation" type="int" value="3"/>
|
||||
</Properties>
|
||||
<SyntheticProperties>
|
||||
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
|
||||
<SyntheticProperty name="generateCenter" type="boolean" value="false"/>
|
||||
</SyntheticProperties>
|
||||
<AuxValues>
|
||||
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
|
||||
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
|
||||
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
|
||||
</AuxValues>
|
||||
|
||||
<Layout>
|
||||
<DimensionLayout dim="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="ShipCanvas" alignment="0" max="32767" attributes="0"/>
|
||||
<Group type="102" attributes="0">
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="labelAmountOfDecks" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="buttonCreate" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" attributes="0">
|
||||
<Component id="comboBoxAmountOfDecks" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace type="separate" max="-2" attributes="0"/>
|
||||
<Component id="labelTypeOfDecks" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="comboBoxTypeOfDecks" min="-2" pref="124" max="-2" attributes="0"/>
|
||||
<EmptySpace max="32767" attributes="0"/>
|
||||
<Component id="buttonUp" min="-2" pref="35" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<Group type="102" attributes="0">
|
||||
<Component id="buttonModify" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="comboBoxMap" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace pref="58" max="32767" attributes="0"/>
|
||||
<Component id="buttonLeft" min="-2" pref="35" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="buttonDown" min="-2" pref="35" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="buttonRight" min="-2" pref="35" max="-2" attributes="0"/>
|
||||
<EmptySpace min="-2" pref="21" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<Component id="statusLabel" alignment="0" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
<DimensionLayout dim="1">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<Component id="ShipCanvas" min="-2" pref="407" max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<EmptySpace min="-2" pref="23" max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="3" attributes="0">
|
||||
<Component id="labelAmountOfDecks" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="comboBoxAmountOfDecks" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="labelTypeOfDecks" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="comboBoxTypeOfDecks" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace type="unrelated" max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="3" attributes="0">
|
||||
<Component id="buttonModify" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="buttonCreate" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="comboBoxMap" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace max="32767" attributes="0"/>
|
||||
</Group>
|
||||
<Group type="102" attributes="0">
|
||||
<EmptySpace pref="12" max="32767" attributes="0"/>
|
||||
<Component id="buttonUp" min="-2" pref="35" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="1" attributes="0">
|
||||
<Component id="buttonLeft" min="-2" pref="35" max="-2" attributes="0"/>
|
||||
<Component id="buttonRight" min="-2" pref="35" max="-2" attributes="0"/>
|
||||
<Component id="buttonDown" alignment="1" min="-2" pref="35" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace min="-2" pref="25" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
<Component id="statusLabel" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
</Layout>
|
||||
<SubComponents>
|
||||
<Container class="containership.MyCanvas" name="ShipCanvas">
|
||||
|
||||
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout">
|
||||
<Property name="useNullLayout" type="boolean" value="true"/>
|
||||
</Layout>
|
||||
</Container>
|
||||
<Component class="javax.swing.JLabel" name="labelAmountOfDecks">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Количество палуб"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component class="javax.swing.JComboBox" name="comboBoxAmountOfDecks">
|
||||
<Properties>
|
||||
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
|
||||
<StringArray count="3">
|
||||
<StringItem index="0" value="Одна"/>
|
||||
<StringItem index="1" value="Две"/>
|
||||
<StringItem index="2" value="Три"/>
|
||||
</StringArray>
|
||||
</Property>
|
||||
</Properties>
|
||||
<AuxValues>
|
||||
<AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="<String>"/>
|
||||
</AuxValues>
|
||||
</Component>
|
||||
<Component class="javax.swing.JLabel" name="labelTypeOfDecks">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Вид палуб"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component class="javax.swing.JComboBox" name="comboBoxTypeOfDecks">
|
||||
<Properties>
|
||||
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
|
||||
<StringArray count="3">
|
||||
<StringItem index="0" value="Квадраты"/>
|
||||
<StringItem index="1" value="Трапеции"/>
|
||||
<StringItem index="2" value="Перевернутые трапеции"/>
|
||||
</StringArray>
|
||||
</Property>
|
||||
</Properties>
|
||||
<AuxValues>
|
||||
<AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="<String>"/>
|
||||
</AuxValues>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="buttonCreate">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Создать"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="buttonCreateActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="buttonModify">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Модификация"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="buttonModifyActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="buttonLeft">
|
||||
<Properties>
|
||||
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
|
||||
<Image iconType="3" name="/containership/LeftArrow.png"/>
|
||||
</Property>
|
||||
<Property name="name" type="java.lang.String" value="buttonLeft" noResource="true"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="moveButtonActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="buttonUp">
|
||||
<Properties>
|
||||
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
|
||||
<Image iconType="3" name="/containership/UpArrow.png"/>
|
||||
</Property>
|
||||
<Property name="toolTipText" type="java.lang.String" value=""/>
|
||||
<Property name="name" type="java.lang.String" value="buttonUp" noResource="true"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="moveButtonActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="buttonRight">
|
||||
<Properties>
|
||||
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
|
||||
<Image iconType="3" name="/containership/Rightarrow.png"/>
|
||||
</Property>
|
||||
<Property name="name" type="java.lang.String" value="buttonRight" noResource="true"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="moveButtonActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="buttonDown">
|
||||
<Properties>
|
||||
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
|
||||
<Image iconType="3" name="/containership/DownArrow.png"/>
|
||||
</Property>
|
||||
<Property name="name" type="java.lang.String" value="buttonDown" noResource="true"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="moveButtonActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JComboBox" name="comboBoxMap">
|
||||
<Properties>
|
||||
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
|
||||
<StringArray count="2">
|
||||
<StringItem index="0" value="Простая карта"/>
|
||||
<StringItem index="1" value="Модифицированная карта"/>
|
||||
</StringArray>
|
||||
</Property>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="itemStateChanged" listener="java.awt.event.ItemListener" parameters="java.awt.event.ItemEvent" handler="comboBoxMapItemStateChanged"/>
|
||||
</Events>
|
||||
<AuxValues>
|
||||
<AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="<String>"/>
|
||||
</AuxValues>
|
||||
</Component>
|
||||
<Component class="javax.swing.JLabel" name="statusLabel">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Скорость: Вес: Цвет: Палубы:"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
</SubComponents>
|
||||
</Form>
|
308
ContainerShip/src/containership/JFrame_Map.java
Normal file
308
ContainerShip/src/containership/JFrame_Map.java
Normal file
@ -0,0 +1,308 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/JFrame.java to edit this template
|
||||
*/
|
||||
package containership;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.util.Random;
|
||||
import javax.swing.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ateks
|
||||
*/
|
||||
public class JFrame_Map extends javax.swing.JFrame {
|
||||
|
||||
/**
|
||||
* Creates new form JFrameMap
|
||||
*/
|
||||
public JFrame_Map() {
|
||||
initComponents();
|
||||
}
|
||||
private DrawingShip _ship;
|
||||
private AbstractMap _abstractMap = new SimpleMap();
|
||||
/**
|
||||
* This method is called from within the constructor to initialize the form.
|
||||
* WARNING: Do NOT modify this code. The content of this method is always
|
||||
* regenerated by the Form Editor.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
||||
private void initComponents() {
|
||||
|
||||
ShipCanvas = new containership.MyCanvas();
|
||||
labelAmountOfDecks = new javax.swing.JLabel();
|
||||
comboBoxAmountOfDecks = new javax.swing.JComboBox<>();
|
||||
labelTypeOfDecks = new javax.swing.JLabel();
|
||||
comboBoxTypeOfDecks = new javax.swing.JComboBox<>();
|
||||
buttonCreate = new javax.swing.JButton();
|
||||
buttonModify = new javax.swing.JButton();
|
||||
buttonLeft = new javax.swing.JButton();
|
||||
buttonUp = new javax.swing.JButton();
|
||||
buttonRight = new javax.swing.JButton();
|
||||
buttonDown = new javax.swing.JButton();
|
||||
comboBoxMap = new javax.swing.JComboBox<>();
|
||||
statusLabel = new javax.swing.JLabel();
|
||||
|
||||
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
|
||||
|
||||
labelAmountOfDecks.setText("Количество палуб");
|
||||
|
||||
comboBoxAmountOfDecks.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Одна", "Две", "Три" }));
|
||||
|
||||
labelTypeOfDecks.setText("Вид палуб");
|
||||
|
||||
comboBoxTypeOfDecks.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Квадраты", "Трапеции", "Перевернутые трапеции" }));
|
||||
|
||||
buttonCreate.setText("Создать");
|
||||
buttonCreate.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
buttonCreateActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
buttonModify.setText("Модификация");
|
||||
buttonModify.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
buttonModifyActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
buttonLeft.setIcon(new javax.swing.ImageIcon(getClass().getResource("/containership/LeftArrow.png"))); // NOI18N
|
||||
buttonLeft.setName("buttonLeft"); // NOI18N
|
||||
buttonLeft.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
moveButtonActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
buttonUp.setIcon(new javax.swing.ImageIcon(getClass().getResource("/containership/UpArrow.png"))); // NOI18N
|
||||
buttonUp.setToolTipText("");
|
||||
buttonUp.setName("buttonUp"); // NOI18N
|
||||
buttonUp.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
moveButtonActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
buttonRight.setIcon(new javax.swing.ImageIcon(getClass().getResource("/containership/Rightarrow.png"))); // NOI18N
|
||||
buttonRight.setName("buttonRight"); // NOI18N
|
||||
buttonRight.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
moveButtonActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
buttonDown.setIcon(new javax.swing.ImageIcon(getClass().getResource("/containership/DownArrow.png"))); // NOI18N
|
||||
buttonDown.setName("buttonDown"); // NOI18N
|
||||
buttonDown.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
moveButtonActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
comboBoxMap.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Простая карта", "Модифицированная карта" }));
|
||||
comboBoxMap.addItemListener(new java.awt.event.ItemListener() {
|
||||
public void itemStateChanged(java.awt.event.ItemEvent evt) {
|
||||
comboBoxMapItemStateChanged(evt);
|
||||
}
|
||||
});
|
||||
|
||||
statusLabel.setText("Скорость: Вес: Цвет: Палубы:");
|
||||
|
||||
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
|
||||
getContentPane().setLayout(layout);
|
||||
layout.setHorizontalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(ShipCanvas, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(labelAmountOfDecks)
|
||||
.addComponent(buttonCreate, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addComponent(comboBoxAmountOfDecks, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addGap(18, 18, 18)
|
||||
.addComponent(labelTypeOfDecks)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(comboBoxTypeOfDecks, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(buttonUp, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addComponent(buttonModify)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(comboBoxMap, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 58, Short.MAX_VALUE)
|
||||
.addComponent(buttonLeft, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(buttonDown, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(buttonRight, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addGap(21, 21, 21))
|
||||
.addComponent(statusLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
);
|
||||
layout.setVerticalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addComponent(ShipCanvas, javax.swing.GroupLayout.PREFERRED_SIZE, 407, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addGap(23, 23, 23)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(labelAmountOfDecks)
|
||||
.addComponent(comboBoxAmountOfDecks, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(labelTypeOfDecks)
|
||||
.addComponent(comboBoxTypeOfDecks, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(buttonModify)
|
||||
.addComponent(buttonCreate)
|
||||
.addComponent(comboBoxMap, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 12, Short.MAX_VALUE)
|
||||
.addComponent(buttonUp, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
|
||||
.addComponent(buttonLeft, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(buttonRight, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(buttonDown, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addGap(25, 25, 25)))
|
||||
.addComponent(statusLabel)
|
||||
.addContainerGap())
|
||||
);
|
||||
|
||||
pack();
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
|
||||
private void moveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_moveButtonActionPerformed
|
||||
if (_ship == null) return;
|
||||
String name = ((JButton) evt.getSource()).getName();
|
||||
Direction dir = Direction.NONE;
|
||||
switch (name)
|
||||
{
|
||||
case "buttonUp":
|
||||
dir = Direction.UP;
|
||||
break;
|
||||
case "buttonDown":
|
||||
dir = Direction.DOWN;
|
||||
break;
|
||||
case "buttonLeft":
|
||||
dir = Direction.LEFT;
|
||||
break;
|
||||
case "buttonRight":
|
||||
dir = Direction.RIGHT;
|
||||
break;
|
||||
}
|
||||
ShipCanvas.getGraphics().drawImage(_abstractMap.MoveObject(dir), 0, 0, null);
|
||||
}//GEN-LAST:event_moveButtonActionPerformed
|
||||
|
||||
private void comboBoxMapItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_comboBoxMapItemStateChanged
|
||||
switch (comboBoxMap.getSelectedIndex()){
|
||||
case 0:
|
||||
_abstractMap = new SimpleMap();
|
||||
break;
|
||||
case 1:
|
||||
_abstractMap = new ModifyMap();
|
||||
break;
|
||||
}
|
||||
}//GEN-LAST:event_comboBoxMapItemStateChanged
|
||||
|
||||
private void buttonCreateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonCreateActionPerformed
|
||||
Random rnd = new Random();
|
||||
DecksType selectedDecksType = null;
|
||||
switch(comboBoxTypeOfDecks.getSelectedItem().toString()){
|
||||
case "Квадраты":
|
||||
selectedDecksType = DecksType.RECTANGLE;
|
||||
break;
|
||||
case "Трапеции":
|
||||
selectedDecksType = DecksType.TROPEC;
|
||||
break;
|
||||
case "Перевернутые трапеции":
|
||||
selectedDecksType = DecksType.REVERSEDTR;
|
||||
break;
|
||||
}
|
||||
_ship = new DrawingShip(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000), new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256)), selectedDecksType, (comboBoxAmountOfDecks.getSelectedIndex() + 1));
|
||||
SetData();
|
||||
}//GEN-LAST:event_buttonCreateActionPerformed
|
||||
|
||||
private void buttonModifyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonModifyActionPerformed
|
||||
Random rnd = new Random();
|
||||
DecksType selectedDecksType = null;
|
||||
switch(comboBoxTypeOfDecks.getSelectedItem().toString()){
|
||||
case "Квадраты":
|
||||
selectedDecksType = DecksType.RECTANGLE;
|
||||
break;
|
||||
case "Трапеции":
|
||||
selectedDecksType = DecksType.TROPEC;
|
||||
break;
|
||||
case "Перевернутые трапеции":
|
||||
selectedDecksType = DecksType.REVERSEDTR;
|
||||
break;
|
||||
}
|
||||
_ship = new DrawingContainerShip(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000), new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256)), selectedDecksType, (comboBoxAmountOfDecks.getSelectedIndex() + 1), new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256)), rnd.nextBoolean(), rnd.nextBoolean());
|
||||
SetData();
|
||||
}//GEN-LAST:event_buttonModifyActionPerformed
|
||||
|
||||
private void SetData(){
|
||||
Random rnd = new Random();
|
||||
_ship.SetPosition(rnd.nextInt(10, 100), rnd.nextInt(10, 100), ShipCanvas.getWidth(), ShipCanvas.getHeight());
|
||||
statusLabel.setText("Скорость: " + _ship.getShip().getSpeed() + " Вес: " + (int) _ship.getShip().getWeight() + " Цвет: " + _ship.getShip().getBodyColor() + " Палубы: " + _ship.drawingDecks.getNumberOfDecks());
|
||||
ShipCanvas.setShip(_ship);
|
||||
ShipCanvas.getGraphics().drawImage(_abstractMap.CreateMap(ShipCanvas.getWidth() + 6, ShipCanvas.getHeight() + 3, new DrawingObjectShip(_ship)), 0, 0, null);
|
||||
}
|
||||
/**
|
||||
* @param args the command line arguments
|
||||
*/
|
||||
public static void main(String args[]) {
|
||||
/* Set the Nimbus look and feel */
|
||||
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
|
||||
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
|
||||
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
|
||||
*/
|
||||
try {
|
||||
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
|
||||
if ("Nimbus".equals(info.getName())) {
|
||||
javax.swing.UIManager.setLookAndFeel(info.getClassName());
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (ClassNotFoundException ex) {
|
||||
java.util.logging.Logger.getLogger(JFrame_Map.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||
} catch (InstantiationException ex) {
|
||||
java.util.logging.Logger.getLogger(JFrame_Map.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||
} catch (IllegalAccessException ex) {
|
||||
java.util.logging.Logger.getLogger(JFrame_Map.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
|
||||
java.util.logging.Logger.getLogger(JFrame_Map.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||
}
|
||||
//</editor-fold>
|
||||
//</editor-fold>
|
||||
|
||||
/* Create and display the form */
|
||||
java.awt.EventQueue.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
new JFrame_Map().setVisible(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private containership.MyCanvas ShipCanvas;
|
||||
private javax.swing.JButton buttonCreate;
|
||||
private javax.swing.JButton buttonDown;
|
||||
private javax.swing.JButton buttonLeft;
|
||||
private javax.swing.JButton buttonModify;
|
||||
private javax.swing.JButton buttonRight;
|
||||
private javax.swing.JButton buttonUp;
|
||||
private javax.swing.JComboBox<String> comboBoxAmountOfDecks;
|
||||
private javax.swing.JComboBox<String> comboBoxMap;
|
||||
private javax.swing.JComboBox<String> comboBoxTypeOfDecks;
|
||||
private javax.swing.JLabel labelAmountOfDecks;
|
||||
private javax.swing.JLabel labelTypeOfDecks;
|
||||
private javax.swing.JLabel statusLabel;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
}
|
@ -30,13 +30,20 @@
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" attributes="0">
|
||||
<Component id="buttonCreate" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace pref="381" max="32767" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="buttonModify" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="32767" attributes="0"/>
|
||||
<Component id="buttonLeft" min="-2" pref="35" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<Component id="labelAmountOfDecks" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="comboBoxAmountOfDecks" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="labelTypeOfDecks" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="comboBoxTypeOfDecks" min="-2" pref="140" max="-2" attributes="0"/>
|
||||
<EmptySpace min="0" pref="106" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
@ -70,9 +77,14 @@
|
||||
<Group type="103" groupAlignment="3" attributes="0">
|
||||
<Component id="labelAmountOfDecks" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="comboBoxAmountOfDecks" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="labelTypeOfDecks" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="comboBoxTypeOfDecks" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace type="unrelated" max="-2" attributes="0"/>
|
||||
<Component id="buttonCreate" min="-2" max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="3" attributes="0">
|
||||
<Component id="buttonCreate" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="buttonModify" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
<Group type="102" alignment="1" attributes="0">
|
||||
<Component id="buttonUp" min="-2" pref="35" max="-2" attributes="0"/>
|
||||
@ -181,5 +193,35 @@
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="moveButtonActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JLabel" name="labelTypeOfDecks">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Вид палуб"/>
|
||||
</Properties>
|
||||
<AccessibilityProperties>
|
||||
<Property name="AccessibleContext.accessibleName" type="java.lang.String" value=""/>
|
||||
</AccessibilityProperties>
|
||||
</Component>
|
||||
<Component class="javax.swing.JComboBox" name="comboBoxTypeOfDecks">
|
||||
<Properties>
|
||||
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
|
||||
<StringArray count="3">
|
||||
<StringItem index="0" value="Квадраты"/>
|
||||
<StringItem index="1" value="Трапеции"/>
|
||||
<StringItem index="2" value="Перевернутые трапеции"/>
|
||||
</StringArray>
|
||||
</Property>
|
||||
</Properties>
|
||||
<AuxValues>
|
||||
<AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="<String>"/>
|
||||
</AuxValues>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="buttonModify">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Модификация"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="buttonModifyActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
</SubComponents>
|
||||
</Form>
|
||||
|
@ -38,6 +38,9 @@ public class JFrame_Ship extends javax.swing.JFrame {
|
||||
buttonDown = new javax.swing.JButton();
|
||||
buttonRight = new javax.swing.JButton();
|
||||
buttonUp = new javax.swing.JButton();
|
||||
labelTypeOfDecks = new javax.swing.JLabel();
|
||||
comboBoxTypeOfDecks = new javax.swing.JComboBox<>();
|
||||
buttonModify = new javax.swing.JButton();
|
||||
|
||||
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
|
||||
|
||||
@ -93,6 +96,17 @@ public class JFrame_Ship extends javax.swing.JFrame {
|
||||
}
|
||||
});
|
||||
|
||||
labelTypeOfDecks.setText("Вид палуб");
|
||||
|
||||
comboBoxTypeOfDecks.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Квадраты", "Трапеции", "Перевернутые трапеции" }));
|
||||
|
||||
buttonModify.setText("Модификация");
|
||||
buttonModify.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
buttonModifyActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
|
||||
getContentPane().setLayout(layout);
|
||||
layout.setHorizontalGroup(
|
||||
@ -104,12 +118,19 @@ public class JFrame_Ship extends javax.swing.JFrame {
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addComponent(buttonCreate)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 381, Short.MAX_VALUE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(buttonModify)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(buttonLeft, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addComponent(labelAmountOfDecks)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(comboBoxAmountOfDecks, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
|
||||
.addComponent(comboBoxAmountOfDecks, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(labelTypeOfDecks)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(comboBoxTypeOfDecks, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addGap(0, 106, Short.MAX_VALUE)))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
@ -133,9 +154,13 @@ public class JFrame_Ship extends javax.swing.JFrame {
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(labelAmountOfDecks)
|
||||
.addComponent(comboBoxAmountOfDecks, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addComponent(comboBoxAmountOfDecks, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(labelTypeOfDecks)
|
||||
.addComponent(comboBoxTypeOfDecks, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
|
||||
.addComponent(buttonCreate))
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(buttonCreate)
|
||||
.addComponent(buttonModify)))
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
||||
.addComponent(buttonUp, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
@ -149,17 +174,27 @@ public class JFrame_Ship extends javax.swing.JFrame {
|
||||
);
|
||||
|
||||
labelAmountOfDecks.getAccessibleContext().setAccessibleName("");
|
||||
labelTypeOfDecks.getAccessibleContext().setAccessibleName("");
|
||||
|
||||
pack();
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
|
||||
private void buttonCreateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonCreateActionPerformed
|
||||
Random rnd = new Random();
|
||||
_ship = new DrawingShip();
|
||||
_ship.Init(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000), new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256)), (comboBoxAmountOfDecks.getSelectedIndex() + 1));
|
||||
_ship.SetPosition(rnd.nextInt(10, 100), rnd.nextInt(10, 100), ShipCanvas.getWidth(), ShipCanvas.getHeight());
|
||||
statusLabel.setText("Скорость: " + _ship.getShip().getSpeed() + " Вес: " + (int) _ship.getShip().getWeight() + " Цвет: " + _ship.getShip().getBodyColor() + " Палубы: " + _ship.drawingDecks.getNumberOfDecks());
|
||||
ShipCanvas.setShip(_ship);
|
||||
DecksType selectedDecksType = null;
|
||||
switch(comboBoxTypeOfDecks.getSelectedItem().toString()){
|
||||
case "Квадраты":
|
||||
selectedDecksType = DecksType.RECTANGLE;
|
||||
break;
|
||||
case "Трапеции":
|
||||
selectedDecksType = DecksType.TROPEC;
|
||||
break;
|
||||
case "Перевернутые трапеции":
|
||||
selectedDecksType = DecksType.REVERSEDTR;
|
||||
break;
|
||||
}
|
||||
_ship = new DrawingShip(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000), new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256)), selectedDecksType, (comboBoxAmountOfDecks.getSelectedIndex() + 1));
|
||||
SetData();
|
||||
Draw();
|
||||
}//GEN-LAST:event_buttonCreateActionPerformed
|
||||
|
||||
@ -189,9 +224,35 @@ public class JFrame_Ship extends javax.swing.JFrame {
|
||||
_ship.ChangeBorders(ShipCanvas.getWidth(), ShipCanvas.getHeight());
|
||||
}//GEN-LAST:event_ShipCanvasComponentResized
|
||||
|
||||
private void buttonModifyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonModifyActionPerformed
|
||||
Random rnd = new Random();
|
||||
DecksType selectedDecksType = null;
|
||||
switch(comboBoxTypeOfDecks.getSelectedItem().toString()){
|
||||
case "Квадраты":
|
||||
selectedDecksType = DecksType.RECTANGLE;
|
||||
break;
|
||||
case "Трапеции":
|
||||
selectedDecksType = DecksType.TROPEC;
|
||||
break;
|
||||
case "Перевернутые трапеции":
|
||||
selectedDecksType = DecksType.REVERSEDTR;
|
||||
break;
|
||||
}
|
||||
_ship = new DrawingContainerShip(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000), new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256)), selectedDecksType, (comboBoxAmountOfDecks.getSelectedIndex() + 1), new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256)), rnd.nextBoolean(), rnd.nextBoolean());
|
||||
SetData();
|
||||
Draw();
|
||||
}//GEN-LAST:event_buttonModifyActionPerformed
|
||||
|
||||
private void Draw(){
|
||||
ShipCanvas.repaint();
|
||||
}
|
||||
|
||||
private void SetData(){
|
||||
Random rnd = new Random();
|
||||
_ship.SetPosition(rnd.nextInt(10, 100), rnd.nextInt(10, 100), ShipCanvas.getWidth(), ShipCanvas.getHeight());
|
||||
statusLabel.setText("Скорость: " + _ship.getShip().getSpeed() + " Вес: " + (int) _ship.getShip().getWeight() + " Цвет: " + _ship.getShip().getBodyColor() + " Палубы: " + _ship.drawingDecks.getNumberOfDecks());
|
||||
ShipCanvas.setShip(_ship);
|
||||
}
|
||||
/**
|
||||
* @param args the command line arguments
|
||||
*/
|
||||
@ -222,7 +283,7 @@ public class JFrame_Ship extends javax.swing.JFrame {
|
||||
/* Create and display the form */
|
||||
java.awt.EventQueue.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
new JFrame_Ship().setVisible(true);
|
||||
new JFrame_Map().setVisible(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -232,10 +293,13 @@ public class JFrame_Ship extends javax.swing.JFrame {
|
||||
private javax.swing.JButton buttonCreate;
|
||||
private javax.swing.JButton buttonDown;
|
||||
private javax.swing.JButton buttonLeft;
|
||||
private javax.swing.JButton buttonModify;
|
||||
private javax.swing.JButton buttonRight;
|
||||
private javax.swing.JButton buttonUp;
|
||||
private javax.swing.JComboBox<String> comboBoxAmountOfDecks;
|
||||
private javax.swing.JComboBox<String> comboBoxTypeOfDecks;
|
||||
private javax.swing.JLabel labelAmountOfDecks;
|
||||
private javax.swing.JLabel labelTypeOfDecks;
|
||||
private javax.swing.JLabel statusLabel;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
}
|
||||
|
61
ContainerShip/src/containership/ModifyMap.java
Normal file
61
ContainerShip/src/containership/ModifyMap.java
Normal file
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package containership;
|
||||
import java.awt.*;
|
||||
/**
|
||||
*
|
||||
* @author ateks
|
||||
*/
|
||||
public class ModifyMap extends AbstractMap {
|
||||
private final Color barrierColor = Color.GRAY;
|
||||
private final Color roadColor = Color.BLUE;
|
||||
|
||||
@Override
|
||||
protected void DrawBarrierPart(Graphics g, int i, int j)
|
||||
{
|
||||
g.setColor(barrierColor);
|
||||
g.fillRect(i * _size_x, j * _size_y, _size_x, _size_y);
|
||||
g.setColor(Color.BLACK);
|
||||
}
|
||||
@Override
|
||||
protected void DrawRoadPart(Graphics g, int i, int j)
|
||||
{
|
||||
g.setColor(roadColor);
|
||||
g.fillRect(i * _size_x, j * _size_y, _size_x, _size_y);
|
||||
g.setColor(Color.BLACK);
|
||||
}
|
||||
@Override
|
||||
protected void GenerateMap()
|
||||
{
|
||||
int pointY;
|
||||
int firstPointX;
|
||||
int secondPointX;
|
||||
_map = new int[100][100];
|
||||
_size_x = _width / _map.length;
|
||||
_size_y = _height / _map[0].length;
|
||||
int counter = 0;
|
||||
while(counter < 15)
|
||||
{
|
||||
boolean freePlace = true;
|
||||
firstPointX = _random.nextInt(0, _map.length-10);
|
||||
secondPointX = _random.nextInt(firstPointX, _map.length-10);
|
||||
pointY = _random.nextInt(0, _map[0].length-10);
|
||||
for(int i = firstPointX; i <secondPointX; i++)
|
||||
{
|
||||
if (_map[i][pointY] == _barrier)
|
||||
{
|
||||
freePlace = false;
|
||||
break;
|
||||
}
|
||||
_map[i][pointY] = _barrier;
|
||||
}
|
||||
if (freePlace)
|
||||
{
|
||||
counter++;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
60
ContainerShip/src/containership/SimpleMap.java
Normal file
60
ContainerShip/src/containership/SimpleMap.java
Normal file
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package containership;
|
||||
import java.awt.*;
|
||||
/**
|
||||
*
|
||||
* @author ateks
|
||||
*/
|
||||
public class SimpleMap extends AbstractMap {
|
||||
/// <summary>
|
||||
/// Цвет участка закрытого
|
||||
/// </summary>
|
||||
private final Color barrierColor = Color.BLACK;
|
||||
/// <summary>
|
||||
/// Цвет участка открытого
|
||||
/// </summary>
|
||||
private final Color roadColor = Color.GRAY;
|
||||
|
||||
@Override
|
||||
protected void DrawBarrierPart(Graphics g, int i, int j)
|
||||
{
|
||||
g.setColor(barrierColor);
|
||||
g.fillRect(i * _size_x, j * _size_y, _size_x, _size_y);
|
||||
g.setColor(Color.BLACK);
|
||||
}
|
||||
@Override
|
||||
protected void DrawRoadPart(Graphics g, int i, int j)
|
||||
{
|
||||
g.setColor(roadColor);
|
||||
g.fillRect(i * _size_x, j * _size_y, _size_x, _size_y);
|
||||
g.setColor(Color.BLACK);
|
||||
}
|
||||
@Override
|
||||
protected void GenerateMap()
|
||||
{
|
||||
_map = new int[100][100];
|
||||
_size_x = _width / _map.length;
|
||||
_size_y = _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++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user