Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
bed425b6e1 | |||
|
e732147b23 | ||
|
6aa347f8eb | ||
|
cf1bbe3133 | ||
|
6d2ced70f7 | ||
|
33b6eb7cc2 | ||
|
d8bc8f2549 |
BIN
res/down.png
Normal file
BIN
res/down.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 321 B |
BIN
res/left.png
Normal file
BIN
res/left.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 270 B |
BIN
res/right.png
Normal file
BIN
res/right.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 266 B |
BIN
res/up.png
Normal file
BIN
res/up.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 304 B |
61
src/CollectionAdditionalObjects/AdditionalCollections.java
Normal file
61
src/CollectionAdditionalObjects/AdditionalCollections.java
Normal file
@ -0,0 +1,61 @@
|
||||
package CollectionAdditionalObjects;
|
||||
|
||||
import DifferentRollers.IDifferentRollers;
|
||||
import Drawings.DrawingBulldozer;
|
||||
import Drawings.DrawingExcavator;
|
||||
import Entities.EntityBulldozer;
|
||||
import Entities.EntityExcavator;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.Random;
|
||||
|
||||
public class AdditionalCollections <T extends EntityBulldozer, U extends IDifferentRollers>{
|
||||
public T[] _collectionEntity;
|
||||
public U[] _collectionRollers;
|
||||
public AdditionalCollections(int size, Class<T> type1, Class<T> type2) {
|
||||
_collectionEntity = (T[]) Array.newInstance(type1, size);
|
||||
_collectionRollers = (U[]) Array.newInstance(type2, size);
|
||||
CountEntities = size;
|
||||
CountRollers = size;
|
||||
}
|
||||
public int CountEntities;
|
||||
public int CountRollers;
|
||||
public int Insert(T entity) {
|
||||
int index = 0;
|
||||
while (index < CountEntities) {
|
||||
if (_collectionEntity[index] == null)
|
||||
{
|
||||
_collectionEntity[index] = entity;
|
||||
return index;
|
||||
}
|
||||
++index;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
public int Insert(U rollers) {
|
||||
int index = 0;
|
||||
while (index < CountRollers) {
|
||||
if (_collectionRollers[index] == null)
|
||||
{
|
||||
_collectionRollers[index] = rollers;
|
||||
return index;
|
||||
}
|
||||
++index;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
public DrawingBulldozer CreateAdditionalCollectionBulldozer() {
|
||||
Random random = new Random();
|
||||
if (_collectionEntity == null || _collectionRollers == null) return null;
|
||||
T entity = _collectionEntity[random.nextInt(CountEntities)];
|
||||
U rollers = _collectionRollers[random.nextInt(CountRollers)];
|
||||
DrawingBulldozer drawingBulldozer = null;
|
||||
if (entity instanceof EntityExcavator) {
|
||||
drawingBulldozer = new DrawingExcavator((EntityExcavator) entity, rollers);
|
||||
}
|
||||
else {
|
||||
drawingBulldozer = new DrawingBulldozer(entity, rollers);
|
||||
}
|
||||
return drawingBulldozer;
|
||||
}
|
||||
}
|
34
src/CollectionGenericObjects/AbstractCompany.java
Normal file
34
src/CollectionGenericObjects/AbstractCompany.java
Normal file
@ -0,0 +1,34 @@
|
||||
package CollectionGenericObjects;
|
||||
|
||||
import Drawings.DrawingBulldozer;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public abstract class AbstractCompany {
|
||||
protected int _placeSizeWidth = 195;
|
||||
protected int _placeSizeHeight = 80;
|
||||
protected int _pictureWidth;
|
||||
protected int _pictureHeight;
|
||||
public ICollectionGenericObjects<DrawingBulldozer> _collection = null;
|
||||
private int GetMaxCount() {
|
||||
return _pictureWidth * _pictureHeight / (_placeSizeWidth * _placeSizeHeight);
|
||||
}
|
||||
public AbstractCompany(int picWidth, int picHeight, ICollectionGenericObjects<DrawingBulldozer> collection)
|
||||
{
|
||||
_pictureWidth = picWidth;
|
||||
_pictureHeight = picHeight;
|
||||
_collection = collection;
|
||||
_collection.SetMaxCount(GetMaxCount());
|
||||
}
|
||||
//перегрузка операторов в джаве невозможна
|
||||
public DrawingBulldozer GetRandomObject()
|
||||
{
|
||||
return _collection.Get((int)(Math.random()*GetMaxCount()));
|
||||
}
|
||||
public void SetPosition()
|
||||
{
|
||||
SetObjectsPosition();
|
||||
}
|
||||
public abstract void DrawBackground(Graphics graphics);
|
||||
protected abstract void SetObjectsPosition();
|
||||
}
|
49
src/CollectionGenericObjects/BulldozerSharingService.java
Normal file
49
src/CollectionGenericObjects/BulldozerSharingService.java
Normal file
@ -0,0 +1,49 @@
|
||||
package CollectionGenericObjects;
|
||||
|
||||
import Drawings.DrawingBulldozer;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class BulldozerSharingService extends AbstractCompany{
|
||||
public BulldozerSharingService(int picWidth, int picHeight, ICollectionGenericObjects<DrawingBulldozer> collection) {
|
||||
super(picWidth, picHeight, collection);
|
||||
}
|
||||
@Override
|
||||
public void DrawBackground(Graphics g) {
|
||||
int width = _pictureWidth / _placeSizeWidth;
|
||||
int height = _pictureHeight / _placeSizeHeight;
|
||||
g.setColor(Color.BLACK);
|
||||
for (int i = 0; i < width; i++)
|
||||
{
|
||||
for (int j = 0; j < height + 1; ++j)
|
||||
{
|
||||
g.drawLine(i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight);
|
||||
}
|
||||
g.drawLine(i * _placeSizeWidth, 0, i * _placeSizeWidth, _pictureHeight);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
protected void SetObjectsPosition() {
|
||||
int width = _pictureWidth / _placeSizeWidth;
|
||||
int height = _pictureHeight / _placeSizeHeight;
|
||||
|
||||
int posWidth = width - 1;
|
||||
int posHeight = 0;
|
||||
for (int i = 0; i < (_collection.getCount()); i++) {
|
||||
if (_collection.Get(i) != null) {
|
||||
_collection.Get(i).SetPictureSize(_pictureWidth, _pictureHeight);
|
||||
_collection.Get(i).SetPosition(_placeSizeWidth * posWidth + 4, posHeight * _placeSizeHeight + 4);
|
||||
}
|
||||
if (posWidth > 0)
|
||||
posWidth--;
|
||||
else {
|
||||
posWidth = width - 1;
|
||||
posHeight++;
|
||||
}
|
||||
if (posHeight > height) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
7
src/CollectionGenericObjects/CollectionType.java
Normal file
7
src/CollectionGenericObjects/CollectionType.java
Normal file
@ -0,0 +1,7 @@
|
||||
package CollectionGenericObjects;
|
||||
|
||||
public enum CollectionType {
|
||||
None,
|
||||
Massive,
|
||||
List
|
||||
}
|
11
src/CollectionGenericObjects/ICollectionGenericObjects.java
Normal file
11
src/CollectionGenericObjects/ICollectionGenericObjects.java
Normal file
@ -0,0 +1,11 @@
|
||||
package CollectionGenericObjects;
|
||||
|
||||
public interface ICollectionGenericObjects<T>
|
||||
{
|
||||
int getCount();
|
||||
void SetMaxCount(int count);
|
||||
int Insert(T obj);
|
||||
T Remove(int position);
|
||||
T Get(int position);
|
||||
}
|
||||
|
41
src/CollectionGenericObjects/ListGenericObjects.java
Normal file
41
src/CollectionGenericObjects/ListGenericObjects.java
Normal file
@ -0,0 +1,41 @@
|
||||
package CollectionGenericObjects;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
public class ListGenericObjects<T> implements ICollectionGenericObjects<T> {
|
||||
private List<T> _collection;
|
||||
private int _maxCount;
|
||||
public int getCount() {
|
||||
return _collection.size();
|
||||
}
|
||||
@Override
|
||||
public void SetMaxCount(int size) {
|
||||
if (size > 0) {
|
||||
_maxCount = size;
|
||||
}
|
||||
}
|
||||
public ListGenericObjects() {
|
||||
_collection = new ArrayList<T>();
|
||||
}
|
||||
@Override
|
||||
public T Get(int position)
|
||||
{
|
||||
if (position >= getCount() || position < 0) return null;
|
||||
return _collection.get(position);
|
||||
}
|
||||
@Override
|
||||
public int Insert(T obj)
|
||||
{
|
||||
if (getCount() == _maxCount) return -1;
|
||||
_collection.add(obj);
|
||||
return getCount();
|
||||
}
|
||||
@Override
|
||||
public T Remove(int position)
|
||||
{
|
||||
if (position >= getCount() || position < 0) return null;
|
||||
T obj = _collection.get(position);
|
||||
_collection.remove(position);
|
||||
return obj;
|
||||
}
|
||||
}
|
49
src/CollectionGenericObjects/MassiveGenericObjects.java
Normal file
49
src/CollectionGenericObjects/MassiveGenericObjects.java
Normal file
@ -0,0 +1,49 @@
|
||||
package CollectionGenericObjects;
|
||||
|
||||
import Drawings.DrawingBulldozer;
|
||||
import java.lang.reflect.Array;
|
||||
|
||||
public class MassiveGenericObjects<T> implements ICollectionGenericObjects<T>{
|
||||
private T[] _collection = null;
|
||||
private int Count;
|
||||
@Override
|
||||
public void SetMaxCount(int size) {
|
||||
if (size > 0) {
|
||||
if (_collection == null){
|
||||
_collection = (T[]) Array.newInstance((Class) DrawingBulldozer.class, size);
|
||||
Count = size;
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public int getCount() {
|
||||
return Count;
|
||||
}
|
||||
@Override
|
||||
public int Insert(T obj) {
|
||||
int index = 0;
|
||||
while (index < getCount())
|
||||
{
|
||||
if (_collection[index] == null)
|
||||
{
|
||||
_collection[index] = obj;
|
||||
return index;
|
||||
}
|
||||
++index;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
@Override
|
||||
public T Remove(int position) {
|
||||
if (position >= getCount() || position < 0)
|
||||
return null;
|
||||
T obj = (T) _collection[position];
|
||||
_collection[position] = null;
|
||||
return obj;
|
||||
}
|
||||
@Override
|
||||
public T Get(int position) {
|
||||
if (position >= getCount() || position < 0) return null;
|
||||
return (T) _collection[position];
|
||||
}
|
||||
}
|
41
src/CollectionGenericObjects/StorageCollection.java
Normal file
41
src/CollectionGenericObjects/StorageCollection.java
Normal file
@ -0,0 +1,41 @@
|
||||
package CollectionGenericObjects;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class StorageCollection<T> {
|
||||
private Map<String, ICollectionGenericObjects<T>> _storages;
|
||||
public StorageCollection()
|
||||
{
|
||||
_storages = new HashMap<String, ICollectionGenericObjects<T>>();
|
||||
}
|
||||
public Set<String> Keys() {
|
||||
Set<String> keys = _storages.keySet();
|
||||
return keys;
|
||||
}
|
||||
public void AddCollection(String name, CollectionType collectionType)
|
||||
{
|
||||
if (_storages.containsKey(name)) return;
|
||||
if (collectionType == CollectionType.None) return;
|
||||
else if (collectionType == CollectionType.Massive)
|
||||
_storages.put(name, new MassiveGenericObjects<T>());
|
||||
else if (collectionType == CollectionType.List)
|
||||
_storages.put(name, new ListGenericObjects<T>());
|
||||
}
|
||||
public void DelCollection(String name)
|
||||
{
|
||||
if (_storages.containsKey(name))
|
||||
_storages.remove(name);
|
||||
}
|
||||
// в джаве отсутствуют индикаторы
|
||||
public ICollectionGenericObjects<T> getCollectionObject(String name) {
|
||||
if (_storages.containsKey(name))
|
||||
return _storages.get(name);
|
||||
return null;
|
||||
}
|
||||
//дополнительное задание 1
|
||||
public T Get(String name, int position){
|
||||
if(_storages.containsKey(name))
|
||||
return _storages.get(name).Remove(position);
|
||||
return null;
|
||||
}
|
||||
}
|
32
src/DifferentRollers/DrawingRollersCross.java
Normal file
32
src/DifferentRollers/DrawingRollersCross.java
Normal file
@ -0,0 +1,32 @@
|
||||
package DifferentRollers;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawingRollersCross implements IDifferentRollers{
|
||||
private RollersCount rollersCount;
|
||||
@Override
|
||||
public void setRollersCount(int numOfRoller){
|
||||
for (RollersCount numofenum : RollersCount.values()){
|
||||
if (numofenum.getNumOfRollers() == numOfRoller){
|
||||
rollersCount = numofenum;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public RollersCount getRollersCount(){
|
||||
return rollersCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void DrawRollers(Graphics2D g, int x, int y, int width, int height, Color bodyColor){
|
||||
g.setColor(bodyColor);
|
||||
g.fillOval(x, y, width, height);
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawLine(x+2, y+2, x+6, y+6);
|
||||
g.drawLine(x+2, y+6, x+6, y+2);
|
||||
g.drawOval(x, y, width, height);
|
||||
g.setColor(bodyColor);
|
||||
}
|
||||
}
|
32
src/DifferentRollers/DrawingRollersPlus.java
Normal file
32
src/DifferentRollers/DrawingRollersPlus.java
Normal file
@ -0,0 +1,32 @@
|
||||
package DifferentRollers;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawingRollersPlus implements IDifferentRollers{
|
||||
private RollersCount rollersCount;
|
||||
@Override
|
||||
public void setRollersCount(int numOfRoller){
|
||||
for (RollersCount numofenum : RollersCount.values()){
|
||||
if (numofenum.getNumOfRollers() == numOfRoller){
|
||||
rollersCount = numofenum;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public RollersCount getRollersCount(){
|
||||
return rollersCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void DrawRollers(Graphics2D g, int x, int y, int width, int height, Color bodyColor){
|
||||
g.setColor(bodyColor);
|
||||
g.fillOval(x, y, width, height);
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawLine(x+4, y, x+4, y+8);
|
||||
g.drawLine(x, y+4, x+8, y+4);
|
||||
g.drawOval(x, y, width, height);
|
||||
g.setColor(bodyColor);
|
||||
}
|
||||
}
|
34
src/DifferentRollers/DrawingRollersStar.java
Normal file
34
src/DifferentRollers/DrawingRollersStar.java
Normal file
@ -0,0 +1,34 @@
|
||||
package DifferentRollers;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawingRollersStar implements IDifferentRollers{
|
||||
private RollersCount rollersCount;
|
||||
@Override
|
||||
public void setRollersCount(int numOfRoller){
|
||||
for (RollersCount numofenum : RollersCount.values()){
|
||||
if (numofenum.getNumOfRollers() == numOfRoller){
|
||||
rollersCount = numofenum;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public RollersCount getRollersCount(){
|
||||
return rollersCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void DrawRollers(Graphics2D g, int x, int y, int width, int height, Color bodyColor){
|
||||
g.setColor(bodyColor);
|
||||
g.fillOval(x, y, width, height);
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawLine(x+4, y, x+4, y+8);
|
||||
g.drawLine(x, y+4, x+8, y+4);
|
||||
g.drawLine(x+2, y+2, x+6, y+6);
|
||||
g.drawLine(x+2, y+6, x+6, y+2);
|
||||
g.drawOval(x, y, width, height);
|
||||
g.setColor(bodyColor);
|
||||
}
|
||||
}
|
9
src/DifferentRollers/IDifferentRollers.java
Normal file
9
src/DifferentRollers/IDifferentRollers.java
Normal file
@ -0,0 +1,9 @@
|
||||
package DifferentRollers;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public interface IDifferentRollers {
|
||||
void setRollersCount(int numOfRoller);
|
||||
RollersCount getRollersCount();
|
||||
void DrawRollers(Graphics2D g, int x, int y, int width, int height, Color bodyColor);
|
||||
}
|
14
src/DifferentRollers/RollersCount.java
Normal file
14
src/DifferentRollers/RollersCount.java
Normal file
@ -0,0 +1,14 @@
|
||||
package DifferentRollers;
|
||||
|
||||
public enum RollersCount {
|
||||
OneRoller(1),
|
||||
TwoRollers(2),
|
||||
ThreeRollers(3);
|
||||
private int numOfRollers;
|
||||
RollersCount(int numOfRollers){
|
||||
this.numOfRollers = numOfRollers;
|
||||
}
|
||||
public int getNumOfRollers(){
|
||||
return numOfRollers;
|
||||
}
|
||||
}
|
18
src/Drawings/CanvasExcavator.java
Normal file
18
src/Drawings/CanvasExcavator.java
Normal file
@ -0,0 +1,18 @@
|
||||
package Drawings;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class CanvasExcavator extends JComponent{
|
||||
public DrawingBulldozer _drawingBulldozer;
|
||||
public CanvasExcavator(){}
|
||||
public void paintComponent(Graphics g){
|
||||
if(_drawingBulldozer == null){
|
||||
return;
|
||||
}
|
||||
super.paintComponent(g);
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
_drawingBulldozer.DrawTransport(g2d);
|
||||
super.repaint();
|
||||
}
|
||||
}
|
34
src/Drawings/CanvasFormBulldozerCollection.java
Normal file
34
src/Drawings/CanvasFormBulldozerCollection.java
Normal file
@ -0,0 +1,34 @@
|
||||
package Drawings;
|
||||
|
||||
import CollectionGenericObjects.AbstractCompany;
|
||||
import CollectionGenericObjects.ICollectionGenericObjects;
|
||||
import CollectionGenericObjects.MassiveGenericObjects;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class CanvasFormBulldozerCollection<T> extends JComponent
|
||||
{
|
||||
public AbstractCompany company = null;
|
||||
public void SetCollectionToCanvas(AbstractCompany company) {
|
||||
this.company = company;
|
||||
}
|
||||
public CanvasFormBulldozerCollection(){}
|
||||
public void paintComponent(Graphics g) {
|
||||
super.paintComponents(g);
|
||||
if (company == null || company._collection == null) {
|
||||
return;
|
||||
}
|
||||
company.DrawBackground(g);
|
||||
for (int i = 0; i < company._collection.getCount(); i++) {
|
||||
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
T obj = (T)company._collection.Get(i);
|
||||
if (obj instanceof DrawingBulldozer) {
|
||||
((DrawingBulldozer) obj).DrawTransport(g2d);
|
||||
}
|
||||
}
|
||||
super.repaint();
|
||||
}
|
||||
}
|
||||
|
9
src/Drawings/DirectionType.java
Normal file
9
src/Drawings/DirectionType.java
Normal file
@ -0,0 +1,9 @@
|
||||
package Drawings;
|
||||
|
||||
public enum DirectionType {
|
||||
Unknow,
|
||||
Up,
|
||||
Down,
|
||||
Left,
|
||||
Right
|
||||
}
|
202
src/Drawings/DrawingBulldozer.java
Normal file
202
src/Drawings/DrawingBulldozer.java
Normal file
@ -0,0 +1,202 @@
|
||||
package Drawings;
|
||||
|
||||
import DifferentRollers.DrawingRollersCross;
|
||||
import DifferentRollers.DrawingRollersPlus;
|
||||
import DifferentRollers.DrawingRollersStar;
|
||||
import DifferentRollers.IDifferentRollers;
|
||||
import Entities.EntityBulldozer;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.Random;
|
||||
|
||||
public class DrawingBulldozer extends JPanel {
|
||||
public Entities.EntityBulldozer EntityBulldozer;
|
||||
public IDifferentRollers drawingRollers;
|
||||
public Integer _startPosX; // Левая координата отрисовки
|
||||
public Integer _startPosY; // Верхняя координата отрисовки
|
||||
private Integer _pictureWidth; // Ширина окна отрисовки
|
||||
private Integer _pictureHeight; // Высота окна отрисовки
|
||||
protected int _drawingExcWidth = 120; // Ширина отрисовки трактора
|
||||
protected int _drawingExcHeight = 70; // Высота отрисовки трактора
|
||||
public Integer GetPosX(){return _startPosX;}
|
||||
public Integer GetPosY(){return _startPosY;}
|
||||
public Integer GetWidth(){return _drawingExcWidth;}
|
||||
public Integer GetHeight(){return _drawingExcHeight;}
|
||||
|
||||
protected DrawingBulldozer(){
|
||||
_pictureWidth = null;
|
||||
_pictureHeight = null;
|
||||
_startPosX = null;
|
||||
_startPosY = null;
|
||||
}
|
||||
|
||||
protected void SetTypeRollers(){
|
||||
int rollersCount = (int)(Math.random()*4);
|
||||
switch ((int)(Math.random()*3+1)){
|
||||
case 1:
|
||||
drawingRollers = new DrawingRollersCross();
|
||||
break;
|
||||
case 2:
|
||||
drawingRollers = new DrawingRollersPlus();
|
||||
break;
|
||||
case 3:
|
||||
drawingRollers = new DrawingRollersStar();
|
||||
break;
|
||||
default:
|
||||
rollersCount = 0;
|
||||
break;
|
||||
}
|
||||
drawingRollers.setRollersCount(rollersCount);
|
||||
}
|
||||
|
||||
public DrawingBulldozer(int speed, double weight, Color bodyColor){
|
||||
super();
|
||||
EntityBulldozer = new EntityBulldozer(speed, weight, bodyColor);
|
||||
SetTypeRollers();
|
||||
}
|
||||
|
||||
protected DrawingBulldozer(int _drawingExcWidth, int _drawingExcHeight) {
|
||||
super();
|
||||
this._drawingExcWidth = _drawingExcWidth;
|
||||
this._drawingExcHeight = _drawingExcHeight;
|
||||
}
|
||||
|
||||
public DrawingBulldozer(EntityBulldozer entity, IDifferentRollers rollers) {
|
||||
EntityBulldozer = entity;
|
||||
drawingRollers = rollers;
|
||||
}
|
||||
|
||||
// Смена границ формы отрисовки
|
||||
public void SetPictureSize(int width, int height)
|
||||
{
|
||||
if (_drawingExcWidth > width || _drawingExcHeight > height)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (_startPosX != null && _startPosY != null) {
|
||||
if (_startPosX < 0) { _startPosX = 0; }
|
||||
if (_startPosX + _drawingExcWidth > width) { _startPosX = width - _drawingExcWidth; }
|
||||
if (_startPosY < 0) { _startPosY = 0; }
|
||||
if (_startPosY + _drawingExcHeight > height) { _startPosY = height - _drawingExcHeight; }
|
||||
}
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
}
|
||||
|
||||
//Установка позиции Экскаватора
|
||||
public void SetPosition(int x, int y){
|
||||
if (_pictureWidth == null || _pictureHeight == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (x + _drawingExcWidth > _pictureWidth || x < 0) {
|
||||
Random random = new Random();
|
||||
_startPosX = random.nextInt(_pictureWidth - _drawingExcWidth);
|
||||
}
|
||||
else {
|
||||
_startPosX = x;
|
||||
}
|
||||
|
||||
if (y + _drawingExcHeight > _pictureHeight || y < 0) {
|
||||
Random random = new Random();
|
||||
_startPosY = random.nextInt(_pictureHeight - _drawingExcHeight);
|
||||
}
|
||||
else {
|
||||
_startPosY = y;
|
||||
}
|
||||
}
|
||||
|
||||
// Изменение направления движения
|
||||
public boolean MoveTransport(DirectionType direction){
|
||||
if (EntityBulldozer == null || _startPosX == null || _startPosY == null){
|
||||
return false;
|
||||
}
|
||||
switch (direction) {
|
||||
case Left:
|
||||
if (_startPosX - EntityBulldozer.Step > 0) {
|
||||
_startPosX -= (int) EntityBulldozer.Step;
|
||||
}
|
||||
return true;
|
||||
case Up:
|
||||
if (_startPosY - EntityBulldozer.Step > 0) {
|
||||
_startPosY -= (int) EntityBulldozer.Step;
|
||||
}
|
||||
return true;
|
||||
case Right:
|
||||
if (_startPosX + EntityBulldozer.Step < _pictureWidth - _drawingExcWidth) {
|
||||
_startPosX += (int) EntityBulldozer.Step;
|
||||
}
|
||||
return true;
|
||||
case Down:
|
||||
if (_startPosY + EntityBulldozer.Step < _pictureHeight - _drawingExcHeight) {
|
||||
_startPosY += (int) EntityBulldozer.Step;
|
||||
}
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Отрисовка Экскаватора
|
||||
public void DrawTransport(Graphics2D g){
|
||||
if (EntityBulldozer == null || _startPosX == null || _startPosY == null){
|
||||
return;
|
||||
}
|
||||
|
||||
// Границы экскаватора
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawRect(_startPosX + 20, _startPosY + 25, 60, 20); // главная нижняя
|
||||
g.drawRect(_startPosX + 35, _startPosY + 10, 5, 15);
|
||||
g.drawRect(_startPosX + 55, _startPosY + 3, 22, 22); // кабина
|
||||
|
||||
g.setColor(EntityBulldozer.getBodyColor());
|
||||
g.fillRect(_startPosX + 21, _startPosY + 26, 59, 19);
|
||||
g.fillRect(_startPosX + 36, _startPosY + 11, 4, 14);
|
||||
|
||||
g.setColor(Color.cyan);
|
||||
g.fillRect(_startPosX + 56, _startPosY + 4, 21, 21);
|
||||
|
||||
// Гусеница
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawRect(_startPosX + 24, _startPosY + 47, 48, 17);
|
||||
|
||||
// Основные катки
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawOval(_startPosX + 15, _startPosY + 47, 17, 17);
|
||||
g.drawOval(_startPosX + 63, _startPosY + 47, 17, 17);
|
||||
|
||||
g.setColor(EntityBulldozer.getBodyColor());
|
||||
g.fillOval(_startPosX + 15, _startPosY + 47, 17, 17);
|
||||
g.fillOval(_startPosX + 63, _startPosY + 47, 17, 17);
|
||||
|
||||
// Малые катки
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawOval(_startPosX + 40, _startPosY + 48, 5, 5);
|
||||
g.drawOval(_startPosX + 50, _startPosY + 48, 5, 5);
|
||||
|
||||
g.setColor(EntityBulldozer.getBodyColor());
|
||||
g.fillOval(_startPosX + 40, _startPosY + 48, 5, 5);
|
||||
g.fillOval(_startPosX + 50, _startPosY + 48, 5, 5);
|
||||
|
||||
int x = _startPosX;
|
||||
if (drawingRollers != null && drawingRollers.getRollersCount() != null){
|
||||
switch (drawingRollers.getRollersCount()){
|
||||
case OneRoller:
|
||||
drawingRollers.DrawRollers(g,x + 34, _startPosY + 55, 8, 8, EntityBulldozer.getBodyColor());
|
||||
break;
|
||||
case TwoRollers:
|
||||
drawingRollers.DrawRollers(g,x + 34, _startPosY + 55, 8, 8, EntityBulldozer.getBodyColor());
|
||||
drawingRollers.DrawRollers(g,x + 44, _startPosY + 55, 8, 8, EntityBulldozer.getBodyColor());
|
||||
break;
|
||||
case ThreeRollers:
|
||||
drawingRollers.DrawRollers(g,x + 34, _startPosY + 55, 8, 8, EntityBulldozer.getBodyColor());
|
||||
drawingRollers.DrawRollers(g,x + 44, _startPosY + 55, 8, 8, EntityBulldozer.getBodyColor());
|
||||
drawingRollers.DrawRollers(g,x + 54, _startPosY + 55, 8, 8, EntityBulldozer.getBodyColor());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
73
src/Drawings/DrawingExcavator.java
Normal file
73
src/Drawings/DrawingExcavator.java
Normal file
@ -0,0 +1,73 @@
|
||||
package Drawings;
|
||||
|
||||
import DifferentRollers.IDifferentRollers;
|
||||
import Entities.EntityExcavator;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawingExcavator extends DrawingBulldozer{
|
||||
|
||||
public DrawingExcavator(int speed, double weight, Color bodyColor, Color additionalColor, boolean prop, boolean ladle){
|
||||
EntityBulldozer = new EntityExcavator(speed, weight, bodyColor, additionalColor, prop, ladle);
|
||||
SetTypeRollers();
|
||||
}
|
||||
|
||||
public DrawingExcavator(EntityExcavator entity, IDifferentRollers rollers) {
|
||||
EntityBulldozer = entity;
|
||||
drawingRollers = rollers;
|
||||
}
|
||||
|
||||
// Отрисовка Экскаватора
|
||||
@Override
|
||||
public void DrawTransport(Graphics2D g){
|
||||
if (EntityBulldozer == null || !(EntityBulldozer instanceof EntityExcavator excavator) || _startPosX == null || _startPosY == null){
|
||||
return;
|
||||
}
|
||||
super.DrawTransport(g);
|
||||
if (excavator.getProp()){
|
||||
g.setColor(Color.BLACK);
|
||||
//Опоры
|
||||
//справа
|
||||
g.drawRect(_startPosX + 80, _startPosY + 40, 11, 3);
|
||||
g.drawRect(_startPosX + 87, _startPosY + 43, 5, 25);
|
||||
g.drawRect(_startPosX + 84, _startPosY + 68, 11, 3);
|
||||
|
||||
//слева
|
||||
g.drawRect(_startPosX + 6, _startPosY + 40, 13, 3);
|
||||
g.drawRect(_startPosX + 4, _startPosY + 43, 5, 25);
|
||||
g.drawRect(_startPosX + 1, _startPosY + 68, 11, 3);
|
||||
|
||||
g.setColor(excavator.getAdditionalColor());
|
||||
//покраска справа
|
||||
g.fillRect(_startPosX + 81, _startPosY + 41, 10, 2);
|
||||
g.fillRect(_startPosX + 88, _startPosY + 44, 4, 24);
|
||||
g.fillRect(_startPosX + 85, _startPosY + 69, 10, 2);
|
||||
|
||||
//покраска слева
|
||||
g.fillRect(_startPosX + 7, _startPosY + 41, 12, 2);
|
||||
g.fillRect(_startPosX + 5, _startPosY + 44, 4, 24);
|
||||
g.fillRect(_startPosX + 2, _startPosY + 69, 10, 2);
|
||||
}
|
||||
|
||||
if(excavator.getLadle()){
|
||||
g.setColor(Color.BLACK);
|
||||
//Ковш
|
||||
//ковш(стрела)
|
||||
g.drawRect(_startPosX + 77, _startPosY + 17, 14, 8);
|
||||
g.drawRect(_startPosX + 91, _startPosY + 9, 20, 7);
|
||||
g.drawRect(_startPosX + 111, _startPosY + 17, 9, 20);
|
||||
|
||||
int[] pointsLadleX = {_startPosX + 120, _startPosX + 104, _startPosX + 120};
|
||||
int[] pointsLadleY = {_startPosY + 37, _startPosY + 54, _startPosY + 54};
|
||||
|
||||
Polygon Ladle = new Polygon(pointsLadleX, pointsLadleY, 3);
|
||||
g.drawPolygon(Ladle);
|
||||
g.setColor(excavator.getAdditionalColor());
|
||||
g.fillPolygon(Ladle);
|
||||
//покраска
|
||||
g.fillRect(_startPosX + 78, _startPosY + 18, 13, 7);
|
||||
g.fillRect(_startPosX + 92, _startPosY + 10, 19, 6);
|
||||
g.fillRect(_startPosX + 112, _startPosY + 18, 8, 19);
|
||||
}
|
||||
}
|
||||
}
|
20
src/Entities/EntityBulldozer.java
Normal file
20
src/Entities/EntityBulldozer.java
Normal file
@ -0,0 +1,20 @@
|
||||
package Entities;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class EntityBulldozer {
|
||||
private Integer Speed;
|
||||
private Double Weight;
|
||||
private Color BodyColor;
|
||||
|
||||
public Color getBodyColor() {
|
||||
return BodyColor;
|
||||
}
|
||||
public double Step;
|
||||
public EntityBulldozer(int speed, double weight, Color bodyColor){
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
Step = Speed * 100 / Weight;
|
||||
}
|
||||
}
|
24
src/Entities/EntityExcavator.java
Normal file
24
src/Entities/EntityExcavator.java
Normal file
@ -0,0 +1,24 @@
|
||||
package Entities;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class EntityExcavator extends EntityBulldozer{
|
||||
private Color AdditionalColor;
|
||||
public Color getAdditionalColor(){
|
||||
return AdditionalColor;
|
||||
}
|
||||
public boolean Prop;
|
||||
public boolean getProp(){
|
||||
return Prop;
|
||||
}
|
||||
public boolean Ladle;
|
||||
public boolean getLadle(){
|
||||
return Ladle;
|
||||
}
|
||||
public EntityExcavator(int speed, double weight, Color bodyColor, Color additionalColor, boolean prop, boolean ladle){
|
||||
super(speed, weight, bodyColor);
|
||||
AdditionalColor = additionalColor;
|
||||
Prop = prop;
|
||||
Ladle = ladle;
|
||||
}
|
||||
}
|
148
src/FormAdditionalCollection.java
Normal file
148
src/FormAdditionalCollection.java
Normal file
@ -0,0 +1,148 @@
|
||||
import CollectionAdditionalObjects.AdditionalCollections;
|
||||
import CollectionGenericObjects.AbstractCompany;
|
||||
import DifferentRollers.DrawingRollersCross;
|
||||
import DifferentRollers.DrawingRollersPlus;
|
||||
import DifferentRollers.DrawingRollersStar;
|
||||
import DifferentRollers.IDifferentRollers;
|
||||
import Drawings.DrawingBulldozer;
|
||||
import Drawings.CanvasExcavator;
|
||||
import Drawings.DrawingExcavator;
|
||||
import Entities.EntityBulldozer;
|
||||
import Entities.EntityExcavator;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.Random;
|
||||
|
||||
public class FormAdditionalCollection extends JFrame {
|
||||
public DrawingBulldozer drawingBulldozer = null;
|
||||
private AbstractCompany company = null;
|
||||
private CanvasExcavator canvasExc = new CanvasExcavator();
|
||||
private AdditionalCollections<EntityBulldozer, IDifferentRollers> additionalCollection = null;
|
||||
private Random random = new Random();
|
||||
private JButton buttonCreate = new JButton("Создать");
|
||||
private JButton buttonAdd = new JButton("Добавить");
|
||||
private JList<String> listEntity = new JList<String>();
|
||||
private JList<String> listRollers = new JList<String>();
|
||||
public FormAdditionalCollection() {
|
||||
setTitle("Случайный объект");
|
||||
setMinimumSize(new Dimension(650,310));
|
||||
additionalCollection = new AdditionalCollections<EntityBulldozer, IDifferentRollers>(3, (Class) EntityBulldozer.class, (Class) IDifferentRollers.class);
|
||||
AddEntities();
|
||||
AddRollers();
|
||||
|
||||
buttonCreate.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
drawingBulldozer = additionalCollection.CreateAdditionalCollectionBulldozer();
|
||||
drawingBulldozer.SetPictureSize(getWidth(), getHeight());
|
||||
drawingBulldozer.SetPosition(50, 50);
|
||||
canvasExc._drawingBulldozer = drawingBulldozer;
|
||||
canvasExc.repaint();
|
||||
|
||||
String[] data1 = new String[additionalCollection.CountEntities];
|
||||
for (int i = 0; i < additionalCollection.CountEntities; i++) {
|
||||
EntityBulldozer entity = additionalCollection._collectionEntity[i];
|
||||
data1[i] = ToString(entity);
|
||||
}
|
||||
String[] data2 = new String[additionalCollection.CountRollers];
|
||||
for (int i = 0; i < additionalCollection.CountRollers; i++) {
|
||||
IDifferentRollers rollers = additionalCollection._collectionRollers[i];
|
||||
data2[i] = ToString(rollers);
|
||||
}
|
||||
listEntity.setListData(data1);
|
||||
listRollers.setListData(data2);
|
||||
}
|
||||
});
|
||||
|
||||
buttonAdd.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (drawingBulldozer != null) {
|
||||
DrawingBulldozer copyBulldozer;
|
||||
if (drawingBulldozer instanceof DrawingExcavator)
|
||||
copyBulldozer = new DrawingExcavator((EntityExcavator) drawingBulldozer.EntityBulldozer, drawingBulldozer.drawingRollers);
|
||||
else
|
||||
copyBulldozer = new DrawingBulldozer(drawingBulldozer.EntityBulldozer, drawingBulldozer.drawingRollers);
|
||||
company._collection.Insert(copyBulldozer);
|
||||
FormBulldozerCollection.canvasShow();
|
||||
}
|
||||
}
|
||||
});
|
||||
buttonCreate.setBounds(300, 10, 100, 50);
|
||||
buttonAdd.setBounds(450, 10, 100, 50);
|
||||
add(buttonCreate);
|
||||
add(buttonAdd);
|
||||
listEntity.setBounds(10,200,300,60);
|
||||
listRollers.setBounds(320,200,300,60);
|
||||
add(listEntity);
|
||||
add(listRollers);
|
||||
add(canvasExc);
|
||||
setVisible(true);
|
||||
}
|
||||
private String ToString(EntityBulldozer entity) {
|
||||
String str = "";
|
||||
if (entity instanceof EntityExcavator) str += "EntityExcavator ";
|
||||
else str += "EntityBulldozer ";
|
||||
str += entity.getBodyColor().toString();
|
||||
return str;
|
||||
}
|
||||
private String ToString(IDifferentRollers rollers) {
|
||||
if (rollers == null || rollers.getRollersCount() == null)
|
||||
return "Dont have rollers";
|
||||
String str = "Rollers ";
|
||||
if (rollers instanceof DrawingRollersCross) str += "Type Cross ";
|
||||
else if (rollers instanceof DrawingRollersPlus) str += "Type Plus ";
|
||||
else str += "Type Star ";
|
||||
str += rollers.getRollersCount().toString();
|
||||
return str;
|
||||
}
|
||||
public void AddEntities() {
|
||||
for (int i = 0; i < additionalCollection.CountEntities; i++) {
|
||||
random = new Random();
|
||||
int speed = random.nextInt(100, 300);
|
||||
double weight = random.nextInt(1000, 3000);
|
||||
Color bodycolor = new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256));
|
||||
EntityBulldozer entity;
|
||||
if (random.nextBoolean()) {
|
||||
entity = new EntityBulldozer(speed, weight, bodycolor);
|
||||
}
|
||||
else {
|
||||
Color additionalcolor = new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256));
|
||||
boolean prop = random.nextBoolean();
|
||||
boolean ladle = random.nextBoolean();
|
||||
entity = new EntityExcavator(speed, weight, bodycolor,
|
||||
additionalcolor, prop, ladle);
|
||||
}
|
||||
additionalCollection.Insert(entity);
|
||||
}
|
||||
}
|
||||
public void AddRollers() {
|
||||
for (int i = 0; i < additionalCollection.CountRollers; i++) {
|
||||
random = new Random();
|
||||
Integer numberOfRollers = random.nextInt(0, 4);
|
||||
IDifferentRollers drawingRollers = null;
|
||||
switch (random.nextInt(0,4)) {
|
||||
case 1:
|
||||
drawingRollers = new DrawingRollersCross();
|
||||
break;
|
||||
case 2:
|
||||
drawingRollers = new DrawingRollersPlus();
|
||||
break;
|
||||
case 3:
|
||||
drawingRollers = new DrawingRollersStar();
|
||||
break;
|
||||
default:
|
||||
numberOfRollers = null;
|
||||
break;
|
||||
}
|
||||
if (drawingRollers != null) drawingRollers.setRollersCount(numberOfRollers);
|
||||
additionalCollection.Insert(drawingRollers);
|
||||
}
|
||||
}
|
||||
void setCompany(AbstractCompany company) {
|
||||
this.company = company;
|
||||
}
|
||||
}
|
319
src/FormBulldozerCollection.java
Normal file
319
src/FormBulldozerCollection.java
Normal file
@ -0,0 +1,319 @@
|
||||
import CollectionGenericObjects.*;
|
||||
import Drawings.CanvasFormBulldozerCollection;
|
||||
import Drawings.DrawingBulldozer;
|
||||
import Drawings.DrawingExcavator;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.text.MaskFormatter;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.text.ParseException;
|
||||
import java.util.Random;
|
||||
import java.util.LinkedList;
|
||||
|
||||
import static java.lang.Integer.parseInt;
|
||||
|
||||
public class FormBulldozerCollection extends JFrame{
|
||||
private String title;
|
||||
private Dimension dimension;
|
||||
public static CanvasFormBulldozerCollection<DrawingBulldozer> _canvasExcavator = new CanvasFormBulldozerCollection<DrawingBulldozer>();
|
||||
private static AbstractCompany _company = null;
|
||||
private LinkedList<DrawingBulldozer> _collectionRemoveObjects = new LinkedList<DrawingBulldozer>();
|
||||
private StorageCollection<DrawingBulldozer> _storageCollection = new StorageCollection<DrawingBulldozer>();
|
||||
private JTextField textBoxCollection = new JTextField();
|
||||
private JRadioButton radioButtonMassive = new JRadioButton("Массив");
|
||||
private JRadioButton radioButtonList = new JRadioButton("Список");
|
||||
private JButton buttonAddCollection = new JButton("Добавить");
|
||||
private JList listBoxCollection = new JList();
|
||||
private JButton buttonRemoveCollection = new JButton("Удалить");
|
||||
private JButton buttonCreateCompany = new JButton("Создать компанию");
|
||||
private JButton CreateExcButton = new JButton("Создать экскаватор");;
|
||||
private JButton CreateBullButton = new JButton("Создать бульдозер");
|
||||
private JButton RemoveButton = new JButton("Удалить");
|
||||
private JButton GoToCheckButton = new JButton("Тест");
|
||||
private JButton RandomButton = new JButton("Случайный объект");
|
||||
private JButton RemoveObjectsButton = new JButton("Показать удаленный");
|
||||
private JButton RefreshButton = new JButton("Обновить");
|
||||
private JComboBox ComboBoxCollections = new JComboBox(new String[]{"", "Хранилище"});
|
||||
private JFormattedTextField MaskedTextField;
|
||||
public FormBulldozerCollection(String title, Dimension dimension) {
|
||||
this.title = title;
|
||||
this.dimension = dimension;
|
||||
}
|
||||
public static void canvasShow() {
|
||||
_company.SetPosition();
|
||||
_canvasExcavator.SetCollectionToCanvas(_company);
|
||||
_canvasExcavator.repaint();
|
||||
}
|
||||
private void CreateObject(String typeOfClass) {
|
||||
if (_company == null) return;
|
||||
int speed = (int)(Math.random() * 300 + 100);
|
||||
double weight = (double)(Math.random() * 3000 + 1000);
|
||||
Color bodyColor = getColor();
|
||||
DrawingBulldozer drawingBulldozer;
|
||||
switch (typeOfClass) {
|
||||
case "DrawingBulldozer":
|
||||
drawingBulldozer = new DrawingBulldozer(speed, weight, bodyColor);
|
||||
break;
|
||||
case "DrawingExcavator":
|
||||
Color additionalColor = getColor();
|
||||
boolean prop = new Random().nextBoolean();
|
||||
boolean ladle = new Random().nextBoolean();
|
||||
drawingBulldozer = new DrawingExcavator(speed, weight, bodyColor, additionalColor, prop, ladle);
|
||||
break;
|
||||
default: return;
|
||||
}
|
||||
if (_company._collection.Insert(drawingBulldozer) != -1) {
|
||||
JOptionPane.showMessageDialog(null, "Объект добавлен");
|
||||
canvasShow();
|
||||
}
|
||||
else {
|
||||
JOptionPane.showMessageDialog(null, "Объект не удалось добавить");
|
||||
}
|
||||
}
|
||||
public Color getColor() {
|
||||
Color initializator = new Color((int)(Math.random() * 255 + 0),(int)(Math.random() * 255 + 0),(int)(Math.random() * 255 + 0));
|
||||
Color color = JColorChooser.showDialog(this, "Выберите цвет", initializator);
|
||||
return color;
|
||||
}
|
||||
public void Init() {
|
||||
setTitle(title);
|
||||
setMinimumSize(dimension);
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
|
||||
MaskFormatter mask = null;
|
||||
try {
|
||||
mask = new MaskFormatter("##");
|
||||
mask.setPlaceholder("00");
|
||||
} catch (ParseException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
MaskedTextField = new JFormattedTextField(mask);
|
||||
|
||||
CreateBullButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
CreateObject("DrawingBulldozer");
|
||||
}
|
||||
});
|
||||
CreateExcButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
CreateObject("DrawingExcavator");
|
||||
}
|
||||
});
|
||||
|
||||
RemoveButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (_company == null || MaskedTextField.getText() == null || listBoxCollection.getSelectedValue().toString() == null) {
|
||||
return;
|
||||
}
|
||||
int pos = parseInt(MaskedTextField.getText());
|
||||
int resultConfirmDialog = JOptionPane.showConfirmDialog(null,
|
||||
"Удалить", "Удаление",
|
||||
JOptionPane.YES_NO_OPTION);
|
||||
if (resultConfirmDialog == JOptionPane.NO_OPTION) return;
|
||||
DrawingBulldozer obj = _storageCollection.Get(listBoxCollection.getSelectedValue().toString(), pos);
|
||||
if (obj != null) {
|
||||
JOptionPane.showMessageDialog(null, "Объект удален");
|
||||
_collectionRemoveObjects.push(obj);
|
||||
canvasShow();
|
||||
}
|
||||
else {
|
||||
JOptionPane.showMessageDialog(null, "Объект не удалось удалить");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
GoToCheckButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (_company == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
DrawingBulldozer bulldozer = null;
|
||||
int counter = 100;
|
||||
while (bulldozer == null)
|
||||
{
|
||||
bulldozer = _company.GetRandomObject();
|
||||
counter--;
|
||||
if (counter <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (bulldozer == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
FormExcavator form = new FormExcavator("Экскаватор", new Dimension(900,565));
|
||||
form.Init(bulldozer);
|
||||
}
|
||||
});
|
||||
|
||||
RandomButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (_company == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
FormAdditionalCollection form = new FormAdditionalCollection();
|
||||
form.setCompany(_company);
|
||||
form.setLocationRelativeTo(null);
|
||||
}
|
||||
});
|
||||
|
||||
RefreshButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (_company == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
canvasShow();
|
||||
}
|
||||
});
|
||||
|
||||
buttonAddCollection.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (textBoxCollection.getText().isEmpty() || (!radioButtonMassive.isSelected()
|
||||
&& !radioButtonList.isSelected())) {
|
||||
JOptionPane.showMessageDialog(null, "Не все данные заполнены");
|
||||
return;
|
||||
}
|
||||
CollectionType collectionType = CollectionType.None;
|
||||
if (radioButtonMassive.isSelected())
|
||||
{
|
||||
collectionType = CollectionType.Massive;
|
||||
}
|
||||
else if (radioButtonList.isSelected())
|
||||
{
|
||||
collectionType = CollectionType.List;
|
||||
}
|
||||
_storageCollection.AddCollection(textBoxCollection.getText(), collectionType);
|
||||
RefreshListBoxItems();
|
||||
}
|
||||
});
|
||||
|
||||
buttonRemoveCollection.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (listBoxCollection.getSelectedIndex() < 0 || listBoxCollection.getSelectedValue() == null) {
|
||||
JOptionPane.showMessageDialog(null, "Коллекция не выбрана");
|
||||
return;
|
||||
}
|
||||
int resultConfirmDialog = JOptionPane.showConfirmDialog(null,
|
||||
"Удалить", "Удаление",
|
||||
JOptionPane.YES_NO_OPTION);
|
||||
if (resultConfirmDialog == JOptionPane.NO_OPTION) return;
|
||||
_storageCollection.DelCollection(listBoxCollection.getSelectedValue().toString());
|
||||
RefreshListBoxItems();
|
||||
}
|
||||
});
|
||||
|
||||
buttonCreateCompany.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (listBoxCollection.getSelectedIndex() < 0 || listBoxCollection.getSelectedValue() == null) {
|
||||
JOptionPane.showMessageDialog(null, "Коллекция не выбрана");
|
||||
return;
|
||||
}
|
||||
ICollectionGenericObjects<DrawingBulldozer> collection =
|
||||
_storageCollection.getCollectionObject(listBoxCollection.getSelectedValue().toString());
|
||||
if (collection == null) {
|
||||
JOptionPane.showMessageDialog(null, "Коллекция не проинициализирована");
|
||||
return;
|
||||
}
|
||||
switch (ComboBoxCollections.getSelectedItem().toString()) {
|
||||
case "Хранилище":
|
||||
_company = new BulldozerSharingService(getWidth()-200, getHeight()-70,
|
||||
collection);
|
||||
break;
|
||||
}
|
||||
RefreshListBoxItems();
|
||||
}
|
||||
});
|
||||
|
||||
RemoveObjectsButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (_collectionRemoveObjects.isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
DrawingBulldozer bulldozer = null;
|
||||
bulldozer = _collectionRemoveObjects.pop();
|
||||
if (bulldozer == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
FormExcavator form = new FormExcavator("Экскаватор", new Dimension(900,565));
|
||||
form.Init(bulldozer);
|
||||
}
|
||||
});
|
||||
|
||||
JLabel labelCollectionName = new JLabel("Название коллекции");
|
||||
ButtonGroup radioButtonsGroup = new ButtonGroup();
|
||||
radioButtonsGroup.add(radioButtonMassive);
|
||||
radioButtonsGroup.add(radioButtonList);
|
||||
|
||||
_canvasExcavator.setBounds(0, 0, getWidth()-200, getHeight());
|
||||
labelCollectionName.setBounds(getWidth()-190, 30, 150, 20);
|
||||
textBoxCollection.setBounds(getWidth()-190, 52, 150, 25);
|
||||
radioButtonMassive.setBounds(getWidth()-190, 80, 75, 20);
|
||||
radioButtonList.setBounds(getWidth()-105, 80, 75, 20);
|
||||
buttonAddCollection.setBounds(getWidth()-190, 105, 150, 20);
|
||||
listBoxCollection.setBounds(getWidth()-190, 135, 150, 70);
|
||||
buttonRemoveCollection.setBounds(getWidth()-190, 210, 150, 20);
|
||||
ComboBoxCollections.setBounds(getWidth()-190, 10, 150, 20);
|
||||
buttonCreateCompany.setBounds(getWidth()-190, 240, 150, 20);
|
||||
CreateBullButton.setBounds(getWidth()-190, 280, 150, 30);
|
||||
CreateExcButton.setBounds(getWidth()-190, 320, 150, 30);
|
||||
MaskedTextField.setBounds(getWidth()-190,360,150,30);
|
||||
RemoveButton.setBounds(getWidth()-190, 400, 150, 30);
|
||||
GoToCheckButton.setBounds(getWidth()-190, 440, 150, 30);
|
||||
RandomButton.setBounds(getWidth()-190, 480, 150, 30);
|
||||
RemoveObjectsButton.setBounds(getWidth()-190, 520, 150, 30);
|
||||
RefreshButton.setBounds(getWidth()-190, getHeight()-90, 150, 30);
|
||||
|
||||
setSize(dimension.width,dimension.height);
|
||||
setLayout(null);
|
||||
add(_canvasExcavator);
|
||||
add(labelCollectionName);
|
||||
add(textBoxCollection);
|
||||
add(radioButtonMassive);
|
||||
add(radioButtonList);
|
||||
add(buttonAddCollection);
|
||||
add(listBoxCollection);
|
||||
add(buttonRemoveCollection);
|
||||
add(ComboBoxCollections);
|
||||
add(buttonCreateCompany);
|
||||
add(CreateBullButton);
|
||||
add(CreateExcButton);
|
||||
add(MaskedTextField);
|
||||
add(RemoveButton);
|
||||
add(GoToCheckButton);
|
||||
add(RandomButton);
|
||||
add(RemoveObjectsButton);
|
||||
add(RefreshButton);
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
private void RefreshListBoxItems()
|
||||
{
|
||||
DefaultListModel<String> list = new DefaultListModel<String>();
|
||||
for (String name : _storageCollection.Keys()) {
|
||||
if (name != "")
|
||||
{
|
||||
list.addElement(name);
|
||||
}
|
||||
}
|
||||
listBoxCollection.setModel(list);
|
||||
}
|
||||
}
|
135
src/FormExcavator.java
Normal file
135
src/FormExcavator.java
Normal file
@ -0,0 +1,135 @@
|
||||
import Drawings.*;
|
||||
import MovementStrategy.*;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
public class FormExcavator extends JFrame {
|
||||
private String title;
|
||||
private Dimension dimension;
|
||||
private int Width, Height;
|
||||
private CanvasExcavator canvasExcavator = new CanvasExcavator();
|
||||
private JButton UpButton = new JButton();
|
||||
private JButton DownButton = new JButton();
|
||||
private JButton LeftButton = new JButton();
|
||||
private JButton RightButton = new JButton();
|
||||
private AbstractStrategy _strategy;
|
||||
private JComboBox ComboBoxStrategy = new JComboBox(new String[]{"К центру", "К краю"});
|
||||
private JButton ButtonStrategy = new JButton("Шаг");
|
||||
public FormExcavator(String title, Dimension dimension) {
|
||||
this.title = title;
|
||||
this.dimension = dimension;
|
||||
}
|
||||
|
||||
public void Init(DrawingBulldozer bulldozer) {
|
||||
setTitle(title);
|
||||
setMinimumSize(dimension);
|
||||
|
||||
Width = getWidth() - 15;
|
||||
Height = getHeight() - 35;
|
||||
ComboBoxStrategy.setEnabled(true);
|
||||
_strategy = null;
|
||||
canvasExcavator._drawingBulldozer = bulldozer;
|
||||
|
||||
Icon iconUp = new ImageIcon("res/up.png");
|
||||
UpButton.setIcon(iconUp);
|
||||
UpButton.setName("Up");
|
||||
DownButton.setName("Down");
|
||||
Icon iconDown = new ImageIcon("res/down.png");
|
||||
DownButton.setIcon(iconDown);
|
||||
LeftButton.setName("Left");
|
||||
Icon iconLeft = new ImageIcon("res/left.png");
|
||||
LeftButton.setIcon(iconLeft);
|
||||
RightButton.setName("Right");
|
||||
Icon iconRight = new ImageIcon("res/right.png");
|
||||
RightButton.setIcon(iconRight);
|
||||
|
||||
ButtonStrategy.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (canvasExcavator._drawingBulldozer == null) return;
|
||||
if (ComboBoxStrategy.isEnabled())
|
||||
{
|
||||
int index = ComboBoxStrategy.getSelectedIndex();
|
||||
switch(index)
|
||||
{
|
||||
case 0:
|
||||
_strategy = new MoveToCenter();
|
||||
break;
|
||||
case 1:
|
||||
_strategy = new MoveToBorder();
|
||||
break;
|
||||
default:
|
||||
_strategy = null;
|
||||
break;
|
||||
}
|
||||
if (_strategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_strategy.SetData(new MoveableExcavator(canvasExcavator._drawingBulldozer), Width, Height);
|
||||
}
|
||||
if (_strategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
ComboBoxStrategy.setEnabled(false);
|
||||
_strategy.MakeStep();
|
||||
if (_strategy.GetStatus() == StrategyStatus.Finish)
|
||||
{
|
||||
ComboBoxStrategy.setEnabled(true);
|
||||
_strategy = null;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
ActionListener actionListener = new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
if (canvasExcavator._drawingBulldozer == null) return;
|
||||
boolean result = false;
|
||||
switch ((((JButton)(event.getSource())).getName())) {
|
||||
case "Up":
|
||||
result = canvasExcavator._drawingBulldozer.MoveTransport(DirectionType.Up);
|
||||
break;
|
||||
case "Down":
|
||||
result = canvasExcavator._drawingBulldozer.MoveTransport(DirectionType.Down);
|
||||
break;
|
||||
case "Left":
|
||||
result = canvasExcavator._drawingBulldozer.MoveTransport(DirectionType.Left);
|
||||
break;
|
||||
case "Right":
|
||||
result = canvasExcavator._drawingBulldozer.MoveTransport(DirectionType.Right);
|
||||
break;
|
||||
}
|
||||
if (result) {
|
||||
canvasExcavator.repaint();
|
||||
}
|
||||
}
|
||||
};
|
||||
UpButton.addActionListener(actionListener);
|
||||
DownButton.addActionListener(actionListener);
|
||||
LeftButton.addActionListener(actionListener);
|
||||
RightButton.addActionListener(actionListener);
|
||||
|
||||
setSize(dimension.width,dimension.height);
|
||||
setLayout(null);
|
||||
canvasExcavator.setBounds(0,0, getWidth(), getHeight());
|
||||
UpButton.setBounds(getWidth() - 110, getHeight() - 135, 35, 35);
|
||||
DownButton.setBounds(getWidth() - 110, getHeight() - 85, 35, 35);
|
||||
RightButton.setBounds(getWidth() - 60, getHeight() - 85, 35, 35);
|
||||
LeftButton.setBounds(getWidth() - 160, getHeight() - 85, 35, 35);
|
||||
ComboBoxStrategy.setBounds(getWidth() - 170, 10, 140, 25);
|
||||
ButtonStrategy.setBounds(getWidth() - 130, 45, 100, 25);
|
||||
add(UpButton);
|
||||
add(DownButton);
|
||||
add(RightButton);
|
||||
add(LeftButton);
|
||||
add(ButtonStrategy);
|
||||
add(ComboBoxStrategy);
|
||||
add(canvasExcavator);
|
||||
setVisible(true);
|
||||
}
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Hello world!");
|
||||
}
|
||||
}
|
56
src/MovementStrategy/AbstractStrategy.java
Normal file
56
src/MovementStrategy/AbstractStrategy.java
Normal file
@ -0,0 +1,56 @@
|
||||
package MovementStrategy;
|
||||
|
||||
public abstract class AbstractStrategy {
|
||||
private IMoveableObjects _moveableObject;
|
||||
private StrategyStatus _state = StrategyStatus.NotInit;
|
||||
public int FieldWidth;
|
||||
public int FieldHeight;
|
||||
public StrategyStatus GetStatus() {return _state;}
|
||||
public void SetData(IMoveableObjects moveableObjects, int width, int height)
|
||||
{
|
||||
if (moveableObjects == null)
|
||||
{
|
||||
_state = StrategyStatus.NotInit;
|
||||
return;
|
||||
}
|
||||
_state = StrategyStatus.InProgress;
|
||||
_moveableObject = moveableObjects;
|
||||
FieldWidth = width;
|
||||
FieldHeight = height;
|
||||
}
|
||||
public void MakeStep()
|
||||
{
|
||||
if (_state != StrategyStatus.InProgress) return;
|
||||
if (IsTargetDestination())
|
||||
{
|
||||
_state = StrategyStatus.Finish;
|
||||
return;
|
||||
}
|
||||
MoveToTarget();
|
||||
}
|
||||
protected boolean MoveLeft() {return MoveTo(MovementDirection.Left);}
|
||||
protected boolean MoveRight() {return MoveTo(MovementDirection.Right);}
|
||||
protected boolean MoveUp() {return MoveTo(MovementDirection.Up);}
|
||||
protected boolean MoveDown() {return MoveTo(MovementDirection.Down);}
|
||||
protected ObjectParameters GetObjectParameters() {return _moveableObject.GetObjectPosition();}
|
||||
protected Integer GetStep()
|
||||
{
|
||||
if (_state != StrategyStatus.InProgress)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return _moveableObject.GetStep();
|
||||
}
|
||||
protected abstract void MoveToTarget();
|
||||
protected abstract boolean IsTargetDestination();
|
||||
private boolean MoveTo(MovementDirection movementDirection)
|
||||
{
|
||||
if (_state != StrategyStatus.InProgress)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
boolean stateTryMoveObject = _moveableObject.TryMoveObject(movementDirection);
|
||||
if (stateTryMoveObject) return stateTryMoveObject;
|
||||
return false;
|
||||
}
|
||||
}
|
7
src/MovementStrategy/IMoveableObjects.java
Normal file
7
src/MovementStrategy/IMoveableObjects.java
Normal file
@ -0,0 +1,7 @@
|
||||
package MovementStrategy;
|
||||
|
||||
public interface IMoveableObjects {
|
||||
ObjectParameters GetObjectPosition();
|
||||
int GetStep();
|
||||
boolean TryMoveObject(MovementDirection direction);
|
||||
}
|
26
src/MovementStrategy/MoveToBorder.java
Normal file
26
src/MovementStrategy/MoveToBorder.java
Normal file
@ -0,0 +1,26 @@
|
||||
package MovementStrategy;
|
||||
|
||||
public class MoveToBorder extends AbstractStrategy{
|
||||
@Override
|
||||
protected boolean IsTargetDestination(){
|
||||
ObjectParameters objParams = GetObjectParameters();
|
||||
if (objParams == null){
|
||||
return false;
|
||||
}
|
||||
return objParams.RightBorder + GetStep() >= FieldWidth - GetStep() && objParams.DownBorder + GetStep() >= FieldHeight - GetStep();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void MoveToTarget(){
|
||||
ObjectParameters objParams = GetObjectParameters();
|
||||
if (objParams == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
//реализация в правый нижний угол
|
||||
int x = objParams.RightBorder;
|
||||
if (x + GetStep() < FieldWidth) MoveRight();
|
||||
int y = objParams.DownBorder;
|
||||
if (y + GetStep() < FieldHeight) MoveDown();
|
||||
}
|
||||
}
|
48
src/MovementStrategy/MoveToCenter.java
Normal file
48
src/MovementStrategy/MoveToCenter.java
Normal file
@ -0,0 +1,48 @@
|
||||
package MovementStrategy;
|
||||
|
||||
public class MoveToCenter extends AbstractStrategy{
|
||||
@Override
|
||||
protected boolean IsTargetDestination() {
|
||||
ObjectParameters objParams = GetObjectParameters();
|
||||
if (objParams == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return objParams.ObjectMiddleHorizontal - GetStep() <= FieldWidth / 2 &&
|
||||
objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth / 2 &&
|
||||
objParams.ObjectMiddleVertical - GetStep() <= FieldHeight / 2 &&
|
||||
objParams.ObjectMiddleVertical + GetStep() >= FieldHeight /2;
|
||||
}
|
||||
@Override
|
||||
protected void MoveToTarget() {
|
||||
ObjectParameters objParams = GetObjectParameters();
|
||||
if (objParams == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int diffX = objParams.ObjectMiddleHorizontal - FieldWidth / 2;
|
||||
if (Math.abs(diffX) > GetStep())
|
||||
{
|
||||
if (diffX > 0)
|
||||
{
|
||||
MoveLeft();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveRight();
|
||||
}
|
||||
}
|
||||
int diffY = objParams.ObjectMiddleVertical - FieldHeight / 2;
|
||||
if (Math.abs(diffY) > GetStep())
|
||||
{
|
||||
if (diffY > 0)
|
||||
{
|
||||
MoveUp();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
45
src/MovementStrategy/MoveableExcavator.java
Normal file
45
src/MovementStrategy/MoveableExcavator.java
Normal file
@ -0,0 +1,45 @@
|
||||
package MovementStrategy;
|
||||
|
||||
import Drawings.CanvasExcavator;
|
||||
import Drawings.DrawingBulldozer;
|
||||
import Drawings.DirectionType;
|
||||
|
||||
public class MoveableExcavator implements IMoveableObjects{
|
||||
private CanvasExcavator canvas = new CanvasExcavator();
|
||||
public MoveableExcavator(DrawingBulldozer drawingBulldozer){
|
||||
canvas._drawingBulldozer = drawingBulldozer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectParameters GetObjectPosition() {
|
||||
if (canvas._drawingBulldozer == null || canvas._drawingBulldozer.EntityBulldozer == null ||
|
||||
canvas._drawingBulldozer.GetPosX() == null || canvas._drawingBulldozer.GetPosY() == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new ObjectParameters(canvas._drawingBulldozer.GetPosX(), canvas._drawingBulldozer.GetPosY(),
|
||||
canvas._drawingBulldozer.GetWidth(), canvas._drawingBulldozer.GetHeight());
|
||||
}
|
||||
@Override
|
||||
public int GetStep() {
|
||||
return (int)(canvas._drawingBulldozer.EntityBulldozer.Step);
|
||||
}
|
||||
@Override
|
||||
public boolean TryMoveObject(MovementDirection direction) {
|
||||
if (canvas._drawingBulldozer == null || canvas._drawingBulldozer.EntityBulldozer == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return canvas._drawingBulldozer.MoveTransport(GetDirectionType(direction));
|
||||
}
|
||||
private static DirectionType GetDirectionType(MovementDirection direction)
|
||||
{
|
||||
switch (direction) {
|
||||
case Left: return DirectionType.Left;
|
||||
case Right: return DirectionType.Right;
|
||||
case Up: return DirectionType.Up;
|
||||
case Down: return DirectionType.Down;
|
||||
default: return DirectionType.Unknow;
|
||||
}
|
||||
}
|
||||
}
|
8
src/MovementStrategy/MovementDirection.java
Normal file
8
src/MovementStrategy/MovementDirection.java
Normal file
@ -0,0 +1,8 @@
|
||||
package MovementStrategy;
|
||||
|
||||
public enum MovementDirection {
|
||||
Up,
|
||||
Down,
|
||||
Left,
|
||||
Right
|
||||
}
|
27
src/MovementStrategy/ObjectParameters.java
Normal file
27
src/MovementStrategy/ObjectParameters.java
Normal file
@ -0,0 +1,27 @@
|
||||
package MovementStrategy;
|
||||
|
||||
public class ObjectParameters {
|
||||
private int _x;
|
||||
private int _y;
|
||||
private int _width;
|
||||
private int _height;
|
||||
public int LeftBorder = _x;
|
||||
public int TopBorder = _y;
|
||||
public int RightBorder = _x + _width;
|
||||
public int DownBorder = _y + _height;
|
||||
public int ObjectMiddleHorizontal = _x + _width / 2;
|
||||
public int ObjectMiddleVertical = _y + _height / 2;
|
||||
public ObjectParameters(int x, int y, int width, int height)
|
||||
{
|
||||
_x = x;
|
||||
_y = y;
|
||||
_width = width;
|
||||
_height = height;
|
||||
LeftBorder = _x;
|
||||
TopBorder = _y;
|
||||
RightBorder = _x + _width;
|
||||
DownBorder = _y + _height;
|
||||
ObjectMiddleHorizontal = _x + _width / 2;
|
||||
ObjectMiddleVertical = _y + _height / 2;
|
||||
}
|
||||
}
|
7
src/MovementStrategy/StrategyStatus.java
Normal file
7
src/MovementStrategy/StrategyStatus.java
Normal file
@ -0,0 +1,7 @@
|
||||
package MovementStrategy;
|
||||
|
||||
public enum StrategyStatus {
|
||||
NotInit,
|
||||
InProgress,
|
||||
Finish
|
||||
}
|
9
src/Program.java
Normal file
9
src/Program.java
Normal file
@ -0,0 +1,9 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class Program {
|
||||
public static void main(String[] args) {
|
||||
FormBulldozerCollection form = new FormBulldozerCollection("Коллекция экскаваторов", new Dimension(1100, 650));
|
||||
form.Init();
|
||||
form.setLocationRelativeTo(null);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user