Compare commits
2 Commits
LabWorking
...
LabWork_4
| Author | SHA1 | Date | |
|---|---|---|---|
| 78a8bd4fa1 | |||
| e7a0a32fd9 |
@@ -0,0 +1,36 @@
|
||||
package Scripts.CollectionGenericObjects;
|
||||
|
||||
import Scripts.Drawing.DrawingMonorail;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public abstract class AbstractCompany {
|
||||
protected int _placeSizeWidth = 220;
|
||||
protected int _placeSizeHeight = 155;
|
||||
protected int _pictureWidth;
|
||||
protected int _pictureHeight;
|
||||
public ICollectionGenericObjects<DrawingMonorail> _collection = null;
|
||||
private int GetMaxCount() {
|
||||
return _pictureWidth * _pictureHeight / (_placeSizeWidth * _placeSizeHeight);
|
||||
|
||||
}
|
||||
public AbstractCompany(int picWidth, int picHeight, ICollectionGenericObjects<DrawingMonorail> collection)
|
||||
{
|
||||
_pictureWidth = picWidth;
|
||||
_pictureHeight = picHeight;
|
||||
_collection = collection;
|
||||
System.out.println(_pictureHeight+" "+_pictureWidth+" "+_placeSizeHeight+" "+_placeSizeWidth);
|
||||
_collection.SetMaxCount(GetMaxCount());
|
||||
}
|
||||
//Перегрузок нет
|
||||
public DrawingMonorail GetRandomObject()
|
||||
{
|
||||
return _collection.Get((int)(Math.random()*GetMaxCount() + 0));
|
||||
}
|
||||
public void SetPosition()
|
||||
{
|
||||
SetObjectsPosition();
|
||||
}
|
||||
public abstract void DrawBackgound(Graphics graphics);
|
||||
protected abstract void SetObjectsPosition();
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package Scripts.CollectionGenericObjects;
|
||||
|
||||
import Scripts.Drawing.DrawingModernMonorail;
|
||||
import Scripts.Drawing.DrawingMonorail;
|
||||
import Scripts.Entities.EntityModernMonorail;
|
||||
import Scripts.Entities.EntityMonorail;
|
||||
import Scripts.Wheels.IDrawingWheels;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.Random;
|
||||
|
||||
public class AdditionalCollection <T extends EntityMonorail, U extends IDrawingWheels>{
|
||||
public T[] CollectionEntity;
|
||||
public U[] CollectionWheels;
|
||||
public AdditionalCollection(int size, Class<T> type1, Class<T> type2) {
|
||||
CollectionEntity = (T[]) Array.newInstance(type1, size);
|
||||
CollectionWheels = (U[]) Array.newInstance(type2, size);
|
||||
CountEntities = size;
|
||||
CountWheels = size;
|
||||
}
|
||||
public int CountEntities;
|
||||
public int CountWheels;
|
||||
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 decks) {
|
||||
int index = 0;
|
||||
while (index < CountWheels) {
|
||||
if (CollectionWheels[index] == null)
|
||||
{
|
||||
CollectionWheels[index] = decks;
|
||||
return index;
|
||||
}
|
||||
++index;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
public DrawingMonorail CreateAdditionalCollectionMonorail() {
|
||||
Random random = new Random();
|
||||
if (CollectionEntity == null || CollectionWheels == null) return null;
|
||||
T entity = CollectionEntity[random.nextInt(CountEntities)];
|
||||
U wheels = CollectionWheels[random.nextInt(CountWheels)];
|
||||
DrawingMonorail drawingBaseStormtrooper = null;
|
||||
if (entity instanceof EntityModernMonorail) {
|
||||
drawingBaseStormtrooper = new DrawingModernMonorail((EntityModernMonorail)entity, wheels);
|
||||
}
|
||||
else {
|
||||
drawingBaseStormtrooper = new DrawingMonorail(entity, wheels);
|
||||
}
|
||||
return drawingBaseStormtrooper;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package Scripts.CollectionGenericObjects;
|
||||
|
||||
public enum CollectionType {
|
||||
None,
|
||||
Massive,
|
||||
List
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package Scripts.CollectionGenericObjects;
|
||||
|
||||
import Scripts.Drawing.DrawingMonorail;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class DepotSharingService extends AbstractCompany {
|
||||
public DepotSharingService (int picWidth, int picHeight, ICollectionGenericObjects<DrawingMonorail> collection) {
|
||||
super(picWidth, picHeight, collection);
|
||||
}
|
||||
|
||||
private int _offsetX = 30;
|
||||
|
||||
@Override
|
||||
public void DrawBackgound(Graphics graphics) {
|
||||
int width = _pictureWidth / _placeSizeWidth;
|
||||
int height = _pictureHeight / _placeSizeHeight;
|
||||
graphics.setColor(Color.BLACK);
|
||||
for (int i = 0; i < width; i++)
|
||||
{
|
||||
for (int j = 0; j < height; ++j)
|
||||
{
|
||||
graphics.drawLine(i * _offsetX + i * _placeSizeWidth, j * _placeSizeHeight, _placeSizeWidth + i * _offsetX + i * _placeSizeWidth, j * _placeSizeHeight);
|
||||
graphics.drawLine(i * _offsetX + i * _placeSizeWidth, j * _placeSizeHeight, i * _offsetX + i * _placeSizeWidth, _placeSizeHeight + j * _placeSizeHeight);
|
||||
graphics.drawLine(i * _offsetX + i * _placeSizeWidth, _placeSizeHeight + j * _placeSizeHeight, _placeSizeWidth + i * _offsetX + i * _placeSizeWidth, _placeSizeHeight + j * _placeSizeHeight);
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
protected void SetObjectsPosition() {
|
||||
int width = _pictureWidth / _placeSizeWidth;
|
||||
int height = _pictureHeight / _placeSizeHeight;
|
||||
|
||||
int boarderOffsetX = 20;
|
||||
int boarderOffsetY = 20;
|
||||
|
||||
int currnetIndex = 0;
|
||||
|
||||
for (int j = height - 1; j >= 0; j--) {
|
||||
for (int i = 0; i < width; i++, currnetIndex++) {
|
||||
if (_collection.Get(currnetIndex) == null) continue;
|
||||
|
||||
_collection.Get(currnetIndex).SetPictureSize(_pictureWidth, _pictureHeight);
|
||||
_collection.Get(currnetIndex).SetPosition(boarderOffsetX + i * _placeSizeWidth + i * _offsetX, boarderOffsetY + j * _placeSizeHeight);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package Scripts.CollectionGenericObjects;
|
||||
|
||||
public interface ICollectionGenericObjects<T>
|
||||
{
|
||||
int getCount();
|
||||
void SetMaxCount(int count);
|
||||
int Insert(T obj);
|
||||
T Remove(int position);
|
||||
T Get(int position);
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package Scripts.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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package Scripts.CollectionGenericObjects;
|
||||
|
||||
import Scripts.Drawing.DrawingMonorail;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
|
||||
public class MassiveGenericObjects<T> implements ICollectionGenericObjects<T>
|
||||
{
|
||||
private T[] _collection;
|
||||
private int Count;
|
||||
public void SetMaxCount(int size) {
|
||||
if (size > 0) {
|
||||
if (_collection == null) {
|
||||
_collection = (T[]) Array.newInstance((Class) DrawingMonorail.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];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package Scripts.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 SetCollectionObject(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;
|
||||
}
|
||||
|
||||
public T remove(String name, int position){
|
||||
if(_storages.containsKey(name))
|
||||
return _storages.get(name).Remove(position);
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package Scripts;
|
||||
package Scripts.Drawing;
|
||||
|
||||
public enum DirectionType {
|
||||
Up,
|
||||
@@ -1,4 +1,6 @@
|
||||
package Scripts;
|
||||
package Scripts.Drawing;
|
||||
|
||||
import Scripts.Forms.FormModernMonorail;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
@@ -12,6 +14,7 @@ public class DrawingField extends JPanel {
|
||||
}
|
||||
|
||||
public DrawingMonorail getDrawingMonorail() {return _drawingMonorail;}
|
||||
public void setDrawingMonorail(DrawingMonorail drawingMonorail) {_drawingMonorail = drawingMonorail;}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
@@ -50,14 +53,14 @@ public class DrawingField extends JPanel {
|
||||
Random rnd=new Random();
|
||||
_drawingMonorail = new DrawingMonorail(rnd.nextInt(50)+10,rnd.nextInt(100)+500,new Color(rnd.nextInt(256),rnd.nextInt(256),rnd.nextInt(256)), null, null);
|
||||
_drawingMonorail.SetPictureSize(getWidth(),getHeight());
|
||||
_drawingMonorail.SetPosition(rnd.nextInt(100)+10,rnd.nextInt(100)+10,getWidth(),getHeight());
|
||||
_drawingMonorail.SetPosition(rnd.nextInt(100)+10,rnd.nextInt(100)+10);
|
||||
}
|
||||
|
||||
public void CreateButtonAction_ModernMonorail(){
|
||||
Random rnd=new Random();
|
||||
_drawingMonorail = new DrawingModernMonorail(rnd.nextInt(50)+10,rnd.nextInt(100)+500,new Color(rnd.nextInt(256),rnd.nextInt(256),rnd.nextInt(256)), new Color(rnd.nextInt(256),rnd.nextInt(256),rnd.nextInt(256)), rnd.nextBoolean(), true);
|
||||
_drawingMonorail.SetPictureSize(getWidth(),getHeight());
|
||||
_drawingMonorail.SetPosition(rnd.nextInt(100)+10,rnd.nextInt(100)+10,getWidth(),getHeight());
|
||||
_drawingMonorail.SetPosition(rnd.nextInt(100)+10,rnd.nextInt(100)+10);
|
||||
}
|
||||
|
||||
public void ResizeField(){
|
||||
@@ -1,6 +1,9 @@
|
||||
package Scripts;
|
||||
package Scripts.Drawing;
|
||||
|
||||
import Scripts.Entities.EntityModernMonorail;
|
||||
import Scripts.Entities.EntityMonorail;
|
||||
import Scripts.Wheels.DrawingWheels;
|
||||
import Scripts.Wheels.IDrawingWheels;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.Random;
|
||||
@@ -17,6 +20,17 @@ public class DrawingModernMonorail extends DrawingMonorail {
|
||||
_wheelsSeed = rnd.nextInt(0, 2);
|
||||
}
|
||||
|
||||
public DrawingModernMonorail(EntityModernMonorail entityModernMonorail, IDrawingWheels wheels)
|
||||
{
|
||||
super((EntityMonorail)entityModernMonorail, 190, 80, wheels);
|
||||
|
||||
_entityMonorail = new EntityModernMonorail(entityModernMonorail.getSpeed(), entityModernMonorail.getWeight(), entityModernMonorail.getBodyColor(), entityModernMonorail.getAdditionalColor(), entityModernMonorail.getMonorailTrack(), entityModernMonorail.getMonorailTrack());
|
||||
_wheels = new DrawingWheels();
|
||||
Random rnd = new Random();
|
||||
_wheels.SetCountWheels(2 + rnd.nextInt(0, 3));
|
||||
_wheelsSeed = rnd.nextInt(0, 2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void DrawTransport(Graphics g)
|
||||
{
|
||||
@@ -1,13 +1,15 @@
|
||||
package Scripts;
|
||||
package Scripts.Drawing;
|
||||
|
||||
import Scripts.Entities.EntityMonorail;
|
||||
import Scripts.Wheels.DrawingWheels;
|
||||
import Scripts.Wheels.IDrawingWheels;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.Random;
|
||||
|
||||
public class DrawingMonorail {
|
||||
protected EntityMonorail _entityMonorail;
|
||||
protected DrawingWheels _wheels;
|
||||
protected IDrawingWheels _wheels;
|
||||
|
||||
private Integer _pictureWidth = null;
|
||||
private Integer _pictureHeight = null;
|
||||
@@ -19,7 +21,7 @@ public class DrawingMonorail {
|
||||
private int _drawningMonorailHeight = 80;
|
||||
|
||||
public EntityMonorail getMonorail() {return _entityMonorail;}
|
||||
public DrawingWheels getWheels() {return _wheels;}
|
||||
public IDrawingWheels getWheels() {return _wheels;}
|
||||
protected int _wheelsSeed;
|
||||
|
||||
public int GetPositionX() { return _startPositionX;}
|
||||
@@ -41,6 +43,45 @@ public class DrawingMonorail {
|
||||
_wheelsSeed = rnd.nextInt(0, 2);
|
||||
}
|
||||
|
||||
public DrawingMonorail(int speed, float weight, Color bodyColor)
|
||||
{
|
||||
this(100, 40);
|
||||
|
||||
_entityMonorail = new EntityMonorail(speed, weight, bodyColor);
|
||||
_wheels = new DrawingWheels();
|
||||
Random rnd = new Random();
|
||||
_wheels.SetCountWheels(2 + rnd.nextInt(0, 3));
|
||||
_wheelsSeed = rnd.nextInt(0, 2);
|
||||
}
|
||||
|
||||
public DrawingMonorail(EntityMonorail entityMonorail, Integer drawningMonorailWidth, Integer drawningMonorailHeight, IDrawingWheels wheels)
|
||||
{
|
||||
this(drawningMonorailWidth, drawningMonorailHeight);
|
||||
|
||||
_wheels = new DrawingWheels();
|
||||
_wheels.SetCountWheels(wheels.getCountWheels());
|
||||
|
||||
_entityMonorail = new EntityMonorail(entityMonorail.getSpeed(), entityMonorail.getWeight(), entityMonorail.getBodyColor());
|
||||
_wheels = new DrawingWheels();
|
||||
Random rnd = new Random();
|
||||
_wheels.SetCountWheels(2 + rnd.nextInt(0, 3));
|
||||
_wheelsSeed = rnd.nextInt(0, 2);
|
||||
}
|
||||
|
||||
public DrawingMonorail(EntityMonorail entityMonorail, IDrawingWheels wheels)
|
||||
{
|
||||
this(100, 40);
|
||||
|
||||
_wheels = new DrawingWheels();
|
||||
_wheels.SetCountWheels(wheels.getCountWheels());
|
||||
|
||||
_entityMonorail = new EntityMonorail(entityMonorail.getSpeed(), entityMonorail.getWeight(), entityMonorail.getBodyColor());
|
||||
_wheels = new DrawingWheels();
|
||||
Random rnd = new Random();
|
||||
_wheels.SetCountWheels(2 + rnd.nextInt(0, 3));
|
||||
_wheelsSeed = rnd.nextInt(0, 2);
|
||||
}
|
||||
|
||||
protected DrawingMonorail(Integer drawningMonorailWidth, Integer drawningMonorailHeight) {
|
||||
if(drawningMonorailWidth == null || drawningMonorailHeight == null) return;
|
||||
|
||||
@@ -69,7 +110,7 @@ public class DrawingMonorail {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void SetPosition(int x, int y, int width, int height)
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
if (_pictureHeight == null || _pictureWidth == null) return;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package Scripts;
|
||||
package Scripts.Entities;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.Random;
|
||||
@@ -1,4 +1,4 @@
|
||||
package Scripts;
|
||||
package Scripts.Entities;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.Random;
|
||||
@@ -0,0 +1,32 @@
|
||||
package Scripts.Forms;
|
||||
|
||||
import Scripts.CollectionGenericObjects.AbstractCompany;
|
||||
import Scripts.Drawing.DrawingMonorail;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class CanvasFormMonorailCollection<T> extends JComponent {
|
||||
public AbstractCompany company = null;
|
||||
public void SetCollectionToCanvas(AbstractCompany company) {
|
||||
this.company = company;
|
||||
}
|
||||
public CanvasFormMonorailCollection() {};
|
||||
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 DrawingMonorail) {
|
||||
((DrawingMonorail) obj).DrawTransport(g2d);
|
||||
}
|
||||
}
|
||||
super.repaint();
|
||||
}
|
||||
}
|
||||
20
ProjectMonorail/src/Scripts/Forms/CanvasMonorail.java
Normal file
20
ProjectMonorail/src/Scripts/Forms/CanvasMonorail.java
Normal file
@@ -0,0 +1,20 @@
|
||||
package Scripts.Forms;
|
||||
|
||||
import Scripts.Drawing.DrawingMonorail;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class CanvasMonorail extends JComponent {
|
||||
public DrawingMonorail _drawingMonorail;
|
||||
public CanvasMonorail(){}
|
||||
public void paintComponent(Graphics g) {
|
||||
if (_drawingMonorail == null) {
|
||||
return;
|
||||
}
|
||||
super.paintComponents(g);
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
_drawingMonorail.DrawTransport(g2d);
|
||||
super.repaint();
|
||||
}
|
||||
}
|
||||
133
ProjectMonorail/src/Scripts/Forms/FormAdditionalCollection.java
Normal file
133
ProjectMonorail/src/Scripts/Forms/FormAdditionalCollection.java
Normal file
@@ -0,0 +1,133 @@
|
||||
package Scripts.Forms;
|
||||
|
||||
import Scripts.CollectionGenericObjects.AbstractCompany;
|
||||
import Scripts.CollectionGenericObjects.AdditionalCollection;
|
||||
import Scripts.Drawing.DrawingModernMonorail;
|
||||
import Scripts.Drawing.DrawingMonorail;
|
||||
import Scripts.Entities.EntityModernMonorail;
|
||||
import Scripts.Entities.EntityMonorail;
|
||||
import Scripts.Wheels.DrawingWheels;
|
||||
|
||||
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 DrawingMonorail _drawingMonorail = null;
|
||||
private DrawingMonorail _copyMonorail = null;
|
||||
private AbstractCompany _company = null;
|
||||
private CanvasMonorail _canvasMonorail = new CanvasMonorail();
|
||||
private AdditionalCollection<EntityMonorail, DrawingWheels> _additionalCollection = null;
|
||||
private Random random = new Random();
|
||||
private JButton buttonGenerate = new JButton("Создать");
|
||||
private JButton buttonGoToCollection = new JButton("В коллекцию");
|
||||
private JList<String> listEntity = new JList<String>();
|
||||
private JList<String> listWheels = new JList<String>();
|
||||
public FormAdditionalCollection() {
|
||||
setTitle("Случайные монорельсы");
|
||||
setMinimumSize(new Dimension(970,310));
|
||||
_additionalCollection = new AdditionalCollection<EntityMonorail, DrawingWheels>(3,(Class)EntityMonorail.class,(Class)DrawingWheels.class);
|
||||
AddEntities();
|
||||
AddWheels();
|
||||
buttonGoToCollection.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if(_drawingMonorail !=null){
|
||||
_company._collection.Insert(_copyMonorail);
|
||||
FormMonorailCollection.canvasShow();
|
||||
dispose();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
buttonGenerate.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
_drawingMonorail = _additionalCollection.CreateAdditionalCollectionMonorail();
|
||||
_drawingMonorail.SetPictureSize(getWidth(), getHeight());
|
||||
_drawingMonorail.SetPosition(360,30);
|
||||
_canvasMonorail._drawingMonorail = _drawingMonorail;
|
||||
_canvasMonorail.repaint();
|
||||
if (_drawingMonorail instanceof DrawingModernMonorail)
|
||||
_copyMonorail = new DrawingModernMonorail((EntityModernMonorail) _drawingMonorail.getMonorail(), _drawingMonorail.getWheels());
|
||||
else
|
||||
_copyMonorail = new DrawingMonorail(_drawingMonorail.getMonorail(), _drawingMonorail.getWheels());
|
||||
}
|
||||
});
|
||||
|
||||
buttonGoToCollection.setBounds(830,200,120,60);
|
||||
buttonGenerate.setBounds(830, 130, 120, 60);
|
||||
listEntity.setBounds(10,200,400,60);
|
||||
listWheels.setBounds(420,200,400,60);
|
||||
add(buttonGenerate);
|
||||
add(buttonGoToCollection);
|
||||
add(listEntity);
|
||||
add(listWheels);
|
||||
add(_canvasMonorail);
|
||||
setVisible(true);
|
||||
}
|
||||
private String ToString(EntityMonorail entity) {
|
||||
String str = "";
|
||||
if (entity instanceof EntityModernMonorail) str += "EntityModernMonorail ";
|
||||
else str += "EntityMonorail ";
|
||||
str += entity.getBodyColor().toString();
|
||||
return str;
|
||||
}
|
||||
private String ToString(DrawingWheels wheels) {
|
||||
if (wheels == null || wheels.getCountWheels() == 0)
|
||||
return "Не имеет колес";
|
||||
String str = ""+wheels.getCountWheels();
|
||||
str+=" колес";
|
||||
|
||||
return str;
|
||||
}
|
||||
public void AddEntities() {
|
||||
for (int i = 0; i < _additionalCollection.CountEntities; i++) {
|
||||
random = new Random();
|
||||
int speed = random.nextInt(100, 300);
|
||||
float weight = random.nextInt(1000, 3000);
|
||||
Color bodycolor = new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256));
|
||||
EntityMonorail entityMonorail;
|
||||
if (random.nextBoolean()) {
|
||||
entityMonorail = new EntityMonorail(speed, weight, bodycolor);
|
||||
}
|
||||
else {
|
||||
Color additionalcolor = new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256));
|
||||
boolean monorailTrack = random.nextBoolean();
|
||||
boolean cabin = random.nextBoolean();
|
||||
entityMonorail = new EntityModernMonorail(speed, weight, bodycolor, additionalcolor, monorailTrack, cabin);
|
||||
}
|
||||
_additionalCollection.Insert(entityMonorail);
|
||||
}
|
||||
}
|
||||
public void AddWheels() {
|
||||
for (int i = 0; i < _additionalCollection.CountWheels; i++) {
|
||||
random = new Random();
|
||||
EntityMonorail entity = _additionalCollection.CollectionEntity[i];
|
||||
DrawingWheels drawingWheels = null;
|
||||
drawingWheels = new DrawingWheels();
|
||||
drawingWheels.SetCountWheels((int) ((Math.random() * 3) + 1) * 2);
|
||||
|
||||
if(drawingWheels!=null){
|
||||
_additionalCollection.Insert(drawingWheels);
|
||||
}
|
||||
}
|
||||
}
|
||||
void setCompany(AbstractCompany company) {
|
||||
this._company = company;
|
||||
String[] data1 = new String[_additionalCollection.CountEntities];
|
||||
for (int i = 0; i < _additionalCollection.CountEntities; i++) {
|
||||
EntityMonorail entity = _additionalCollection.CollectionEntity[i];
|
||||
data1[i] = ToString(entity);
|
||||
}
|
||||
String[] data2 = new String[_additionalCollection.CountWheels];
|
||||
for (int i = 0; i < _additionalCollection.CountWheels; i++) {
|
||||
DrawingWheels wheels = _additionalCollection.CollectionWheels[i];
|
||||
data2[i] = ToString(wheels);
|
||||
}
|
||||
listEntity.setListData(data1);
|
||||
listWheels.setListData(data2);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package Scripts;
|
||||
package Scripts.Forms;
|
||||
|
||||
import Scripts.Drawing.DrawingField;
|
||||
import Scripts.Drawing.DrawingMonorail;
|
||||
import Scripts.MovementStratagy.*;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -20,9 +22,6 @@ public class FormModernMonorail extends JFrame{
|
||||
|
||||
private DrawingField field = new DrawingField(this);
|
||||
|
||||
private JButton ButtonCreateMonorail = new JButton("Create Monorail");
|
||||
private JButton ButtonCreateModernMonorail = new JButton("Create Modern Monorail");
|
||||
|
||||
private Icon _iconUp = new ImageIcon("Resource\\Arrows\\ArrowUp.png");
|
||||
private Icon _iconDown = new ImageIcon("Resource\\Arrows\\ArrowDown.png");
|
||||
private Icon _iconRight = new ImageIcon("Resource\\Arrows\\ArrowRight.png");
|
||||
@@ -49,7 +48,6 @@ public class FormModernMonorail extends JFrame{
|
||||
Height=getHeight();
|
||||
ShowWindow();
|
||||
RefreshWindow();
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
@@ -103,18 +101,6 @@ public class FormModernMonorail extends JFrame{
|
||||
|
||||
CreatePanel.setLayout(new FlowLayout(FlowLayout.RIGHT,0,0));
|
||||
CreatePanel.setBackground(new Color(0,0,0,0));
|
||||
CreatePanel.add(ButtonCreateMonorail);
|
||||
CreatePanel.add(ButtonCreateModernMonorail);
|
||||
|
||||
ButtonCreateModernMonorail.addActionListener(e->{
|
||||
field.CreateButtonAction_ModernMonorail();
|
||||
repaint();
|
||||
});
|
||||
|
||||
ButtonCreateMonorail.addActionListener(e->{
|
||||
field.CreateButtonAction_Monorail();
|
||||
repaint();
|
||||
});
|
||||
|
||||
StrategyPanel.setLayout(new FlowLayout(FlowLayout.RIGHT,0,0));
|
||||
StrategyPanel.setBackground(new Color(0,0,0,0));
|
||||
@@ -181,4 +167,8 @@ public class FormModernMonorail extends JFrame{
|
||||
BottomAndCreatePanel.setBounds(-220,Height-110,Width,80);
|
||||
DimentionPanel.setBounds(Width-170,Height-170,190,140);
|
||||
}
|
||||
|
||||
public void Init(DrawingMonorail drawingMonorail) {
|
||||
field.setDrawingMonorail(drawingMonorail);
|
||||
}
|
||||
}
|
||||
321
ProjectMonorail/src/Scripts/Forms/FormMonorailCollection.java
Normal file
321
ProjectMonorail/src/Scripts/Forms/FormMonorailCollection.java
Normal file
@@ -0,0 +1,321 @@
|
||||
package Scripts.Forms;
|
||||
|
||||
import Scripts.CollectionGenericObjects.*;
|
||||
import Scripts.Drawing.DrawingModernMonorail;
|
||||
import Scripts.Drawing.DrawingMonorail;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.Queue;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.util.Random;
|
||||
|
||||
import static java.lang.Integer.parseInt;
|
||||
|
||||
public class FormMonorailCollection extends JFrame{
|
||||
private String title;
|
||||
private Dimension dimension;
|
||||
public static CanvasFormMonorailCollection<DrawingMonorail> _canvasMonorail = new CanvasFormMonorailCollection<DrawingMonorail>();
|
||||
private static AbstractCompany _company = null;
|
||||
|
||||
private Queue<DrawingMonorail> _collectionRemovedObjects = new LinkedList<DrawingMonorail>();
|
||||
private StorageCollection<DrawingMonorail> _storageCollection = new StorageCollection<DrawingMonorail>();
|
||||
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 createButton = new JButton("Создать современный монорельс");;
|
||||
private JButton createModernButton = new JButton("Создать монорельс");
|
||||
private JButton removeButton = new JButton("Удалить");
|
||||
private JButton removeObjectsButton = 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 TextField;
|
||||
public FormMonorailCollection(String title, Dimension dimension) {
|
||||
this.title = title;
|
||||
this.dimension = dimension;
|
||||
}
|
||||
public static void canvasShow() {
|
||||
_company.SetPosition();
|
||||
_canvasMonorail.SetCollectionToCanvas(_company);
|
||||
_canvasMonorail.repaint();
|
||||
}
|
||||
private void CreateObject(String typeOfClass){
|
||||
if (_company == null) return;
|
||||
int speed = (int)(Math.random() * 300 + 100);
|
||||
float weight = (float)(Math.random() * 3000 + 1000);
|
||||
Color bodyColor = getColor();
|
||||
DrawingMonorail drawingMonorail;
|
||||
switch (typeOfClass) {
|
||||
case "DrawingMonorail":
|
||||
drawingMonorail = new DrawingMonorail(speed, weight, bodyColor);
|
||||
break;
|
||||
case "DrawingModernMonorail":
|
||||
Color additionalColor = getColor();
|
||||
boolean monorailTrack = new Random().nextBoolean();
|
||||
boolean cabin = true;
|
||||
drawingMonorail = new DrawingModernMonorail(speed, weight, bodyColor, additionalColor, monorailTrack, cabin);
|
||||
break;
|
||||
default: return;
|
||||
}
|
||||
if (_company._collection.Insert(drawingMonorail) != -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);
|
||||
|
||||
TextField = new JFormattedTextField();
|
||||
|
||||
ComboBoxCollections.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
switch (ComboBoxCollections.getSelectedItem().toString()) {
|
||||
case "Хранилище":
|
||||
_company = new DepotSharingService(getWidth()-200, getHeight()-110, new MassiveGenericObjects<DrawingMonorail>());
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
createModernButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
CreateObject("DrawingMonorail");
|
||||
}
|
||||
});
|
||||
createButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
CreateObject("DrawingModernMonorail");
|
||||
}
|
||||
});
|
||||
|
||||
removeButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (_company == null || TextField.getText() == null) {
|
||||
return;
|
||||
}
|
||||
int pos = parseInt(TextField.getText());
|
||||
int resultConfirmDialog = JOptionPane.showConfirmDialog(null, "Удалить", "Удаление", JOptionPane.YES_NO_OPTION);
|
||||
if (resultConfirmDialog == JOptionPane.NO_OPTION) return;
|
||||
|
||||
DrawingMonorail obj = _storageCollection.remove(listBoxCollection.getSelectedValue().toString(), pos);
|
||||
System.out.println(obj);
|
||||
if (obj != null) {
|
||||
JOptionPane.showMessageDialog(null, "Объект удален");
|
||||
_collectionRemovedObjects.add(obj);
|
||||
canvasShow();
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(null, "Не удалось удалить объект");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
GoToCheckButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (_company == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
DrawingMonorail drawingMonorail = null;
|
||||
int counter = 100;
|
||||
while (drawingMonorail == null)
|
||||
{
|
||||
drawingMonorail = _company.GetRandomObject();
|
||||
counter--;
|
||||
if (counter <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (drawingMonorail == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
FormModernMonorail form = new FormModernMonorail();
|
||||
form.addWindowListener(new WindowAdapter() {
|
||||
@Override
|
||||
public void windowClosing(WindowEvent e) {
|
||||
canvasShow();
|
||||
super.windowClosing(e);
|
||||
}
|
||||
});
|
||||
form.Init(drawingMonorail);
|
||||
}
|
||||
});
|
||||
|
||||
RefreshButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (_company == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
canvasShow();
|
||||
}
|
||||
});
|
||||
RandomButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if(_company==null){
|
||||
return;
|
||||
}
|
||||
FormAdditionalCollection form = new FormAdditionalCollection();
|
||||
form.setCompany(_company);
|
||||
}
|
||||
});
|
||||
|
||||
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.SetCollectionObject(textBoxCollection.getText(), collectionType);
|
||||
RerfreshListBoxItems();
|
||||
}
|
||||
});
|
||||
|
||||
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());
|
||||
RerfreshListBoxItems();
|
||||
}
|
||||
});
|
||||
|
||||
buttonCreateCompany.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (listBoxCollection.getSelectedIndex() < 0 || listBoxCollection.getSelectedValue() == null) {
|
||||
JOptionPane.showMessageDialog(null, "Коллекция не выбрана");
|
||||
return;
|
||||
}
|
||||
ICollectionGenericObjects<DrawingMonorail> collection =
|
||||
_storageCollection.GetCollectionObject(listBoxCollection.getSelectedValue().toString());
|
||||
if (collection == null) {
|
||||
JOptionPane.showMessageDialog(null, "Коллекция не проинициализирована");
|
||||
return;
|
||||
}
|
||||
switch (ComboBoxCollections.getSelectedItem().toString()) {
|
||||
case "Хранилище":
|
||||
_company = new DepotSharingService(getWidth() - 200, getHeight() - 110,
|
||||
collection);
|
||||
break;
|
||||
}
|
||||
RerfreshListBoxItems();
|
||||
}
|
||||
});
|
||||
|
||||
removeObjectsButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (_collectionRemovedObjects.isEmpty()) {
|
||||
JOptionPane.showMessageDialog(null, "Коллекция пуста");
|
||||
return;
|
||||
}
|
||||
DrawingMonorail drawingMonorail = null;
|
||||
drawingMonorail = _collectionRemovedObjects.remove();
|
||||
if (drawingMonorail == null) {
|
||||
return;
|
||||
}
|
||||
FormModernMonorail form = new FormModernMonorail();
|
||||
form.Init(drawingMonorail);
|
||||
}
|
||||
});
|
||||
|
||||
ButtonGroup radioButtonsGroup = new ButtonGroup();
|
||||
JLabel labelCollectionName = new JLabel("Название коллекции");
|
||||
radioButtonsGroup.add(radioButtonMassive);
|
||||
radioButtonsGroup.add(radioButtonList);
|
||||
_canvasMonorail.setBounds(0, 0, getWidth() - 200, getHeight());
|
||||
labelCollectionName.setBounds(getWidth()-190, 10, 150, 20);
|
||||
textBoxCollection.setBounds(getWidth()-190,35,150,25);
|
||||
radioButtonMassive.setBounds(getWidth()-190, 60, 75, 20);
|
||||
radioButtonList.setBounds(getWidth()-105, 60, 75, 20);
|
||||
buttonAddCollection.setBounds(getWidth()-190, 85, 150, 20);
|
||||
listBoxCollection.setBounds(getWidth()-190, 115, 150, 70);
|
||||
buttonRemoveCollection.setBounds(getWidth()-190, 195, 150, 20);
|
||||
ComboBoxCollections.setBounds(getWidth() - 190, 225, 150, 20);
|
||||
buttonCreateCompany.setBounds(getWidth()-190, 255, 150, 20);
|
||||
createModernButton.setBounds(getWidth() - 190, 285, 150, 30);
|
||||
createButton.setBounds(getWidth() - 190, 325, 150, 30);
|
||||
RandomButton.setBounds(getWidth() - 190, 365, 150, 30);
|
||||
removeObjectsButton.setBounds(getWidth()-190, 505, 150, 30);
|
||||
TextField.setBounds(getWidth() - 190, 545, 150, 30);
|
||||
removeButton.setBounds(getWidth() - 190, 585, 150, 30);
|
||||
GoToCheckButton.setBounds(getWidth() - 190, 625, 150, 30);
|
||||
RefreshButton.setBounds(getWidth() - 190, 665, 150, 30);
|
||||
setSize(dimension.width, dimension.height);
|
||||
setLayout(null);
|
||||
|
||||
add(textBoxCollection);
|
||||
add(radioButtonMassive);
|
||||
add(radioButtonList);
|
||||
add(buttonAddCollection);
|
||||
add(listBoxCollection);
|
||||
add(buttonRemoveCollection);
|
||||
add(buttonCreateCompany);
|
||||
add(labelCollectionName);
|
||||
add(removeObjectsButton);
|
||||
|
||||
add(_canvasMonorail);
|
||||
add(ComboBoxCollections);
|
||||
add(createModernButton);
|
||||
add(createButton);
|
||||
add(TextField);
|
||||
add(GoToCheckButton);
|
||||
add(RandomButton);
|
||||
add(removeButton);
|
||||
add(RefreshButton);
|
||||
setVisible(true);
|
||||
}
|
||||
private void RerfreshListBoxItems() {
|
||||
DefaultListModel<String> list = new DefaultListModel<String>();
|
||||
for (String name : _storageCollection.Keys()) {
|
||||
if (name != "") {
|
||||
list.addElement(name);
|
||||
}
|
||||
}
|
||||
|
||||
listBoxCollection.setModel(list);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package Scripts.MovementStratagy;
|
||||
|
||||
import Scripts.DirectionType;
|
||||
import Scripts.Drawing.DirectionType;
|
||||
|
||||
public abstract class AbstractStrategy {
|
||||
private IMoveableObject moveableObject;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package Scripts.MovementStratagy;
|
||||
|
||||
import Scripts.DirectionType;
|
||||
import Scripts.Drawing.DirectionType;
|
||||
|
||||
public interface IMoveableObject{
|
||||
ObjectParameters GetObjectPosition();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package Scripts.MovementStratagy;
|
||||
|
||||
import Scripts.DirectionType;
|
||||
import Scripts.DrawingMonorail;
|
||||
import Scripts.Drawing.DirectionType;
|
||||
import Scripts.Drawing.DrawingMonorail;
|
||||
|
||||
public class MoveableMonorail implements IMoveableObject {
|
||||
private DrawingMonorail _drawingMonorail = null;
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
package Scripts;
|
||||
|
||||
import Scripts.Forms.FormMonorailCollection;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class Program {
|
||||
public static void main(String[] args){
|
||||
new FormModernMonorail();
|
||||
FormMonorailCollection form = new FormMonorailCollection("Монорельс", new Dimension(800, 800));
|
||||
form.Init();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,26 +5,31 @@ import Scripts.Wheels.CountWheels;
|
||||
import java.awt.*;
|
||||
import java.util.Random;
|
||||
|
||||
public class DrawingWheels {
|
||||
public class DrawingWheels implements IDrawingWheels{
|
||||
private CountWheels _wheels;
|
||||
private IOrnament _ornament;
|
||||
private int _seedOrnament;
|
||||
|
||||
public void SetCountWheels(int Count){
|
||||
for (CountWheels temp: CountWheels.values())
|
||||
if (temp.getCountWheels() == Count){
|
||||
Random rnd = new Random();
|
||||
_seedOrnament = rnd.nextInt(0, 3);
|
||||
_wheels=temp;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public int getCountWheels() {
|
||||
return _wheels.getCountWheels();
|
||||
if (_wheels != null) return _wheels.getCountWheels();
|
||||
else {
|
||||
SetCountWheels(2);
|
||||
return _wheels.getCountWheels();
|
||||
}
|
||||
}
|
||||
|
||||
public void DrawWheels(Graphics2D g,int startPosX[], int startPosY, Color color) {
|
||||
Random rnd = new Random();
|
||||
int ranOrnament = rnd.nextInt(0, 3);
|
||||
switch (ranOrnament) {
|
||||
switch (_seedOrnament) {
|
||||
case 0:
|
||||
_ornament = new DrawOrnament();
|
||||
break;
|
||||
|
||||
9
ProjectMonorail/src/Scripts/Wheels/IDrawingWheels.java
Normal file
9
ProjectMonorail/src/Scripts/Wheels/IDrawingWheels.java
Normal file
@@ -0,0 +1,9 @@
|
||||
package Scripts.Wheels;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public interface IDrawingWheels {
|
||||
public void SetCountWheels(int Count);
|
||||
public int getCountWheels();
|
||||
public void DrawWheels(Graphics2D g, int startPosX[], int startPosY, Color color);
|
||||
}
|
||||
Reference in New Issue
Block a user