Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
b50cb4a9f4 | |||
|
e67ef3d181 | ||
90cd0c8afb | |||
2041097d1c |
17
CanvasDumpTruck.java
Normal file
17
CanvasDumpTruck.java
Normal file
@ -0,0 +1,17 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class CanvasDumpTruck extends JComponent {
|
||||
public DrawningDumpTruck _drawningDumpTruck;
|
||||
public CanvasDumpTruck() {}
|
||||
|
||||
public void paintComponent(Graphics g) {
|
||||
if (_drawningDumpTruck == null) {
|
||||
return;
|
||||
}
|
||||
super.paintComponents(g);
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
_drawningDumpTruck.DrawTransport(g2d);
|
||||
super.repaint();
|
||||
}
|
||||
}
|
37
CollectionGenericObjects/AbstractCompany.java
Normal file
37
CollectionGenericObjects/AbstractCompany.java
Normal file
@ -0,0 +1,37 @@
|
||||
package CollectionGenericObjects;
|
||||
import Drawnings.DrawningTruck;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.Random;
|
||||
|
||||
public class AbstractCompany {
|
||||
protected int _placeSizeWidth = 120;
|
||||
protected int _placeSizeHeight = 120;
|
||||
protected int _pictureWidth;
|
||||
protected int _pictureHeight;
|
||||
public ICollectionGenericObjects<DrawningTruck> _collection = null;
|
||||
|
||||
private int GetMaxCount (){ return _pictureWidth * _pictureHeight / (_placeSizeWidth * _placeSizeHeight);}
|
||||
public AbstractCompany(int picWidth, int picHeight,
|
||||
ICollectionGenericObjects<DrawningTruck> collection)
|
||||
{
|
||||
_pictureWidth = picWidth;
|
||||
_pictureHeight = picHeight;
|
||||
_collection = collection;
|
||||
_collection.SetMaxCount( GetMaxCount(), DrawningTruck.class);
|
||||
}
|
||||
public DrawningTruck GetRandomObject()
|
||||
{
|
||||
Random random = new Random();
|
||||
return _collection.Get(random.nextInt(GetMaxCount()));
|
||||
}
|
||||
|
||||
public void DrawBackgound(Graphics g) { }
|
||||
|
||||
protected void SetObjectsPosition() { }
|
||||
|
||||
public void SetPosition()
|
||||
{
|
||||
SetObjectsPosition();
|
||||
}
|
||||
}
|
65
CollectionGenericObjects/AdditionalCollection.java
Normal file
65
CollectionGenericObjects/AdditionalCollection.java
Normal file
@ -0,0 +1,65 @@
|
||||
package CollectionGenericObjects;
|
||||
|
||||
import DifferenceOfWheels.IOrnaments;
|
||||
import Drawnings.DrawningDumpTruck;
|
||||
import Drawnings.DrawningTruck;
|
||||
import Entities.EntityDumpTruck;
|
||||
import Entities.EntityTruck;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.Random;
|
||||
|
||||
public class AdditionalCollection<T extends EntityTruck, U extends IOrnaments> {
|
||||
public T[] _collectionEntityTruck;
|
||||
public U[] _collectionIOrnaments;
|
||||
public int Len_entity;
|
||||
public int Len_ornament;
|
||||
public AdditionalCollection(int len, Class<T> entity, Class<U> ornament){
|
||||
_collectionEntityTruck = (T[]) Array.newInstance(entity, len);
|
||||
_collectionIOrnaments = (U[]) Array.newInstance(ornament, len);
|
||||
Len_entity = len;
|
||||
Len_ornament = len;
|
||||
}
|
||||
|
||||
public int Insert(T entity) {
|
||||
int index = 0;
|
||||
while (index < Len_entity) {
|
||||
if (_collectionEntityTruck[index] == null)
|
||||
{
|
||||
_collectionEntityTruck[index] = entity;
|
||||
return index;
|
||||
}
|
||||
++index;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
public int Insert(U ornament) {
|
||||
int index = 0;
|
||||
while (index < Len_ornament) {
|
||||
if (_collectionIOrnaments[index] == null)
|
||||
{
|
||||
_collectionIOrnaments[index] = ornament;
|
||||
return index;
|
||||
}
|
||||
++index;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public DrawningTruck CreateDrawningTruckClass(){
|
||||
if (_collectionIOrnaments == null || _collectionEntityTruck == null){
|
||||
return null;
|
||||
}
|
||||
DrawningTruck _drawningTruck;
|
||||
Random random = new Random();
|
||||
EntityTruck _truck = _collectionEntityTruck[random.nextInt(0, Len_entity)];
|
||||
IOrnaments _ornament = _collectionIOrnaments[random.nextInt(0, Len_ornament)];
|
||||
if (_truck instanceof EntityDumpTruck){
|
||||
_drawningTruck = new DrawningDumpTruck((EntityDumpTruck) _truck, _ornament);
|
||||
}
|
||||
else{
|
||||
_drawningTruck = new DrawningTruck(_truck, _ornament);
|
||||
}
|
||||
return _drawningTruck;
|
||||
}
|
||||
}
|
9
CollectionGenericObjects/ICollectionGenericObjects.java
Normal file
9
CollectionGenericObjects/ICollectionGenericObjects.java
Normal file
@ -0,0 +1,9 @@
|
||||
package CollectionGenericObjects;
|
||||
public interface ICollectionGenericObjects<T>{
|
||||
int getCount();
|
||||
void SetMaxCount(int count, Class<T> type);
|
||||
int Insert(T obj);
|
||||
int Insert(T obj, int position);
|
||||
T Remove(int position);
|
||||
T Get(int position);
|
||||
}
|
85
CollectionGenericObjects/MassiveGenericObjects.java
Normal file
85
CollectionGenericObjects/MassiveGenericObjects.java
Normal file
@ -0,0 +1,85 @@
|
||||
package CollectionGenericObjects;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
|
||||
public class MassiveGenericObjects<T> implements ICollectionGenericObjects<T> {
|
||||
|
||||
private T[] _collection;
|
||||
int Count;
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return _collection.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void SetMaxCount(int count, Class<T> type) {
|
||||
if (count > 0) {
|
||||
_collection = (T[]) Array.newInstance(type, count);
|
||||
Count = count;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public T Get(int position) {
|
||||
if (position >= getCount() || position < 0)
|
||||
return null;
|
||||
return (T) _collection[position];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int Insert(T obj) {
|
||||
for (int i = 0; i < _collection.length; ++i)
|
||||
{
|
||||
if (_collection[i] == null)
|
||||
{
|
||||
_collection[i] = obj;
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int Insert(T obj, int position) {
|
||||
if (position < 0 || position > Count)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if (_collection[position] == null)
|
||||
{
|
||||
_collection[position] = obj;
|
||||
return position;
|
||||
}
|
||||
for (int i = position + 1; i < _collection.length; ++i)
|
||||
{
|
||||
if (_collection[i] == null)
|
||||
{
|
||||
_collection[i] = obj;
|
||||
return position;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < position; ++i)
|
||||
{
|
||||
if (_collection[i] == null)
|
||||
{
|
||||
_collection[i] = obj;
|
||||
return position;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T Remove(int position) {
|
||||
if (position >= 0 && position < Count)
|
||||
{
|
||||
T remove = _collection[position];
|
||||
_collection[position]= null;
|
||||
return remove;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
65
CollectionGenericObjects/TruckShearingService.java
Normal file
65
CollectionGenericObjects/TruckShearingService.java
Normal file
@ -0,0 +1,65 @@
|
||||
package CollectionGenericObjects;
|
||||
import Drawnings.DrawningTruck;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class TruckShearingService extends AbstractCompany {
|
||||
public TruckShearingService(int picWidth, int picHeight, ICollectionGenericObjects<DrawningTruck> collection)
|
||||
{
|
||||
super(picWidth, picHeight, collection);
|
||||
}
|
||||
|
||||
private int start_width = 10, start_height = 20;
|
||||
private int width_between = 60;
|
||||
|
||||
@Override
|
||||
public void DrawBackgound(Graphics g)
|
||||
{
|
||||
g.setColor(Color.BLACK);
|
||||
int height = 5, width = 5;
|
||||
|
||||
int maxWidth = _pictureWidth / (_placeSizeWidth + width_between);
|
||||
int maxHeight = _pictureHeight / _placeSizeHeight;
|
||||
|
||||
for (int i = 0; i < maxWidth; i++)
|
||||
{
|
||||
height = 10;
|
||||
for (int j = 0; j < maxHeight; j++)
|
||||
{
|
||||
g.drawLine(width, height, width + _placeSizeWidth, height);
|
||||
g.drawLine(width, height, width, height + _placeSizeHeight);
|
||||
height += _placeSizeHeight;
|
||||
}
|
||||
g.drawLine(width, height, width + _placeSizeWidth, height);
|
||||
width = width + _placeSizeWidth + width_between;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void SetObjectsPosition()
|
||||
{
|
||||
int maxWidth = _pictureWidth / (_placeSizeWidth + width_between);
|
||||
int maxHeight = _pictureHeight / _placeSizeHeight;
|
||||
int i_collection = 0;
|
||||
int x_pos = start_width, y_pos = start_height;
|
||||
|
||||
|
||||
if (_collection != null) {
|
||||
for (int j = 0; j < maxHeight; j++)
|
||||
{
|
||||
x_pos = start_width;
|
||||
for (int i = 0; i < maxWidth; i++)
|
||||
{
|
||||
if (_collection.Get(i_collection) != null)
|
||||
{
|
||||
_collection.Get(i_collection).SetPictureSize(_pictureWidth, _pictureHeight);
|
||||
_collection.Get(i_collection).SetPosition(x_pos, y_pos);
|
||||
x_pos += _placeSizeWidth + width_between;
|
||||
i_collection++;
|
||||
}
|
||||
}
|
||||
y_pos = y_pos + _placeSizeHeight;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
47
DifferenceOfWheels/DrawningOrnamentRectangle.java
Normal file
47
DifferenceOfWheels/DrawningOrnamentRectangle.java
Normal file
@ -0,0 +1,47 @@
|
||||
package DifferenceOfWheels;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawningOrnamentRectangle implements IOrnaments{
|
||||
int CountWeel;
|
||||
|
||||
@Override
|
||||
public void SetCount(int n) {
|
||||
CountWeel = n;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer get_count_weels() {
|
||||
return CountWeel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void DrawOrnament(Graphics2D g, int x, int y) {
|
||||
g.setColor(Color.BLACK);
|
||||
g.fillOval(x, y, 25, 25);
|
||||
|
||||
g.setColor(Color.PINK);
|
||||
g.fillRect(x + 5, y + 5, 15, 15);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void DrawWeels(Graphics2D g, int x, int y) {
|
||||
switch (CountWeel){
|
||||
case 2:
|
||||
DrawOrnament(g, x + 10, y + 67);
|
||||
DrawOrnament(g, x + 85, y + 67);
|
||||
break;
|
||||
case 3:
|
||||
DrawOrnament(g, x + 10, y + 67);
|
||||
DrawOrnament(g, x + 38, y + 67);
|
||||
DrawOrnament(g, x + 85, y + 67);
|
||||
break;
|
||||
case 4:
|
||||
DrawOrnament(g, x + 5, y + 67);
|
||||
DrawOrnament(g, x + 32, y + 67);
|
||||
DrawOrnament(g, x + 61, y + 67);
|
||||
DrawOrnament(g, x + 88, y + 67);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
57
DifferenceOfWheels/DrawningOrnamentStar.java
Normal file
57
DifferenceOfWheels/DrawningOrnamentStar.java
Normal file
@ -0,0 +1,57 @@
|
||||
package DifferenceOfWheels;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawningOrnamentStar implements IOrnaments{
|
||||
int CountWeel;
|
||||
@Override
|
||||
public void SetCount(int n) {
|
||||
CountWeel = n;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer get_count_weels() {
|
||||
return CountWeel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void DrawOrnament(Graphics2D g, int x, int y) {
|
||||
g.setColor(Color.BLACK);
|
||||
g.fillOval(x, y, 25, 25);
|
||||
|
||||
g.setColor(Color.CYAN);
|
||||
Polygon elements = new Polygon();
|
||||
elements.addPoint(x + 12, y + 2);
|
||||
elements.addPoint(x + 15, y + 8);
|
||||
elements.addPoint(x + 21, y + 10);
|
||||
elements.addPoint(x + 15, y + 13);
|
||||
elements.addPoint(x + 19, y + 19);
|
||||
elements.addPoint(x + 12, y + 15);
|
||||
elements.addPoint(x + 5, y + 19);
|
||||
elements.addPoint(x + 9, y + 13);
|
||||
elements.addPoint(x + 3, y + 10);
|
||||
elements.addPoint(x + 10, y + 8);
|
||||
g.fillPolygon(elements);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void DrawWeels(Graphics2D g, int x, int y) {
|
||||
switch (CountWeel){
|
||||
case 2:
|
||||
DrawOrnament(g, x + 10, y + 67);
|
||||
DrawOrnament(g, x + 85, y + 67);
|
||||
break;
|
||||
case 3:
|
||||
DrawOrnament(g, x + 10, y + 67);
|
||||
DrawOrnament(g, x + 38, y + 67);
|
||||
DrawOrnament(g, x + 85, y + 67);
|
||||
break;
|
||||
case 4:
|
||||
DrawOrnament(g, x + 5, y + 67);
|
||||
DrawOrnament(g, x + 32, y + 67);
|
||||
DrawOrnament(g, x + 61, y + 67);
|
||||
DrawOrnament(g, x + 88, y + 67);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
51
DifferenceOfWheels/DrawningOrnamentTriangle.java
Normal file
51
DifferenceOfWheels/DrawningOrnamentTriangle.java
Normal file
@ -0,0 +1,51 @@
|
||||
package DifferenceOfWheels;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawningOrnamentTriangle implements IOrnaments{
|
||||
int CountWeel;
|
||||
@Override
|
||||
public void SetCount(int n) {
|
||||
CountWeel = n;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer get_count_weels() {
|
||||
return CountWeel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void DrawOrnament(Graphics2D g, int x, int y) {
|
||||
g.setColor(Color.BLACK);
|
||||
g.fillOval(x, y, 25, 25);
|
||||
|
||||
g.setColor(Color.MAGENTA);
|
||||
Polygon elements = new Polygon();
|
||||
elements.addPoint(x + 7, y + 6);
|
||||
elements.addPoint(x + 20, y + 6);
|
||||
elements.addPoint(x + 7, y + 18);
|
||||
g.fillPolygon(elements);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void DrawWeels(Graphics2D g, int x, int y) {
|
||||
switch (CountWeel){
|
||||
case 2:
|
||||
DrawOrnament(g, x + 10, y + 67);
|
||||
DrawOrnament(g, x + 85, y + 67);
|
||||
break;
|
||||
case 3:
|
||||
DrawOrnament(g, x + 10, y + 67);
|
||||
DrawOrnament(g, x + 38, y + 67);
|
||||
DrawOrnament(g, x + 85, y + 67);
|
||||
break;
|
||||
case 4:
|
||||
DrawOrnament(g, x + 5, y + 67);
|
||||
DrawOrnament(g, x + 32, y + 67);
|
||||
DrawOrnament(g, x + 61, y + 67);
|
||||
DrawOrnament(g, x + 88, y + 67);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
53
DifferenceOfWheels/DrawningWheels.java
Normal file
53
DifferenceOfWheels/DrawningWheels.java
Normal file
@ -0,0 +1,53 @@
|
||||
package DifferenceOfWheels;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.Random;
|
||||
|
||||
public class DrawningWheels implements IOrnaments {
|
||||
int CountWeel;
|
||||
Random rnd = new Random();
|
||||
int ranOrnament = rnd.nextInt(0, 3);
|
||||
|
||||
@Override
|
||||
public void SetCount(int n) {
|
||||
for (EnumWheels count: EnumWheels.values()) {
|
||||
if (count.get_number() == n) {
|
||||
CountWeel = n;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer get_count_weels () {
|
||||
return CountWeel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void DrawOrnament (Graphics2D g,int x, int y) {
|
||||
g.setColor(Color.BLACK);
|
||||
g.fillOval(x, y, 25, 25);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void DrawWeels(Graphics2D g, int x, int y) {
|
||||
switch (CountWeel){
|
||||
case 2:
|
||||
DrawOrnament(g, x + 10, y + 67);
|
||||
DrawOrnament(g, x + 85, y + 67);
|
||||
break;
|
||||
case 3:
|
||||
DrawOrnament(g, x + 10, y + 67);
|
||||
DrawOrnament(g, x + 38, y + 67);
|
||||
DrawOrnament(g, x + 85, y + 67);
|
||||
break;
|
||||
case 4:
|
||||
DrawOrnament(g, x + 5, y + 67);
|
||||
DrawOrnament(g, x + 32, y + 67);
|
||||
DrawOrnament(g, x + 61, y + 67);
|
||||
DrawOrnament(g, x + 88, y + 67);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
15
DifferenceOfWheels/EnumWheels.java
Normal file
15
DifferenceOfWheels/EnumWheels.java
Normal file
@ -0,0 +1,15 @@
|
||||
package DifferenceOfWheels;
|
||||
|
||||
public enum EnumWheels {
|
||||
Two (2),
|
||||
Three (3),
|
||||
Four (4);
|
||||
|
||||
private int number;
|
||||
|
||||
EnumWheels(int n){
|
||||
this.number = n;
|
||||
}
|
||||
|
||||
public int get_number() { return number; }
|
||||
}
|
10
DifferenceOfWheels/IOrnaments.java
Normal file
10
DifferenceOfWheels/IOrnaments.java
Normal file
@ -0,0 +1,10 @@
|
||||
package DifferenceOfWheels;
|
||||
import java.awt.*;
|
||||
|
||||
public interface IOrnaments {
|
||||
void SetCount(int n);
|
||||
Integer get_count_weels();
|
||||
void DrawOrnament(Graphics2D g, int x, int y);
|
||||
|
||||
void DrawWeels(Graphics2D g, int x, int y);
|
||||
}
|
18
Drawnings/CanvasDumpTruck.java
Normal file
18
Drawnings/CanvasDumpTruck.java
Normal file
@ -0,0 +1,18 @@
|
||||
package Drawnings;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class CanvasDumpTruck extends JComponent {
|
||||
public DrawningTruck _drawningTruck;
|
||||
public CanvasDumpTruck() {}
|
||||
|
||||
public void paintComponent(Graphics g) {
|
||||
if (_drawningTruck == null) {
|
||||
return;
|
||||
}
|
||||
super.paintComponents(g);
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
_drawningTruck.DrawTransport(g2d);
|
||||
super.repaint();
|
||||
}
|
||||
}
|
33
Drawnings/CanvasFormDumpTruckCollection.java
Normal file
33
Drawnings/CanvasFormDumpTruckCollection.java
Normal file
@ -0,0 +1,33 @@
|
||||
package Drawnings;
|
||||
|
||||
import CollectionGenericObjects.AbstractCompany;
|
||||
import CollectionGenericObjects.ICollectionGenericObjects;
|
||||
import CollectionGenericObjects.MassiveGenericObjects;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class CanvasFormDumpTruckCollection <T> extends JComponent {
|
||||
public ICollectionGenericObjects<T> collection = new MassiveGenericObjects<T>();
|
||||
public AbstractCompany company = null;
|
||||
public void SetCollectionToCanvas(AbstractCompany company) {
|
||||
this.company = company;
|
||||
}
|
||||
public CanvasFormDumpTruckCollection(){};
|
||||
public void paintComponent(Graphics g) {
|
||||
super.paintComponents(g);
|
||||
if (company == null || company._collection == null) {
|
||||
return;
|
||||
}
|
||||
company.DrawBackgound(g);
|
||||
for (int i = 0; i < company._collection.getCount(); i++) {
|
||||
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
T obj = (T)company._collection.Get(i);
|
||||
if (obj instanceof DrawningTruck) {
|
||||
((DrawningTruck) obj).DrawTransport(g2d);
|
||||
}
|
||||
}
|
||||
super.repaint();
|
||||
}
|
||||
}
|
9
Drawnings/DirectionType.java
Normal file
9
Drawnings/DirectionType.java
Normal file
@ -0,0 +1,9 @@
|
||||
package Drawnings;
|
||||
|
||||
public enum DirectionType {
|
||||
Up,
|
||||
Down,
|
||||
Left,
|
||||
Right,
|
||||
Unknow
|
||||
}
|
63
Drawnings/DrawningDumpTruck.java
Normal file
63
Drawnings/DrawningDumpTruck.java
Normal file
@ -0,0 +1,63 @@
|
||||
package Drawnings;
|
||||
import DifferenceOfWheels.IOrnaments;
|
||||
import Entities.EntityDumpTruck;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawningDumpTruck extends DrawningTruck{
|
||||
|
||||
public DrawningDumpTruck(int speed, double weight, Color bodyColor,
|
||||
Color additionalColor, Boolean body, Boolean tent)
|
||||
{
|
||||
super(speed, weight, bodyColor);
|
||||
EntityTruck = new EntityDumpTruck(speed, weight, bodyColor, additionalColor, body, tent);
|
||||
SetOrnamentWheel();
|
||||
_ornament.SetCount(random.nextInt(2, 5));
|
||||
|
||||
}
|
||||
|
||||
public DrawningDumpTruck (EntityDumpTruck _dumpTruck, IOrnaments ornament){
|
||||
super(_dumpTruck, ornament);
|
||||
}
|
||||
|
||||
public DrawningDumpTruck(){
|
||||
super(110, 100);
|
||||
}
|
||||
|
||||
public void DrawTransport(Graphics2D g)
|
||||
{
|
||||
if (EntityTruck == null || !(EntityTruck instanceof EntityDumpTruck entityTruck) || _startPosX == null || _startPosY == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
g.setPaint(Color.BLACK);
|
||||
|
||||
_startPosX += 5;
|
||||
super.DrawTransport(g);
|
||||
_startPosX -= 5;
|
||||
|
||||
if (entityTruck.Body)
|
||||
{
|
||||
int[] x_b = {_startPosX, _startPosX + 77, _startPosX + 77, _startPosX + 20};
|
||||
int[] y_b = {_startPosY + 15, _startPosY + 15, _startPosY + 50, _startPosY + 50};
|
||||
|
||||
g.setPaint(Color.BLACK);
|
||||
g.drawPolygon(x_b, y_b, 4);
|
||||
g.setPaint(entityTruck.AdditionalColor);
|
||||
g.fillPolygon(x_b, y_b, 4);
|
||||
}
|
||||
|
||||
if (entityTruck.Tent && entityTruck.Body)
|
||||
{
|
||||
int[] x_t = {_startPosX, _startPosX + 39, _startPosX + 77};
|
||||
int[] y_t = {_startPosY + 13, _startPosY, _startPosY + 13};
|
||||
|
||||
g.setPaint(Color.BLACK);
|
||||
g.drawPolygon(x_t, y_t, 3);
|
||||
g.setPaint(entityTruck.AdditionalColor);
|
||||
g.fillPolygon(x_t, y_t, 3);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
217
Drawnings/DrawningTruck.java
Normal file
217
Drawnings/DrawningTruck.java
Normal file
@ -0,0 +1,217 @@
|
||||
package Drawnings;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.Random;
|
||||
import DifferenceOfWheels.*;
|
||||
import Entities.EntityTruck;
|
||||
|
||||
|
||||
public class DrawningTruck {
|
||||
public EntityTruck EntityTruck;
|
||||
protected EntityTruck get_EntityTruck() { return EntityTruck; }
|
||||
public IOrnaments _ornament = new DrawningWheels();
|
||||
int CountOfWheels = 0;
|
||||
int ornament_type;
|
||||
|
||||
// Ширина окна
|
||||
private Integer _pictureWidth;
|
||||
|
||||
// Высота окна
|
||||
private Integer _pictureHeight;
|
||||
|
||||
// Левая координата прорисовки автомобиля
|
||||
protected Integer _startPosX;
|
||||
|
||||
// Верхняя кооридната прорисовки автомобиля
|
||||
protected Integer _startPosY;
|
||||
|
||||
// Ширина прорисовки самосвала
|
||||
private int _drawningTruckWidth = 110; //100
|
||||
|
||||
// Высота прорисовки самосвала
|
||||
private int _drawningTruckHeight = 110; //92
|
||||
|
||||
public Integer GetPosX() { return _startPosX;}
|
||||
public Integer GetPosY() { return _startPosY;}
|
||||
public Integer GetWidth() { return _drawningTruckWidth;}
|
||||
public Integer GetHeight() { return _drawningTruckHeight;}
|
||||
Random random = new Random();
|
||||
|
||||
private DrawningTruck()
|
||||
{
|
||||
_pictureWidth = null;
|
||||
_pictureHeight = null;
|
||||
_startPosX = null;
|
||||
_startPosY = null;
|
||||
|
||||
}
|
||||
|
||||
public DrawningTruck(int speed, double weight, Color bodyColor)
|
||||
{
|
||||
EntityTruck = new EntityTruck(speed, weight, bodyColor);
|
||||
CountOfWheels = random.nextInt(2, 5);
|
||||
ornament_type = random.nextInt(0, 3);
|
||||
}
|
||||
|
||||
protected DrawningTruck(int drawningTruckWidth, int drawningTruckHeight)
|
||||
{
|
||||
_drawningTruckWidth = drawningTruckWidth;
|
||||
_drawningTruckHeight = drawningTruckHeight;
|
||||
}
|
||||
|
||||
public DrawningTruck(EntityTruck _truck, IOrnaments ornament){
|
||||
EntityTruck = _truck;
|
||||
_ornament = ornament;
|
||||
if (_ornament instanceof DrawningOrnamentStar) ornament_type = 0;
|
||||
else if (_ornament instanceof DrawningOrnamentTriangle) ornament_type = 1;
|
||||
else if (_ornament instanceof DrawningOrnamentRectangle) ornament_type = 2;
|
||||
CountOfWheels = _ornament.get_count_weels();
|
||||
}
|
||||
|
||||
protected void SetOrnamentWheel(){
|
||||
switch (ornament_type){
|
||||
case 0:
|
||||
_ornament = new DrawningOrnamentStar();
|
||||
_ornament.SetCount(CountOfWheels);
|
||||
break;
|
||||
case 1:
|
||||
_ornament = new DrawningOrnamentTriangle();
|
||||
_ornament.SetCount(CountOfWheels);
|
||||
break;
|
||||
case 2:
|
||||
_ornament = new DrawningOrnamentRectangle();
|
||||
_ornament.SetCount(CountOfWheels);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public Boolean SetPictureSize(int width, int height)
|
||||
{
|
||||
if (_drawningTruckWidth > width || _drawningTruckHeight > height)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (_pictureWidth != null && width != _pictureWidth || _pictureHeight != null && height != _pictureHeight)
|
||||
{
|
||||
if (_startPosX + _drawningTruckWidth > width)
|
||||
{
|
||||
_startPosX -= _drawningTruckWidth;
|
||||
}
|
||||
|
||||
if (_startPosY + _drawningTruckHeight > height)
|
||||
{
|
||||
_startPosY -= _drawningTruckHeight;
|
||||
}
|
||||
}
|
||||
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
return true;
|
||||
}
|
||||
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
if (_pictureHeight == null|| _pictureWidth == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (x < 0)
|
||||
{
|
||||
x = 0;
|
||||
}
|
||||
if (x + _drawningTruckWidth > _pictureWidth)
|
||||
{
|
||||
x = (int)_pictureWidth - _drawningTruckWidth;
|
||||
}
|
||||
if (y < 0)
|
||||
{
|
||||
y = 0;
|
||||
}
|
||||
if (y + _drawningTruckHeight > _pictureHeight)
|
||||
{
|
||||
y = (int)_pictureHeight - _drawningTruckHeight;
|
||||
|
||||
}
|
||||
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
|
||||
}
|
||||
|
||||
public Boolean MoveTransport(DirectionType direction)
|
||||
{
|
||||
if (EntityTruck == null || _startPosX == null || _startPosY == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (direction)
|
||||
{
|
||||
//влево
|
||||
case DirectionType.Left:
|
||||
if (_startPosX - _drawningTruckWidth > 0)
|
||||
{
|
||||
_startPosX -= (int)EntityTruck.Step;
|
||||
}
|
||||
return true;
|
||||
//вверх
|
||||
case DirectionType.Up:
|
||||
if (_startPosY - _drawningTruckHeight > 0)
|
||||
{
|
||||
_startPosY -= (int)EntityTruck.Step;
|
||||
}
|
||||
return true;
|
||||
// вправо
|
||||
case DirectionType.Right:
|
||||
if (_startPosX + _drawningTruckWidth + (int)EntityTruck.Step < _pictureWidth)
|
||||
{
|
||||
_startPosX += (int)EntityTruck.Step;
|
||||
}
|
||||
return true;
|
||||
//вниз
|
||||
case DirectionType.Down:
|
||||
if (_startPosY + _drawningTruckHeight + (int)EntityTruck.Step < _pictureHeight)
|
||||
{
|
||||
_startPosY += (int)EntityTruck.Step;
|
||||
}
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void DrawTransport(Graphics2D g)
|
||||
{
|
||||
if (EntityTruck == null || _startPosX == null || _startPosY == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
g.setPaint(Color.BLACK);
|
||||
|
||||
// Колёса
|
||||
g.setPaint(Color.BLACK);
|
||||
SetOrnamentWheel();
|
||||
if (_ornament != null){
|
||||
_ornament.DrawWeels(g, _startPosX - 5, _startPosY);
|
||||
}
|
||||
|
||||
//Границы самосвала
|
||||
g.drawRect( _startPosX + 5, _startPosY + 53, 100, 13);
|
||||
g.drawRect( _startPosX + 75, _startPosY + 15, 30, 36);
|
||||
g.drawRect(_startPosX + 80, _startPosY + 20, 20, 20);
|
||||
|
||||
// Кузов
|
||||
g.setPaint(EntityTruck.BodyColor);
|
||||
g.fillRect(_startPosX + 5, _startPosY + 53, 100, 13);
|
||||
g.fillRect(_startPosX + 75, _startPosY + 15, 30, 36);
|
||||
|
||||
//Окно
|
||||
g.setPaint(Color.CYAN);
|
||||
g.fillRect(_startPosX + 80, _startPosY + 20, 20, 20);
|
||||
|
||||
}
|
||||
|
||||
}
|
26
Entities/EntityDumpTruck.java
Normal file
26
Entities/EntityDumpTruck.java
Normal file
@ -0,0 +1,26 @@
|
||||
package Entities;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class EntityDumpTruck extends EntityTruck {
|
||||
|
||||
public Color AdditionalColor;
|
||||
private Color get_AdditionalColor(){ return AdditionalColor; }
|
||||
|
||||
public Boolean Body;
|
||||
private Boolean get_Body() { return Body; }
|
||||
|
||||
public Boolean Tent;
|
||||
private Boolean get_Tent() { return Tent; }
|
||||
|
||||
public double Step;
|
||||
|
||||
public EntityDumpTruck(int speed, double weight, Color bodyColor, Color additionalColor, Boolean body, Boolean tent)
|
||||
{
|
||||
super (speed, weight, bodyColor);
|
||||
AdditionalColor = additionalColor;
|
||||
Body = body;
|
||||
Tent = tent;
|
||||
}
|
||||
|
||||
}
|
24
Entities/EntityTruck.java
Normal file
24
Entities/EntityTruck.java
Normal file
@ -0,0 +1,24 @@
|
||||
package Entities;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class EntityTruck {
|
||||
public int Speed;
|
||||
private int get_Speed(){ return Speed; }
|
||||
|
||||
public double Weight;
|
||||
private double get_Weight(){return Weight; }
|
||||
|
||||
public Color BodyColor;
|
||||
public Color get_BodyColor(){ return BodyColor; }
|
||||
|
||||
public double Step;
|
||||
|
||||
public EntityTruck(int speed, double weight, Color bodyColor)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
Step = (speed * 100) / weight;
|
||||
}
|
||||
}
|
147
FormAdditionalCollection.java
Normal file
147
FormAdditionalCollection.java
Normal file
@ -0,0 +1,147 @@
|
||||
import CollectionGenericObjects.AbstractCompany;
|
||||
import CollectionGenericObjects.AdditionalCollection;
|
||||
import DifferenceOfWheels.DrawningOrnamentRectangle;
|
||||
import DifferenceOfWheels.DrawningOrnamentStar;
|
||||
import DifferenceOfWheels.DrawningOrnamentTriangle;
|
||||
import DifferenceOfWheels.IOrnaments;
|
||||
import Drawnings.CanvasDumpTruck;
|
||||
import Drawnings.DrawningDumpTruck;
|
||||
import Drawnings.DrawningTruck;
|
||||
import Entities.EntityDumpTruck;
|
||||
import Entities.EntityTruck;
|
||||
|
||||
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{
|
||||
DrawningTruck _drawningTruck;
|
||||
private AbstractCompany _company = null;
|
||||
private CanvasDumpTruck _canvasTruck = new CanvasDumpTruck();
|
||||
private AdditionalCollection<EntityTruck, IOrnaments> _additionalCollection = null;
|
||||
private Random random = new Random();
|
||||
private JButton buttonGenerate = new JButton("Создать");
|
||||
private JButton buttonAdd = new JButton("Добавить");
|
||||
private JList<String> listEntity = new JList<String>();
|
||||
private JList<String> listOrnament = new JList<String>();
|
||||
public FormAdditionalCollection() {
|
||||
setTitle("Случайный грузовик");
|
||||
setMinimumSize(new Dimension(650,310));
|
||||
_additionalCollection = new AdditionalCollection<EntityTruck, IOrnaments>(3,
|
||||
(Class) EntityTruck.class, (Class) IOrnaments.class);
|
||||
AddEntities();
|
||||
AddOrnaments();
|
||||
buttonGenerate.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
_drawningTruck = _additionalCollection.CreateDrawningTruckClass();
|
||||
_drawningTruck.SetPictureSize(getWidth(), getHeight());
|
||||
_drawningTruck.SetPosition(50,50);
|
||||
_canvasTruck.repaint();
|
||||
_canvasTruck._drawningTruck = _drawningTruck;
|
||||
DrawningTruck _copyTruck;
|
||||
if (_drawningTruck instanceof DrawningDumpTruck)
|
||||
_copyTruck = new DrawningDumpTruck((EntityDumpTruck) _drawningTruck.EntityTruck, _drawningTruck._ornament);
|
||||
else
|
||||
_copyTruck = new DrawningTruck(_drawningTruck.EntityTruck, _drawningTruck._ornament);
|
||||
_company._collection.Insert(_copyTruck);
|
||||
|
||||
String[] data1 = new String[_additionalCollection.Len_entity];
|
||||
for (int i = 0; i < _additionalCollection.Len_entity; i++) {
|
||||
EntityTruck _entity = _additionalCollection._collectionEntityTruck[i];
|
||||
data1[i] = ToString(_entity);
|
||||
}
|
||||
String[] data2 = new String[_additionalCollection.Len_ornament];
|
||||
for (int i = 0; i < _additionalCollection.Len_ornament; i++) {
|
||||
IOrnaments ornament = _additionalCollection._collectionIOrnaments[i];
|
||||
data2[i] = ToString(ornament);
|
||||
}
|
||||
listEntity.setListData(data1);
|
||||
listOrnament.setListData(data2);
|
||||
}
|
||||
});
|
||||
|
||||
buttonAdd.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
FormDumpTruckCollection.canvasShow();
|
||||
}
|
||||
});
|
||||
|
||||
buttonGenerate.setBounds(450, 10, 100, 50);
|
||||
buttonAdd.setBounds(450, 70, 100, 50);
|
||||
add(buttonGenerate);
|
||||
add(buttonAdd);
|
||||
listEntity.setBounds(10,200,300,60);
|
||||
listOrnament.setBounds(320,200,300,60);
|
||||
add(listEntity);
|
||||
add(listOrnament);
|
||||
add(_canvasTruck);
|
||||
setVisible(true);
|
||||
}
|
||||
private String ToString(EntityTruck entity) {
|
||||
String str = "";
|
||||
if (entity instanceof EntityDumpTruck) str += "Самосвал ";
|
||||
else str += "Грузовик ";
|
||||
str += entity.get_BodyColor().toString();
|
||||
return str;
|
||||
}
|
||||
private String ToString(IOrnaments ornament) {
|
||||
if (ornament == null || ornament.get_count_weels() == null)
|
||||
return "Нет орнамента";
|
||||
String str = "Орнамент ";
|
||||
if (ornament instanceof DrawningOrnamentRectangle) str += "Квадрат ";
|
||||
else if (ornament instanceof DrawningOrnamentStar) str += "Звезда ";
|
||||
else if (ornament instanceof DrawningOrnamentTriangle) str += "Треугольник ";
|
||||
str += ornament.get_count_weels().toString();
|
||||
return str;
|
||||
}
|
||||
public void AddEntities() {
|
||||
for (int i = 0; i < _additionalCollection.Len_entity; 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));
|
||||
EntityTruck entity;
|
||||
if (random.nextBoolean()) {
|
||||
entity = new EntityTruck(speed, weight, bodycolor);
|
||||
}
|
||||
else {
|
||||
Color additionalcolor = new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256));
|
||||
boolean body = random.nextBoolean();
|
||||
boolean tent = random.nextBoolean();
|
||||
entity = new EntityDumpTruck(speed, weight, bodycolor,
|
||||
additionalcolor, body, tent);
|
||||
}
|
||||
_additionalCollection.Insert(entity);
|
||||
}
|
||||
}
|
||||
public void AddOrnaments() {
|
||||
for (int i = 0; i < _additionalCollection.Len_ornament; i++) {
|
||||
random = new Random();
|
||||
Integer count_of_wheels = random.nextInt(2, 5);
|
||||
IOrnaments _ornament = null;
|
||||
switch (random.nextInt(0,3)) {
|
||||
case 0:
|
||||
_ornament = new DrawningOrnamentStar();
|
||||
break;
|
||||
case 1:
|
||||
_ornament = new DrawningOrnamentTriangle();
|
||||
break;
|
||||
case 2:
|
||||
_ornament = new DrawningOrnamentRectangle();
|
||||
break;
|
||||
default:
|
||||
count_of_wheels = null;
|
||||
break;
|
||||
}
|
||||
if (_ornament != null) _ornament.SetCount(count_of_wheels);
|
||||
_additionalCollection.Insert(_ornament);
|
||||
}
|
||||
}
|
||||
void setCompany(AbstractCompany company) {
|
||||
this._company = company;
|
||||
}
|
||||
}
|
220
FormDumpTruck.java
Normal file
220
FormDumpTruck.java
Normal file
@ -0,0 +1,220 @@
|
||||
import Drawnings.CanvasDumpTruck;
|
||||
import Drawnings.DirectionType;
|
||||
import Drawnings.DrawningDumpTruck;
|
||||
import Drawnings.DrawningTruck;
|
||||
import MovementStrategy.*;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ComponentAdapter;
|
||||
import java.awt.event.ComponentEvent;
|
||||
import javax.swing.*;
|
||||
import java.util.Random;
|
||||
|
||||
public class FormDumpTruck extends JFrame{
|
||||
|
||||
private CanvasDumpTruck _canvasDumpTruck = new CanvasDumpTruck();
|
||||
|
||||
private AbstractStrategy _strategy;
|
||||
|
||||
// Размер формы
|
||||
private Dimension dimension;
|
||||
// Название формы
|
||||
private String title;
|
||||
|
||||
private JButton CreateDumpTruckButton = new JButton("Создать грузовик");
|
||||
private JButton CreateTruckButton = new JButton("Создать самосвал");
|
||||
private JButton UpButton = new JButton();
|
||||
private JButton DownButton = new JButton();;
|
||||
private JButton LeftButton = new JButton();;
|
||||
private JButton RightButton = new JButton();
|
||||
private JComboBox ComboBoxStrategy = new JComboBox(new String[]{"К центру", "К краю"});
|
||||
private JButton ButtonStrategy = new JButton("Шаг");
|
||||
|
||||
public FormDumpTruck(String title, Dimension dimension) {
|
||||
this.title = title;
|
||||
this.dimension = dimension;
|
||||
}
|
||||
|
||||
private void CreateObject(String type){
|
||||
Random random = new Random();
|
||||
Color bodyColor = new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256));
|
||||
switch(type){
|
||||
case "DrawningTruck":
|
||||
_canvasDumpTruck._drawningTruck = new Drawnings.DrawningTruck(random.nextInt(100, 300), random.nextInt(1000, 3000),
|
||||
bodyColor);
|
||||
_canvasDumpTruck._drawningTruck.SetPictureSize(getWidth(), getHeight());
|
||||
_canvasDumpTruck._drawningTruck.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100));
|
||||
_canvasDumpTruck.repaint();
|
||||
break;
|
||||
case "DrawningDumpTruck":
|
||||
Color additionalColor = new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256));
|
||||
_canvasDumpTruck._drawningTruck = new DrawningDumpTruck();
|
||||
_canvasDumpTruck._drawningTruck = new DrawningDumpTruck(random.nextInt(100, 300), random.nextInt(1000, 3000),
|
||||
bodyColor, additionalColor,
|
||||
random.nextBoolean(), random.nextBoolean());
|
||||
_canvasDumpTruck._drawningTruck.SetPictureSize(getWidth(), getHeight());
|
||||
_canvasDumpTruck._drawningTruck.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100));
|
||||
_canvasDumpTruck.repaint();
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
_strategy = null;
|
||||
ComboBoxStrategy.setEnabled(true);
|
||||
}
|
||||
|
||||
public void Form(DrawningTruck _truck) {
|
||||
CreateDumpTruckButton.setName("Создать самосвал");
|
||||
CreateTruckButton.setName("Создать грузовик");
|
||||
setMinimumSize(dimension);
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
|
||||
_canvasDumpTruck._drawningTruck = _truck;
|
||||
|
||||
UpButton.setName("UP");
|
||||
Icon iconUp = new ImageIcon("C:\\Users\\Antonovs\\Downloads\\ArrowUp.png");
|
||||
UpButton.setIcon(iconUp);
|
||||
|
||||
DownButton.setName("DOWN");
|
||||
Icon iconDown = new ImageIcon("C:\\Users\\Antonovs\\Downloads\\ArrowDown.png");
|
||||
DownButton.setIcon(iconDown);
|
||||
|
||||
LeftButton.setName("LEFT");
|
||||
Icon iconLeft = new ImageIcon("C:\\Users\\Antonovs\\Downloads\\ArrowLeft.png");
|
||||
LeftButton.setIcon(iconLeft);
|
||||
|
||||
RightButton.setName("RIGHT");
|
||||
Icon iconRight = new ImageIcon("C:\\Users\\Antonovs\\Downloads\\ArrowRight.png");
|
||||
RightButton.setIcon(iconRight);
|
||||
|
||||
CreateTruckButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
CreateObject("DrawningTruck");
|
||||
}
|
||||
});
|
||||
|
||||
CreateDumpTruckButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
CreateObject("DrawningDumpTruck");
|
||||
}
|
||||
});
|
||||
|
||||
ButtonStrategy.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (_canvasDumpTruck._drawningTruck == 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 MoveableTruck(_canvasDumpTruck._drawningTruck), getWidth() - 23, getHeight()-23);
|
||||
}
|
||||
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 (_canvasDumpTruck._drawningTruck == null) return;
|
||||
boolean result = false;
|
||||
switch ((((JButton) (event.getSource())).getName())) {
|
||||
case "UP":
|
||||
result = _canvasDumpTruck._drawningTruck.MoveTransport(DirectionType.Up);
|
||||
break;
|
||||
case "DOWN":
|
||||
result = _canvasDumpTruck._drawningTruck.MoveTransport(DirectionType.Down);
|
||||
break;
|
||||
case "LEFT":
|
||||
result = _canvasDumpTruck._drawningTruck.MoveTransport(DirectionType.Left);
|
||||
break;
|
||||
case "RIGHT":
|
||||
result = _canvasDumpTruck._drawningTruck.MoveTransport(DirectionType.Right);
|
||||
break;
|
||||
}
|
||||
if (result) {
|
||||
_canvasDumpTruck.repaint();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
UpButton.addActionListener(actionListener);
|
||||
DownButton.addActionListener(actionListener);
|
||||
LeftButton.addActionListener(actionListener);
|
||||
RightButton.addActionListener(actionListener);
|
||||
|
||||
setSize(dimension.width, dimension.height);
|
||||
setLayout(null);
|
||||
_canvasDumpTruck.setBounds(0, 0, getWidth(), getHeight());
|
||||
// кнопки создаиния самосвала и грузовика
|
||||
CreateDumpTruckButton.setBounds(10, getHeight() - 90, 160, 40);
|
||||
CreateTruckButton.setBounds(160, getHeight() - 90, 160, 40);
|
||||
// кнопки направлений
|
||||
UpButton.setBounds(getWidth() - 150, getHeight() - 170, 60, 60);
|
||||
DownButton.setBounds(getWidth() - 140, getHeight() - 100, 60, 60);
|
||||
RightButton.setBounds(getWidth() - 85, getHeight() - 100, 60, 60);
|
||||
LeftButton.setBounds(getWidth() - 215, getHeight() - 100, 60, 60);
|
||||
// кнокпи для стратегий
|
||||
ComboBoxStrategy.setBounds(getWidth() - 170, 10, 140, 35);
|
||||
ButtonStrategy.setBounds(getWidth() - 130, 55, 100, 25);
|
||||
// добавление кнопок
|
||||
add(CreateDumpTruckButton);
|
||||
add(CreateTruckButton);
|
||||
add(UpButton);
|
||||
add(DownButton);
|
||||
add(RightButton);
|
||||
add(LeftButton);
|
||||
add(_canvasDumpTruck);
|
||||
add(ComboBoxStrategy);
|
||||
add(ButtonStrategy);
|
||||
pack();
|
||||
setVisible(true);
|
||||
|
||||
addComponentListener(new ComponentAdapter() {
|
||||
public void componentResized(ComponentEvent e) {
|
||||
int Width = getWidth();
|
||||
int Height = getHeight();
|
||||
if (_canvasDumpTruck._drawningTruck != null)
|
||||
_canvasDumpTruck._drawningTruck.SetPictureSize(Width, Height);
|
||||
_canvasDumpTruck.setBounds(0, 0, getWidth(), getHeight());
|
||||
CreateDumpTruckButton.setBounds(10, getHeight() - 90, 160, 40);
|
||||
CreateTruckButton.setBounds(180, getHeight() - 90, 160, 40);
|
||||
UpButton.setBounds(getWidth() - 150, getHeight() - 170, 60, 60);
|
||||
DownButton.setBounds(getWidth() - 150, getHeight() - 100, 60, 60);
|
||||
RightButton.setBounds(getWidth() - 85, getHeight() - 100, 60, 60);
|
||||
LeftButton.setBounds(getWidth() - 215, getHeight() - 100, 60, 60);
|
||||
ComboBoxStrategy.setBounds(getWidth() - 170, 10, 140, 35);
|
||||
ButtonStrategy.setBounds(getWidth() - 130, 55, 100, 25);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
225
FormDumpTruckCollection.java
Normal file
225
FormDumpTruckCollection.java
Normal file
@ -0,0 +1,225 @@
|
||||
import CollectionGenericObjects.AbstractCompany;
|
||||
import CollectionGenericObjects.MassiveGenericObjects;
|
||||
import CollectionGenericObjects.TruckShearingService;
|
||||
import Drawnings.CanvasFormDumpTruckCollection;
|
||||
import Drawnings.DrawningDumpTruck;
|
||||
import Drawnings.DrawningTruck;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.text.MaskFormatter;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ComponentAdapter;
|
||||
import java.awt.event.ComponentEvent;
|
||||
import java.text.ParseException;
|
||||
import java.util.Random;
|
||||
|
||||
import static java.lang.Integer.parseInt;
|
||||
|
||||
public class FormDumpTruckCollection extends JFrame {
|
||||
private String title;
|
||||
private Dimension dimension;
|
||||
public static CanvasFormDumpTruckCollection<DrawningTruck> _canvasDumpTruck = new CanvasFormDumpTruckCollection<DrawningTruck>();
|
||||
private static AbstractCompany _company = null;
|
||||
private JButton CreateDumpTruckButton = new JButton("Создать самосвал");;
|
||||
private JButton CreateTruckButton = new JButton("Создать грузовик");
|
||||
private JButton RemoveButton = new JButton("Удалить");
|
||||
private JButton GoToCheckButton = new JButton("Передать на тесты");
|
||||
private JButton RandomButton = new JButton("Рандомный грузовик");
|
||||
private JButton RefreshButton = new JButton("Обновить");
|
||||
private JComboBox ComboBoxCollections = new JComboBox(new String[]{"", "Хранилище"});
|
||||
private JFormattedTextField MaskedTextField;
|
||||
private Random random = new Random();
|
||||
|
||||
public FormDumpTruckCollection(String title, Dimension dimension) {
|
||||
this.title = title;
|
||||
this.dimension = dimension;
|
||||
}
|
||||
|
||||
public static void canvasShow() {
|
||||
_company.SetPosition();
|
||||
_canvasDumpTruck.SetCollectionToCanvas(_company);
|
||||
_canvasDumpTruck.repaint();
|
||||
}
|
||||
|
||||
private void CreateObject(String type){
|
||||
DrawningTruck _drawningTruck;
|
||||
Color bodyColor = new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256));
|
||||
switch(type){
|
||||
case "DrawningTruck":
|
||||
_drawningTruck = new DrawningTruck(random.nextInt(100, 300), random.nextInt(1000, 3000),
|
||||
bodyColor);
|
||||
break;
|
||||
case "DrawningDumpTruck":
|
||||
Color additionalColor = new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256));
|
||||
_drawningTruck = new DrawningDumpTruck(random.nextInt(100, 300), random.nextInt(1000, 3000),
|
||||
bodyColor, additionalColor,
|
||||
random.nextBoolean(), random.nextBoolean());
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
if (_company._collection.Insert(_drawningTruck) >= 0){
|
||||
JOptionPane.showMessageDialog(null, "Объект добавлен");
|
||||
canvasShow();
|
||||
}
|
||||
else{
|
||||
JOptionPane.showMessageDialog(null, "Объект не удалось добавить");
|
||||
}
|
||||
}
|
||||
|
||||
public Color getColor() {
|
||||
Color initializator = new Color(random.nextInt(0, 256),random.nextInt(0, 256),random.nextInt(0, 256));
|
||||
Color _color = JColorChooser.showDialog(this, "Выберите цвет", initializator);
|
||||
return _color;
|
||||
}
|
||||
|
||||
public void Form(){
|
||||
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);
|
||||
|
||||
ComboBoxCollections.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
switch (ComboBoxCollections.getSelectedItem().toString()) {
|
||||
case "Хранилище":
|
||||
_company = new TruckShearingService(getWidth()-200, getHeight()-70, new MassiveGenericObjects<DrawningTruck>());
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
CreateTruckButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
CreateObject("DrawningTruck");
|
||||
}
|
||||
});
|
||||
CreateDumpTruckButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
CreateObject("DrawningDumpTruck");
|
||||
}
|
||||
});
|
||||
|
||||
RemoveButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (_company == null || MaskedTextField.getText() == null) {
|
||||
return;
|
||||
}
|
||||
int pos = parseInt(MaskedTextField.getText());
|
||||
int resultConfirmDialog = JOptionPane.showConfirmDialog(null,
|
||||
"Удалить", "Удаление",
|
||||
JOptionPane.YES_NO_OPTION);
|
||||
if (resultConfirmDialog == JOptionPane.NO_OPTION) return;
|
||||
if (_company._collection.Remove(pos) != null) {
|
||||
JOptionPane.showMessageDialog(null, "Объект удален");
|
||||
canvasShow();
|
||||
}
|
||||
else {
|
||||
JOptionPane.showMessageDialog(null, "Объект не удалось удалить");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
GoToCheckButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (_company == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
DrawningTruck _truck = null;
|
||||
int counter = 100;
|
||||
while (_truck == null)
|
||||
{
|
||||
_truck = _company.GetRandomObject();
|
||||
counter--;
|
||||
if (counter <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (_truck == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
FormDumpTruck form = new FormDumpTruck("Самосвал", new Dimension(900,565));
|
||||
form.Form(_truck);
|
||||
}
|
||||
});
|
||||
|
||||
RandomButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (_company == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
FormAdditionalCollection form = new FormAdditionalCollection();
|
||||
form.setCompany(_company);
|
||||
}
|
||||
});
|
||||
|
||||
RefreshButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (_company == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
canvasShow();
|
||||
}
|
||||
});
|
||||
|
||||
_canvasDumpTruck.setBounds(0, 0, getWidth()-200, getHeight());
|
||||
ComboBoxCollections.setBounds(getWidth()-170, 10, 150, 20);
|
||||
CreateTruckButton.setBounds(getWidth()-170, 60, 160, 30);
|
||||
CreateDumpTruckButton.setBounds(getWidth()-170, 100, 160, 30);
|
||||
MaskedTextField.setBounds(getWidth()-170,200,150,30);
|
||||
RemoveButton.setBounds(getWidth()-170, 240, 150, 30);
|
||||
GoToCheckButton.setBounds(getWidth()-170, 280, 150, 30);
|
||||
RandomButton.setBounds(getWidth()-170, 320, 150, 30);
|
||||
RefreshButton.setBounds(getWidth()-170, getHeight()-90, 150, 30);
|
||||
|
||||
setSize(dimension.width,dimension.height);
|
||||
setLayout(null);
|
||||
add(_canvasDumpTruck);
|
||||
add(ComboBoxCollections);
|
||||
add(CreateTruckButton);
|
||||
add(CreateDumpTruckButton);
|
||||
add(MaskedTextField);
|
||||
add(RemoveButton);
|
||||
add(GoToCheckButton);
|
||||
add(RandomButton);
|
||||
add(RefreshButton);
|
||||
setVisible(true);
|
||||
|
||||
addComponentListener(new ComponentAdapter() {
|
||||
public void componentResized(ComponentEvent e) {
|
||||
_canvasDumpTruck.setBounds(0, 0, getWidth()-200, getHeight()-70);
|
||||
ComboBoxCollections.setBounds(getWidth()-170, 10, 150, 20);
|
||||
CreateTruckButton.setBounds(getWidth()-170, 60, 160, 30);
|
||||
CreateDumpTruckButton.setBounds(getWidth()-170, 100, 160, 30);
|
||||
MaskedTextField.setBounds(getWidth()-170,200,150,30);
|
||||
RemoveButton.setBounds(getWidth()-170, 240, 150, 30);
|
||||
GoToCheckButton.setBounds(getWidth()-170, 280, 150, 30);
|
||||
RandomButton.setBounds(getWidth()-170, 320, 150, 30);
|
||||
RefreshButton.setBounds(getWidth()-170, getHeight()-90, 150, 30);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -1,5 +1,8 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
System.out.println();
|
||||
FormDumpTruckCollection formDumpTruck = new FormDumpTruckCollection("Самосвал", new Dimension(950, 700));
|
||||
formDumpTruck.Form();
|
||||
}
|
||||
}
|
||||
|
60
MovementStrategy/AbstractStrategy.java
Normal file
60
MovementStrategy/AbstractStrategy.java
Normal file
@ -0,0 +1,60 @@
|
||||
package MovementStrategy;
|
||||
|
||||
public abstract class AbstractStrategy {
|
||||
private IMoveableObject _moveableObject;
|
||||
private StrategyStatus _state = StrategyStatus.NotInit;
|
||||
protected int FieldWidth;
|
||||
protected int FieldHeight;
|
||||
public StrategyStatus GetStatus() { return _state; }
|
||||
public void SetData(IMoveableObject moveableObject, int width, int height)
|
||||
{
|
||||
if (moveableObject == null)
|
||||
{
|
||||
_state = StrategyStatus.NotInit;
|
||||
return;
|
||||
}
|
||||
_state = StrategyStatus.InProgress;
|
||||
_moveableObject = moveableObject;
|
||||
FieldWidth = width;
|
||||
FieldHeight = height;
|
||||
}
|
||||
public void MakeStep()
|
||||
{
|
||||
if (_state != StrategyStatus.InProgress)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (IsTargetDestinaion())
|
||||
{
|
||||
_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 IsTargetDestinaion();
|
||||
private boolean MoveTo(MovementDirection movementDirection)
|
||||
{
|
||||
if (_state != StrategyStatus.InProgress)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (_moveableObject.TryMoveObject(movementDirection))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
}
|
7
MovementStrategy/IMoveableObject.java
Normal file
7
MovementStrategy/IMoveableObject.java
Normal file
@ -0,0 +1,7 @@
|
||||
package MovementStrategy;
|
||||
|
||||
public interface IMoveableObject {
|
||||
ObjectParameters GetObjectPosition();
|
||||
int GetStep();
|
||||
Boolean TryMoveObject(MovementDirection direction);
|
||||
}
|
36
MovementStrategy/MoveToBorder.java
Normal file
36
MovementStrategy/MoveToBorder.java
Normal file
@ -0,0 +1,36 @@
|
||||
package MovementStrategy;
|
||||
|
||||
public class MoveToBorder extends AbstractStrategy{
|
||||
@Override
|
||||
protected boolean IsTargetDestinaion() {
|
||||
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 diffX = FieldWidth - objParams.RightBorder;
|
||||
if (Math.abs(diffX) > GetStep())
|
||||
{
|
||||
MoveRight();
|
||||
}
|
||||
|
||||
int diffY = FieldHeight - objParams.DownBorder;
|
||||
if (Math.abs(diffY) > GetStep())
|
||||
{
|
||||
MoveDown();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
38
MovementStrategy/MoveToCenter.java
Normal file
38
MovementStrategy/MoveToCenter.java
Normal file
@ -0,0 +1,38 @@
|
||||
package MovementStrategy;
|
||||
|
||||
public class MoveToCenter extends AbstractStrategy{
|
||||
@Override
|
||||
protected boolean IsTargetDestinaion() {
|
||||
ObjectParameters objParams = GetObjectParameters();
|
||||
if (objParams == null) {
|
||||
return false;
|
||||
}
|
||||
return objParams.ObjectMiddleHorizontal - GetStep() <= FieldWidth / 2 - GetStep() &&
|
||||
objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth / 2 - GetStep() &&
|
||||
objParams.ObjectMiddleVertical - GetStep() <= FieldHeight / 2 - GetStep() &&
|
||||
objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2 - GetStep() ;
|
||||
}
|
||||
@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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
48
MovementStrategy/MoveableTruck.java
Normal file
48
MovementStrategy/MoveableTruck.java
Normal file
@ -0,0 +1,48 @@
|
||||
package MovementStrategy;
|
||||
|
||||
import Drawnings.CanvasDumpTruck;
|
||||
import Drawnings.DirectionType;
|
||||
import Drawnings.DrawningTruck;
|
||||
|
||||
public class MoveableTruck implements IMoveableObject {
|
||||
private CanvasDumpTruck canvas = new CanvasDumpTruck();
|
||||
public MoveableTruck(DrawningTruck drawningTruck)
|
||||
{
|
||||
canvas._drawningTruck = drawningTruck;
|
||||
}
|
||||
@Override
|
||||
public ObjectParameters GetObjectPosition() {
|
||||
if (canvas._drawningTruck == null || canvas._drawningTruck.EntityTruck == null ||
|
||||
canvas._drawningTruck.GetPosX() == null || canvas._drawningTruck.GetPosY() == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new ObjectParameters(canvas._drawningTruck.GetPosX(), canvas._drawningTruck.GetPosY(),
|
||||
canvas._drawningTruck.GetWidth(), canvas._drawningTruck.GetHeight());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int GetStep() {
|
||||
return (int)(canvas._drawningTruck.EntityTruck.Step);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean TryMoveObject(MovementDirection direction) {
|
||||
if (canvas._drawningTruck == null || canvas._drawningTruck.EntityTruck == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return canvas._drawningTruck.MoveTransport(GetDirectionType(direction));
|
||||
}
|
||||
|
||||
private static DirectionType GetDirectionType(MovementDirection direction)
|
||||
{
|
||||
switch (direction) {
|
||||
case MovementDirection.Left: return DirectionType.Left;
|
||||
case MovementDirection.Right: return DirectionType.Right;
|
||||
case MovementDirection.Up: return DirectionType.Up;
|
||||
case MovementDirection.Down: return DirectionType.Down;
|
||||
default: return DirectionType.Unknow;
|
||||
}
|
||||
}
|
||||
}
|
8
MovementStrategy/MovementDirection.java
Normal file
8
MovementStrategy/MovementDirection.java
Normal file
@ -0,0 +1,8 @@
|
||||
package MovementStrategy;
|
||||
|
||||
public enum MovementDirection {
|
||||
Up,
|
||||
Down,
|
||||
Left,
|
||||
Right
|
||||
}
|
27
MovementStrategy/ObjectParameters.java
Normal file
27
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;
|
||||
RightBorder = _x + _width;
|
||||
DownBorder = _y + _height;
|
||||
ObjectMiddleHorizontal = _x + _width / 2;
|
||||
ObjectMiddleVertical = _y + _height / 2;
|
||||
}
|
||||
|
||||
}
|
7
MovementStrategy/StrategyStatus.java
Normal file
7
MovementStrategy/StrategyStatus.java
Normal file
@ -0,0 +1,7 @@
|
||||
package MovementStrategy;
|
||||
|
||||
public enum StrategyStatus {
|
||||
NotInit,
|
||||
InProgress,
|
||||
Finish
|
||||
}
|
Loading…
Reference in New Issue
Block a user