Compare commits
No commits in common. "laba3" and "main" have entirely different histories.
@ -1,70 +0,0 @@
|
|||||||
public abstract class AbstractStrategy {
|
|
||||||
private IMoveableObject _moveableObject;
|
|
||||||
private Status _state = Status.NotInit;
|
|
||||||
protected int FieldWidth;
|
|
||||||
protected int FieldHeight;
|
|
||||||
public Status GetStatus() { return _state; }
|
|
||||||
public void SetData(IMoveableObject moveableObject, int width, int
|
|
||||||
height)
|
|
||||||
{
|
|
||||||
if (moveableObject == null)
|
|
||||||
{
|
|
||||||
_state = Status.NotInit;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_state = Status.InProgress;
|
|
||||||
_moveableObject = moveableObject;
|
|
||||||
FieldWidth = width;
|
|
||||||
FieldHeight = height;
|
|
||||||
}
|
|
||||||
public void MakeStep()
|
|
||||||
{
|
|
||||||
if (_state != Status.InProgress)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (IsTargetDestinaion())
|
|
||||||
{
|
|
||||||
_state = Status.Finish;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
MoveToTarget();
|
|
||||||
}
|
|
||||||
protected boolean MoveLeft() { return MoveTo(Direction.Left);};
|
|
||||||
protected boolean MoveRight(){return MoveTo(Direction.Right);}
|
|
||||||
protected boolean MoveUp(){return MoveTo(Direction.Up);}
|
|
||||||
protected boolean MoveDown(){return MoveTo(Direction.Down);}
|
|
||||||
protected ObjectParameters GetObjectParameters(){
|
|
||||||
if (_moveableObject != null) {
|
|
||||||
return _moveableObject.GetObjectPosition();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
protected int GetStep()
|
|
||||||
{
|
|
||||||
if (_state != Status.InProgress)
|
|
||||||
{
|
|
||||||
return Integer.parseInt(null);
|
|
||||||
}
|
|
||||||
return _moveableObject.GetStep();
|
|
||||||
}
|
|
||||||
protected abstract void MoveToTarget();
|
|
||||||
protected abstract boolean IsTargetDestinaion();
|
|
||||||
private boolean MoveTo(Direction directionType)
|
|
||||||
{
|
|
||||||
if (_state != Status.InProgress)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (_moveableObject.CheckCanMove(directionType))
|
|
||||||
{
|
|
||||||
_moveableObject.MoveObject(directionType);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,90 +0,0 @@
|
|||||||
import javax.swing.*;
|
|
||||||
import java.awt.*;
|
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
public class CruiserCollectionFrame extends JFrame {
|
|
||||||
private CruiserGenericCollection<DrawingCruiser, DrawingObjectCruiser> _cruiser;
|
|
||||||
|
|
||||||
public CruiserCollectionFrame() {
|
|
||||||
this.setSize(800, 600);
|
|
||||||
this.setTitle("Collection");
|
|
||||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
||||||
this.setResizable(false);
|
|
||||||
this.setLocationRelativeTo(null);
|
|
||||||
CollectionPanel panel = new CollectionPanel();
|
|
||||||
this.add(panel);
|
|
||||||
this.setVisible(true);
|
|
||||||
}
|
|
||||||
public class CollectionPanel extends JPanel {
|
|
||||||
static final int SCREEN_W = 800;
|
|
||||||
static final int SCREEN_H = 600;
|
|
||||||
CollectionPanel() {
|
|
||||||
this.setLayout(null);
|
|
||||||
this.setPreferredSize(new Dimension(SCREEN_W, SCREEN_H));
|
|
||||||
JTextField textFieldRemove = new JTextField();
|
|
||||||
textFieldRemove.setBounds(600, 200, 150, 30);
|
|
||||||
this.add(textFieldRemove);
|
|
||||||
JButton ButtonAddCruiser = new JButton("Добавить объект");
|
|
||||||
ButtonAddCruiser.setBounds(600, 150, 150, 30);
|
|
||||||
ButtonAddCruiser.addActionListener(new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
GameFrame form = new GameFrame();
|
|
||||||
if (form.getSelectedCruiser() != null) {
|
|
||||||
if (_cruiser.plus(_cruiser, form.SelectedCruiser) != -1) {
|
|
||||||
JOptionPane.showMessageDialog(null, "Объект добавлен");
|
|
||||||
|
|
||||||
} else {
|
|
||||||
JOptionPane.showMessageDialog(null, "Не удалось добавить объект");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
repaint();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
this.add(ButtonAddCruiser);
|
|
||||||
JButton ButtonRemoveCruiser = new JButton("Удалить объект");
|
|
||||||
ButtonRemoveCruiser.setBounds(600, 250, 150, 30);
|
|
||||||
ButtonRemoveCruiser.addActionListener(new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
if (_cruiser == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
String tmp = textFieldRemove.getText();
|
|
||||||
int num;
|
|
||||||
try {
|
|
||||||
num = Integer.parseInt(tmp);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
JOptionPane.showMessageDialog(null, "Введите число", "Информация", JOptionPane.INFORMATION_MESSAGE);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_cruiser.minus(_cruiser, num);
|
|
||||||
JOptionPane.showMessageDialog(null, "Объект удален", "Информация", JOptionPane.INFORMATION_MESSAGE);
|
|
||||||
repaint();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
this.add(ButtonRemoveCruiser);
|
|
||||||
JButton ButtonRefresh = new JButton("Обновить");
|
|
||||||
ButtonRefresh.setBounds(600, 300, 150, 30);
|
|
||||||
ButtonRefresh.addActionListener(new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
if (_cruiser == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
repaint();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
this.add(ButtonRefresh);
|
|
||||||
_cruiser = new CruiserGenericCollection<DrawingCruiser, DrawingObjectCruiser>(SCREEN_W, SCREEN_H);
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public void paintComponent(Graphics g) {
|
|
||||||
super.paintComponent(g);
|
|
||||||
draw(g);
|
|
||||||
}
|
|
||||||
public void draw(Graphics g) {
|
|
||||||
_cruiser.ShowCruiser(g);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,75 +0,0 @@
|
|||||||
import java.awt.*;
|
|
||||||
|
|
||||||
public class CruiserGenericCollection<T extends DrawingCruiser, U extends IMoveableObject> {
|
|
||||||
private int _pictureWidth;
|
|
||||||
private int _pictureHeight;
|
|
||||||
private int _placeSizeWidth = 210;
|
|
||||||
private int _placeSizeHeight = 90;
|
|
||||||
private SetGeneric<T> _collection;
|
|
||||||
public CruiserGenericCollection(int picWidth, int picHeight)
|
|
||||||
{
|
|
||||||
int width = picWidth / _placeSizeWidth;
|
|
||||||
int height = picHeight / _placeSizeHeight;
|
|
||||||
_pictureWidth = picWidth;
|
|
||||||
_pictureHeight = picHeight;
|
|
||||||
_collection = new SetGeneric<T>(width * height);
|
|
||||||
}
|
|
||||||
public int plus(CruiserGenericCollection<T, U> collect, T obj)
|
|
||||||
{
|
|
||||||
if (obj == null)
|
|
||||||
{
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return collect._collection.Insert(obj);
|
|
||||||
}
|
|
||||||
public boolean minus(CruiserGenericCollection<T, U> collect, int pos)
|
|
||||||
{
|
|
||||||
T obj = collect._collection.Get(pos);
|
|
||||||
if (obj != null)
|
|
||||||
{
|
|
||||||
collect._collection.Remove(pos);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
public U GetU(int pos)
|
|
||||||
{
|
|
||||||
T ans = _collection.Get(pos);
|
|
||||||
if(ans == null)
|
|
||||||
return null;
|
|
||||||
return (U)ans.GetMoveableObject();
|
|
||||||
}
|
|
||||||
public void ShowCruiser(Graphics gr)
|
|
||||||
{
|
|
||||||
DrawBackground(gr);
|
|
||||||
DrawObjects(gr);
|
|
||||||
}
|
|
||||||
private void DrawBackground(Graphics g)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
|
|
||||||
{
|
|
||||||
for (int j = 0; j < _pictureHeight / _placeSizeHeight +
|
|
||||||
1; ++j)
|
|
||||||
{
|
|
||||||
g.drawLine( i * _placeSizeWidth, j *
|
|
||||||
_placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j *
|
|
||||||
_placeSizeHeight);
|
|
||||||
}
|
|
||||||
g.drawLine(i * _placeSizeWidth, 0, i *
|
|
||||||
_placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private void DrawObjects(Graphics g)
|
|
||||||
{
|
|
||||||
DrawingCruiser cruiser;
|
|
||||||
int numPlacesInRow = _pictureWidth / _placeSizeWidth;
|
|
||||||
for (int i = 0; i < _collection.Count(); i++)
|
|
||||||
{
|
|
||||||
cruiser = _collection.Get(i);
|
|
||||||
if (cruiser != null)
|
|
||||||
{
|
|
||||||
cruiser.SetPosition((i % numPlacesInRow) * _placeSizeWidth + _placeSizeWidth / 20, _placeSizeHeight * (i / numPlacesInRow) + _placeSizeHeight / 10);
|
|
||||||
cruiser.DrawTransport(g);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,6 +0,0 @@
|
|||||||
public enum Direction {
|
|
||||||
Up,
|
|
||||||
Down,
|
|
||||||
Left,
|
|
||||||
Right
|
|
||||||
}
|
|
@ -1,34 +0,0 @@
|
|||||||
import java.awt.*;
|
|
||||||
public class DopClassMixed implements IDop{
|
|
||||||
public int numOfWheels;
|
|
||||||
public DopClassMixed(int num){
|
|
||||||
numOfWheels = num;
|
|
||||||
}
|
|
||||||
public void setNumOfWheels(String num){
|
|
||||||
switch (Integer.valueOf(num)){
|
|
||||||
case 2:
|
|
||||||
numOfWheels = NumberOfWheelsEnum.wheel_2.value;
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
numOfWheels = NumberOfWheelsEnum.wheel_3.value;
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
numOfWheels = NumberOfWheelsEnum.wheel_4.value;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
numOfWheels = NumberOfWheelsEnum.wheel_2.value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public void drawWheels(Graphics g, int _startPosX, int _startPosY, Color c) {
|
|
||||||
g.setColor(c);
|
|
||||||
|
|
||||||
if (numOfWheels >= 2) {
|
|
||||||
g.fillRect(_startPosX+55, _startPosY+20, 20, 15);
|
|
||||||
g.fillRect(_startPosX+55, _startPosY+40, 20, 15);
|
|
||||||
} if (numOfWheels >= 3) {
|
|
||||||
g.fillOval(_startPosX+30, _startPosY+20, 20, 15);
|
|
||||||
} if (numOfWheels >= 4) {
|
|
||||||
g.fillRect(_startPosX+85, _startPosY+20, 20, 15);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,33 +0,0 @@
|
|||||||
import java.awt.*;
|
|
||||||
public class DopClassRect implements IDop{
|
|
||||||
public int numOfWheels;
|
|
||||||
public DopClassRect(int num){
|
|
||||||
numOfWheels = num;
|
|
||||||
}
|
|
||||||
public void setNumOfWheels(String num){
|
|
||||||
switch (Integer.valueOf(num)){
|
|
||||||
case 2:
|
|
||||||
numOfWheels = NumberOfWheelsEnum.wheel_2.value;
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
numOfWheels = NumberOfWheelsEnum.wheel_3.value;
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
numOfWheels = NumberOfWheelsEnum.wheel_4.value;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
numOfWheels = NumberOfWheelsEnum.wheel_2.value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public void drawWheels(Graphics g, int _startPosX, int _startPosY, Color c) {
|
|
||||||
g.setColor(c);
|
|
||||||
if (numOfWheels >= 2) {
|
|
||||||
g.fillRect(_startPosX+55, _startPosY+15, 20, 15);
|
|
||||||
g.fillRect(_startPosX+55, _startPosY+30, 20, 15);
|
|
||||||
} if (numOfWheels >= 3) {
|
|
||||||
g.fillRect(_startPosX+30, _startPosY+15, 20, 15);
|
|
||||||
} if (numOfWheels >= 4) {
|
|
||||||
g.fillRect(_startPosX + 60, _startPosY + 35, 15, 15);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,50 +0,0 @@
|
|||||||
import java.awt.*;
|
|
||||||
public class DrawingAdvancedCruiser extends DrawingCruiser{
|
|
||||||
EntityAdvancedCruiser EntityCruiser;
|
|
||||||
public DrawingAdvancedCruiser(int speed, double weight, Color bodyColor, Color additionalColor, boolean helicopterPad, boolean coating, boolean ornamentWheels, int width, int height) {
|
|
||||||
super(speed, weight, bodyColor, width, height, 110, 60);
|
|
||||||
{
|
|
||||||
EntityCruiser = new EntityAdvancedCruiser(speed, weight, bodyColor, additionalColor, helicopterPad, coating);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public DrawingAdvancedCruiser(EntityAdvancedCruiser entityAdvancedCruiser,IDop wheels)
|
|
||||||
{
|
|
||||||
super(entityAdvancedCruiser, wheels);
|
|
||||||
{
|
|
||||||
EntityCruiser = entityAdvancedCruiser;
|
|
||||||
this.wheels = wheels;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public EntityAdvancedCruiser getEntityCruiser(){
|
|
||||||
return EntityCruiser;
|
|
||||||
}
|
|
||||||
public void DrawTransport(Graphics g)
|
|
||||||
{
|
|
||||||
if (!(EntityCruiser instanceof EntityAdvancedCruiser)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
super.DrawTransport(g);
|
|
||||||
EntityAdvancedCruiser advancedCruiser = (EntityAdvancedCruiser) EntityCruiser;
|
|
||||||
if (advancedCruiser == null )
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Color addBrush = advancedCruiser.AdditionalColor;
|
|
||||||
Color brush = advancedCruiser.BodyColor;
|
|
||||||
if (advancedCruiser.HelicopterPad)
|
|
||||||
{
|
|
||||||
g.setColor(addBrush);
|
|
||||||
g.drawRect(_startPosX + 35,
|
|
||||||
_startPosY + 23, 15, 15);
|
|
||||||
g.drawRect(_startPosX + 50,
|
|
||||||
_startPosY + 19, 30, 25);
|
|
||||||
}
|
|
||||||
if (advancedCruiser.Coating)
|
|
||||||
{
|
|
||||||
g.drawOval(_startPosX + 70,
|
|
||||||
_startPosY + 29, 20, 20);
|
|
||||||
}
|
|
||||||
if (wheels == null){return;}
|
|
||||||
wheels.drawWheels(g, _startPosX, _startPosY, brush);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,147 +0,0 @@
|
|||||||
import java.awt.*;
|
|
||||||
|
|
||||||
public class DrawingCruiser {
|
|
||||||
public EntityCruiser EntityCruiser;
|
|
||||||
private int _pictureWidth;
|
|
||||||
private int _pictureHeight;
|
|
||||||
protected int _startPosX;
|
|
||||||
protected int _startPosY;
|
|
||||||
private int _cruiserWidth = 110;
|
|
||||||
private int _cruiserHeight = 60;
|
|
||||||
|
|
||||||
public int GetPosX() {
|
|
||||||
return _startPosX;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int GetPosY() {
|
|
||||||
return _startPosY;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int GetWidth() {
|
|
||||||
return _cruiserWidth;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int GetHeight() {
|
|
||||||
return _cruiserHeight;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IDop wheels;
|
|
||||||
|
|
||||||
public DrawingCruiser(int speed, double weight, Color bodyColor, int width, int height) {
|
|
||||||
if (width < _cruiserWidth || height < _cruiserHeight) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_pictureWidth = width;
|
|
||||||
_pictureHeight = height;
|
|
||||||
EntityCruiser = new EntityCruiser(speed, weight, bodyColor);
|
|
||||||
}
|
|
||||||
|
|
||||||
public EntityCruiser getEntity() {
|
|
||||||
return EntityCruiser;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected DrawingCruiser(int speed, double weight, Color bodyColor, int
|
|
||||||
width, int height, int cruiserWidth, int cruiserHeight) {
|
|
||||||
if (width <= _cruiserWidth || height <= _cruiserHeight) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_pictureWidth = width;
|
|
||||||
_pictureHeight = height;
|
|
||||||
_cruiserWidth = cruiserWidth;
|
|
||||||
_cruiserHeight = cruiserHeight;
|
|
||||||
EntityCruiser = new EntityCruiser(speed, weight, bodyColor);
|
|
||||||
}
|
|
||||||
public DrawingCruiser(EntityCruiser entityCruiser, IDop wheels) {
|
|
||||||
EntityCruiser = entityCruiser;
|
|
||||||
this.wheels = wheels;
|
|
||||||
_pictureWidth = 1000;
|
|
||||||
_pictureHeight = 1000;
|
|
||||||
_cruiserWidth = 110;
|
|
||||||
_cruiserHeight = 60;
|
|
||||||
}
|
|
||||||
public void SetPosition(int x, int y) {
|
|
||||||
if (x < 0 || x + _cruiserWidth > _pictureWidth) {
|
|
||||||
x = Math.max(0, _pictureWidth - _cruiserWidth);
|
|
||||||
}
|
|
||||||
if (y < 0 || y + _cruiserHeight > _pictureHeight) {
|
|
||||||
y = Math.max(0, _pictureHeight - _cruiserHeight);
|
|
||||||
}
|
|
||||||
_startPosX = x;
|
|
||||||
_startPosY = y;
|
|
||||||
}
|
|
||||||
public void MoveTransport(Direction direction) {
|
|
||||||
if (!CanMove(direction) || EntityCruiser == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
switch (direction) {
|
|
||||||
case Left:
|
|
||||||
if (_startPosX - EntityCruiser.Step() >= 0) {
|
|
||||||
_startPosX -= (int) EntityCruiser.Step();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case Up:
|
|
||||||
if (_startPosY - EntityCruiser.Step() >= 0) {
|
|
||||||
_startPosY -= (int) EntityCruiser.Step();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case Right:
|
|
||||||
if (_startPosX + EntityCruiser.Step() + _cruiserWidth <= _pictureWidth) {
|
|
||||||
_startPosX += (int) EntityCruiser.Step();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case Down:
|
|
||||||
if (_startPosY + EntityCruiser.Step() + _cruiserHeight <= _pictureHeight) {
|
|
||||||
_startPosY += (int) EntityCruiser.Step();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public boolean CanMove(Direction direction) {
|
|
||||||
if (EntityCruiser == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
switch (direction) {
|
|
||||||
case Left:
|
|
||||||
return (_startPosX - EntityCruiser.Step()) > 0;
|
|
||||||
case Up:
|
|
||||||
return _startPosY - EntityCruiser.Step() > 0;
|
|
||||||
case Right:
|
|
||||||
return _startPosX + EntityCruiser.Step() + _cruiserWidth < _pictureWidth;
|
|
||||||
case Down:
|
|
||||||
return _startPosY + EntityCruiser.Step() + _cruiserHeight < _pictureHeight;
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public void DrawTransport(Graphics g) {
|
|
||||||
if (EntityCruiser == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
g.setColor(EntityCruiser.BodyColor);
|
|
||||||
g.drawRect(_startPosX + 9, _startPosY + 15, 10, 30);
|
|
||||||
g.drawRect(_startPosX + 90, _startPosY + 15, 10,
|
|
||||||
30);
|
|
||||||
g.drawRect(_startPosX + 20, _startPosY + 4, 70, 52);
|
|
||||||
|
|
||||||
g.fillRect(_startPosX + 10, _startPosY + 15, 10, 30);
|
|
||||||
g.fillRect(_startPosX + 90, _startPosY + 15, 10, 30);
|
|
||||||
g.fillRect(_startPosX + 20, _startPosY + 5, 70, 50);
|
|
||||||
g.fillRect(_startPosX + 10, _startPosY + 15, 10, 30);
|
|
||||||
g.fillRect(_startPosX + 90, _startPosY + 15, 10, 30);
|
|
||||||
g.fillRect(_startPosX + 20, _startPosY + 5, 70, 50);
|
|
||||||
|
|
||||||
Point[] points1 = new Point[3];
|
|
||||||
points1[0] = new Point(_startPosX + 100, _startPosY + 5);
|
|
||||||
points1[1] = new Point(_startPosX + 100, _startPosY + 55);
|
|
||||||
points1[2] = new Point(_startPosX + 150, _startPosY + 30);
|
|
||||||
g.fillPolygon(new int[]{points1[0].x, points1[1].x, points1[2].x},
|
|
||||||
new int[]{points1[0].y, points1[1].y, points1[2].y}, 3);
|
|
||||||
g.fillRect(_startPosX + 5, _startPosY + 15, 10, 10);
|
|
||||||
g.fillRect(_startPosX + 5, _startPosY + 35, 10, 10);
|
|
||||||
if (wheels == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
wheels.drawWheels(g, _startPosX, _startPosY, EntityCruiser.BodyColor);
|
|
||||||
}
|
|
||||||
public IMoveableObject GetMoveableObject(){return new DrawingObjectCruiser(this);}
|
|
||||||
}
|
|
@ -1,32 +0,0 @@
|
|||||||
public class DrawingObjectCruiser implements IMoveableObject{
|
|
||||||
private DrawingCruiser _drawningCruiser;
|
|
||||||
public DrawingObjectCruiser(DrawingCruiser drawningCruiser)
|
|
||||||
{
|
|
||||||
_drawningCruiser = drawningCruiser;
|
|
||||||
}
|
|
||||||
public ObjectParameters GetObjectPosition()
|
|
||||||
{
|
|
||||||
if (_drawningCruiser == null || _drawningCruiser.EntityCruiser ==
|
|
||||||
null)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return new ObjectParameters(_drawningCruiser.GetPosX(),
|
|
||||||
_drawningCruiser.GetPosY(), _drawningCruiser.GetWidth(), _drawningCruiser.GetHeight());
|
|
||||||
}
|
|
||||||
public int GetStep() {
|
|
||||||
if(_drawningCruiser.getEntity() == null)
|
|
||||||
return 0;
|
|
||||||
return (int)_drawningCruiser.getEntity().Step();
|
|
||||||
}
|
|
||||||
public boolean CheckCanMove(Direction direction){
|
|
||||||
if(_drawningCruiser == null)
|
|
||||||
return false;
|
|
||||||
return _drawningCruiser.CanMove(direction);
|
|
||||||
}
|
|
||||||
public void MoveObject(Direction direction){
|
|
||||||
if(_drawningCruiser == null)
|
|
||||||
return;
|
|
||||||
_drawningCruiser.MoveTransport(direction);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,14 +0,0 @@
|
|||||||
import java.awt.*;
|
|
||||||
public class EntityAdvancedCruiser extends EntityCruiser{
|
|
||||||
public Color AdditionalColor;
|
|
||||||
public boolean HelicopterPad ;
|
|
||||||
public boolean Coating ;
|
|
||||||
public EntityAdvancedCruiser(int speed, double weight, Color bodyColor, Color
|
|
||||||
additionalColor, boolean helicopterPad, boolean coating)
|
|
||||||
{
|
|
||||||
super(speed, weight, bodyColor);
|
|
||||||
AdditionalColor = additionalColor;
|
|
||||||
HelicopterPad = helicopterPad;
|
|
||||||
Coating = coating;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,14 +0,0 @@
|
|||||||
import java.awt.*;
|
|
||||||
public class EntityCruiser {
|
|
||||||
public int Speed;
|
|
||||||
public double Weight;
|
|
||||||
public Color BodyColor;
|
|
||||||
public double Step() {return (double)Speed * 100 / Weight;};
|
|
||||||
public boolean OrnamentWheels;
|
|
||||||
public EntityCruiser(int speed, double weight, Color bodyColor)
|
|
||||||
{
|
|
||||||
Speed = speed;
|
|
||||||
Weight = weight;
|
|
||||||
BodyColor = bodyColor;
|
|
||||||
}
|
|
||||||
}
|
|
229
GameFrame.java
229
GameFrame.java
@ -1,229 +0,0 @@
|
|||||||
import javax.swing.*;
|
|
||||||
import javax.swing.plaf.basic.BasicArrowButton;
|
|
||||||
import java.awt.*;
|
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
public class GameFrame extends JDialog {
|
|
||||||
protected DrawingCruiser SelectedCruiser;
|
|
||||||
|
|
||||||
GameFrame() {
|
|
||||||
this.setSize(710, 535);
|
|
||||||
this.setTitle("Cruiser");
|
|
||||||
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
|
||||||
this.setModalExclusionType(ModalExclusionType.APPLICATION_EXCLUDE);
|
|
||||||
this.setModalityType(ModalityType.APPLICATION_MODAL);
|
|
||||||
this.setResizable(false);
|
|
||||||
this.setLocationRelativeTo(null);
|
|
||||||
GamePanel panel = new GamePanel();
|
|
||||||
this.add(panel);
|
|
||||||
this.setVisible(true);
|
|
||||||
}
|
|
||||||
public DrawingCruiser getSelectedCruiser(){
|
|
||||||
return SelectedCruiser;
|
|
||||||
}
|
|
||||||
public class GamePanel extends JPanel {
|
|
||||||
static final int SCREEN_W = 700;
|
|
||||||
static final int SCREEN_H = 500;
|
|
||||||
int xx = 0;
|
|
||||||
int yy = 0;
|
|
||||||
private DrawingCruiser _drawningCruiser;
|
|
||||||
private AbstractStrategy _abstractStrategy;
|
|
||||||
JColorChooser dialogColor = new JColorChooser();
|
|
||||||
GamePanel() {
|
|
||||||
this.setLayout(null);
|
|
||||||
this.setPreferredSize(new Dimension(SCREEN_W, SCREEN_H));
|
|
||||||
GridBagConstraints layers = new GridBagConstraints();
|
|
||||||
JButton buttonCruiser = new JButton("Создать объект");
|
|
||||||
buttonCruiser.addActionListener(new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
Random random = new Random();
|
|
||||||
Color color = Color.BLACK;
|
|
||||||
Color choosenColor = JColorChooser.showDialog(getParent(), "Выберите цвет", Color.WHITE);
|
|
||||||
if(choosenColor != null){
|
|
||||||
color = choosenColor;
|
|
||||||
}
|
|
||||||
_drawningCruiser = new DrawingCruiser(random.nextInt(100, 300),
|
|
||||||
random.nextInt(1000, 3000),
|
|
||||||
color,
|
|
||||||
GamePanel.SCREEN_W, GamePanel.SCREEN_H);
|
|
||||||
_drawningCruiser.SetPosition(random.nextInt(10, 100), random.nextInt(10,
|
|
||||||
100));
|
|
||||||
int ornament = random.nextInt(1, 4);
|
|
||||||
switch (ornament){
|
|
||||||
case 1:
|
|
||||||
_drawningCruiser.wheels = new NumberOfWheels(random.nextInt(2, 5));
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
_drawningCruiser.wheels = new DopClassRect(random.nextInt(2, 5));
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
_drawningCruiser.wheels = new DopClassMixed(random.nextInt(2, 5));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
repaint();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
buttonCruiser.setBounds(20 + 150, 390, 120, 30);
|
|
||||||
this.add(buttonCruiser);
|
|
||||||
|
|
||||||
JButton buttonAdvancedCruiser = new JButton("Создать продвинутый объект");
|
|
||||||
buttonAdvancedCruiser.addActionListener(new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
Random random = new Random();
|
|
||||||
Color color = Color.BLACK; Color colorAdd = Color.WHITE;
|
|
||||||
Color choosenColor = JColorChooser.showDialog(getParent(), "Выберите цвет", Color.WHITE);
|
|
||||||
Color choosenAddColor = JColorChooser.showDialog(getParent(), "Выберите цвет", Color.WHITE);
|
|
||||||
if(choosenColor != null){
|
|
||||||
color = choosenColor;
|
|
||||||
}
|
|
||||||
if(choosenAddColor != null){
|
|
||||||
colorAdd = choosenAddColor;
|
|
||||||
}
|
|
||||||
_drawningCruiser = new DrawingAdvancedCruiser(random.nextInt(100, 300),
|
|
||||||
random.nextInt(1000, 3000),
|
|
||||||
color, colorAdd, random.nextBoolean(),random.nextBoolean(),random.nextBoolean(),
|
|
||||||
GamePanel.SCREEN_W, GamePanel.SCREEN_H);
|
|
||||||
_drawningCruiser.SetPosition(random.nextInt(10, 100), random.nextInt(10,
|
|
||||||
100));
|
|
||||||
int ornament = random.nextInt(1, 4);
|
|
||||||
switch (ornament){
|
|
||||||
case 1:
|
|
||||||
_drawningCruiser.wheels = new NumberOfWheels(random.nextInt(2, 5));
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
_drawningCruiser.wheels = new DopClassRect(random.nextInt(2, 5));
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
_drawningCruiser.wheels = new DopClassMixed(random.nextInt(2, 5));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
repaint();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
buttonAdvancedCruiser.setBounds( 20, 390, 120, 30);
|
|
||||||
this.add(buttonAdvancedCruiser);
|
|
||||||
JTextField textStrategy = new JTextField();
|
|
||||||
textStrategy.setBounds(550, 20, 120, 30);
|
|
||||||
this.add(textStrategy);
|
|
||||||
JButton buttonStep = new JButton("Шаг");
|
|
||||||
buttonStep.addActionListener(new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
if (_drawningCruiser == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (textStrategy.getText() != null)
|
|
||||||
{
|
|
||||||
switch(textStrategy.getText())
|
|
||||||
{
|
|
||||||
case "center":
|
|
||||||
|
|
||||||
_abstractStrategy = new MoveToCenter();
|
|
||||||
break;
|
|
||||||
case "border":
|
|
||||||
_abstractStrategy = new MoveToBorder();
|
|
||||||
break;
|
|
||||||
};
|
|
||||||
if (_abstractStrategy == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_abstractStrategy.SetData((IMoveableObject) _drawningCruiser, SCREEN_W, SCREEN_H);
|
|
||||||
}
|
|
||||||
if (_abstractStrategy == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
System.out.println("step");
|
|
||||||
_abstractStrategy.MakeStep();
|
|
||||||
repaint();
|
|
||||||
if (_abstractStrategy.GetStatus() == Status.Finish)
|
|
||||||
{
|
|
||||||
_abstractStrategy = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
buttonStep.setBounds(550, 60, 70, 30);
|
|
||||||
this.add(buttonStep);
|
|
||||||
JButton up = new BasicArrowButton(BasicArrowButton.NORTH);
|
|
||||||
up.addActionListener(new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
_drawningCruiser.MoveTransport(Direction.Up);
|
|
||||||
repaint();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
JButton left = new BasicArrowButton(BasicArrowButton.WEST);
|
|
||||||
left.addActionListener(new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
_drawningCruiser.MoveTransport(Direction.Left);
|
|
||||||
repaint();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
JButton down = new BasicArrowButton(BasicArrowButton.SOUTH);
|
|
||||||
down.addActionListener(new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
_drawningCruiser.MoveTransport(Direction.Down);
|
|
||||||
repaint();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
JButton right = new BasicArrowButton(BasicArrowButton.EAST);
|
|
||||||
right.addActionListener(new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
_drawningCruiser.MoveTransport(Direction.Right);
|
|
||||||
repaint();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
up.setBounds(570, 350, 30, 30);
|
|
||||||
this.add(up);
|
|
||||||
down.setBounds(570, 350 + 40, 30, 30);
|
|
||||||
this.add(down);
|
|
||||||
left.setBounds(570 - 40, 350 + 40, 30, 30);
|
|
||||||
this.add(left);
|
|
||||||
right.setBounds(570 + 40, 350 + 40, 30, 30);
|
|
||||||
this.add(right);
|
|
||||||
JButton buttonSelectedCruiser = new JButton("Выбрать объект");
|
|
||||||
buttonSelectedCruiser.addActionListener(new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
SelectedCruiser = _drawningCruiser;
|
|
||||||
dispose();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
buttonSelectedCruiser.setBounds(510, 100, 150, 30);
|
|
||||||
this.add(buttonSelectedCruiser);
|
|
||||||
}
|
|
||||||
private void Draw()
|
|
||||||
{
|
|
||||||
if (_drawningCruiser == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Graphics gr =new DebugGraphics();
|
|
||||||
_drawningCruiser.DrawTransport(gr);
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public void paintComponent(Graphics g) {
|
|
||||||
super.paintComponent(g);
|
|
||||||
draw(g);
|
|
||||||
}
|
|
||||||
public void draw(Graphics g) {
|
|
||||||
if (_drawningCruiser != null) {
|
|
||||||
_drawningCruiser.DrawTransport(g);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public Color ChooseColor(JFrame MonorailFrame){
|
|
||||||
JColorChooser dialog = new JColorChooser();
|
|
||||||
Color res = JColorChooser.showDialog(MonorailFrame, "Выберите цвет", Color.WHITE);
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,67 +0,0 @@
|
|||||||
import javax.swing.*;
|
|
||||||
import java.awt.*;
|
|
||||||
import java.util.Random;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
public class GenericCreate<T extends EntityCruiser, U extends IDop> {
|
|
||||||
ArrayList<T> _EntityCruiser;
|
|
||||||
ArrayList<U> _Wheels;
|
|
||||||
int pointerCruiser = 0;
|
|
||||||
int pointerWheels = 0;
|
|
||||||
public ArrayList<T> getEntities(){
|
|
||||||
return _EntityCruiser;
|
|
||||||
}
|
|
||||||
public ArrayList<U> getWheels(){
|
|
||||||
return _Wheels;
|
|
||||||
}
|
|
||||||
public GenericCreate(int countEntities,int countWheels){
|
|
||||||
_EntityCruiser=new ArrayList<>(countEntities);
|
|
||||||
_Wheels=new ArrayList<>(countWheels);
|
|
||||||
}
|
|
||||||
public int Add(T cruiser){
|
|
||||||
if(pointerCruiser <= _EntityCruiser.size()){
|
|
||||||
_EntityCruiser.add(cruiser);
|
|
||||||
pointerCruiser++;
|
|
||||||
return pointerCruiser;
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
public int Add(U wheels){
|
|
||||||
if(pointerWheels <= _Wheels.size()){
|
|
||||||
_Wheels.add(wheels);
|
|
||||||
pointerWheels++;
|
|
||||||
return pointerWheels;
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
public DrawingCruiser DrawingGeneratedCruiser()
|
|
||||||
{
|
|
||||||
Random rand=new Random();
|
|
||||||
if (_EntityCruiser.size() == 0 || _Wheels.size() == 0){
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
T entity = (_EntityCruiser.get(rand.nextInt(pointerCruiser)));
|
|
||||||
U wheel = (_Wheels.get(rand.nextInt(pointerWheels)));
|
|
||||||
if(entity instanceof EntityAdvancedCruiser){
|
|
||||||
return new DrawingAdvancedCruiser((EntityAdvancedCruiser) entity, wheel);
|
|
||||||
}
|
|
||||||
return new DrawingCruiser(entity, wheel);
|
|
||||||
}
|
|
||||||
public DrawingCruiser[] DrawEntitiesCruiser(Graphics g, int startX, int startY) {
|
|
||||||
DrawingCruiser[] drawingCruisers = new DrawingCruiser[_EntityCruiser.size()];
|
|
||||||
int height = 70;
|
|
||||||
DrawingCruiser cruiser;
|
|
||||||
DrawingAdvancedCruiser advancedcruiser;
|
|
||||||
for (int i = 0; i < _EntityCruiser.size(); i++) {
|
|
||||||
if (_EntityCruiser.get(i) instanceof EntityAdvancedCruiser) {
|
|
||||||
advancedcruiser = new DrawingAdvancedCruiser((EntityAdvancedCruiser) _EntityCruiser.get(i), null);
|
|
||||||
advancedcruiser.SetPosition(startX , startY + i * height);
|
|
||||||
advancedcruiser.DrawTransport(g);
|
|
||||||
} else {
|
|
||||||
cruiser = new DrawingCruiser(_EntityCruiser.get(i), null);
|
|
||||||
cruiser.SetPosition(startX , startY + i * height);
|
|
||||||
cruiser.DrawTransport(g);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return drawingCruisers;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,5 +0,0 @@
|
|||||||
import java.awt.*;
|
|
||||||
public interface IDop {
|
|
||||||
public void setNumOfWheels(String num);
|
|
||||||
public void drawWheels(Graphics g, int _startPosX, int _startPosY, Color c);
|
|
||||||
}
|
|
@ -1,6 +0,0 @@
|
|||||||
public interface IMoveableObject {
|
|
||||||
public ObjectParameters GetObjectPosition();
|
|
||||||
public int GetStep();
|
|
||||||
boolean CheckCanMove(Direction direction);
|
|
||||||
void MoveObject(Direction direction);
|
|
||||||
}
|
|
@ -1,5 +0,0 @@
|
|||||||
public class Main {
|
|
||||||
public static void main(String[] args) {
|
|
||||||
RandomFrame frame = new RandomFrame();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,28 +0,0 @@
|
|||||||
public class MoveToBorder extends AbstractStrategy {
|
|
||||||
protected boolean IsTargetDestinaion()
|
|
||||||
{
|
|
||||||
var objParams = GetObjectParameters();
|
|
||||||
if (objParams == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return objParams.RightBorder() <= FieldWidth &&
|
|
||||||
objParams.RightBorder() + GetStep() >= FieldWidth &&
|
|
||||||
objParams.DownBorder() <= FieldHeight &&
|
|
||||||
objParams.DownBorder() + GetStep() >= FieldHeight;
|
|
||||||
}
|
|
||||||
protected void MoveToTarget()
|
|
||||||
{
|
|
||||||
var objParams = GetObjectParameters();
|
|
||||||
if (objParams == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var diffX = FieldWidth - objParams.ObjectMiddleHorizontal();
|
|
||||||
if (Math.abs(diffX) > GetStep()) {
|
|
||||||
MoveRight();
|
|
||||||
}
|
|
||||||
var diffY = FieldHeight - objParams.ObjectMiddleVertical();
|
|
||||||
if (Math.abs(diffY) > GetStep()) {
|
|
||||||
MoveDown();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,38 +0,0 @@
|
|||||||
public class MoveToCenter extends AbstractStrategy {
|
|
||||||
protected boolean IsTargetDestinaion()
|
|
||||||
{
|
|
||||||
var objParams = GetObjectParameters();
|
|
||||||
if (objParams == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return (objParams.ObjectMiddleHorizontal() <= FieldWidth / 2 &&
|
|
||||||
objParams.ObjectMiddleHorizontal() + GetStep() >= FieldWidth / 2 &&
|
|
||||||
objParams.ObjectMiddleVertical() <= FieldHeight / 2 &&
|
|
||||||
objParams.ObjectMiddleVertical() + GetStep() >= FieldHeight / 2);
|
|
||||||
}
|
|
||||||
protected void MoveToTarget()
|
|
||||||
{
|
|
||||||
var objParams = GetObjectParameters();
|
|
||||||
if (objParams == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var diffX = objParams.ObjectMiddleHorizontal() - FieldWidth / 2;
|
|
||||||
if (Math.abs(diffX) > GetStep()) {
|
|
||||||
if (diffX > 0) {
|
|
||||||
MoveLeft();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
MoveRight();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var diffY = objParams.ObjectMiddleVertical() - FieldHeight / 2;
|
|
||||||
if (Math.abs(diffY) > GetStep()) {
|
|
||||||
if (diffY > 0) {
|
|
||||||
MoveUp();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
MoveDown();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,33 +0,0 @@
|
|||||||
import java.awt.*;
|
|
||||||
public class NumberOfWheels implements IDop{
|
|
||||||
public int numOfWheels;
|
|
||||||
public NumberOfWheels(int num){
|
|
||||||
numOfWheels = num;
|
|
||||||
}
|
|
||||||
public void setNumOfWheels(String num){
|
|
||||||
switch (Integer.valueOf(num)){
|
|
||||||
case 2:
|
|
||||||
numOfWheels = NumberOfWheelsEnum.wheel_2.value;
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
numOfWheels = NumberOfWheelsEnum.wheel_3.value;
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
numOfWheels = NumberOfWheelsEnum.wheel_4.value;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
numOfWheels = NumberOfWheelsEnum.wheel_2.value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public void drawWheels(Graphics g, int _startPosX, int _startPosY, Color c) {
|
|
||||||
g.setColor(c);
|
|
||||||
if (numOfWheels >= 2) {
|
|
||||||
g.fillOval(_startPosX+55, _startPosY+15, 20, 15);
|
|
||||||
g.fillOval(_startPosX+55, _startPosY+30, 20, 15);
|
|
||||||
} if (numOfWheels >= 3) {
|
|
||||||
g.fillOval(_startPosX+30, _startPosY+15, 20, 15);
|
|
||||||
} if(numOfWheels >= 4){
|
|
||||||
g.fillOval(_startPosX+85, _startPosY+15, 20, 15);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,9 +0,0 @@
|
|||||||
public enum NumberOfWheelsEnum {
|
|
||||||
wheel_2(2),
|
|
||||||
wheel_3(3),
|
|
||||||
wheel_4(4);
|
|
||||||
public int value;
|
|
||||||
NumberOfWheelsEnum(int value) {
|
|
||||||
this.value = value;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,19 +0,0 @@
|
|||||||
public class ObjectParameters {
|
|
||||||
private final int _x;
|
|
||||||
private final int _y;
|
|
||||||
private final int _width;
|
|
||||||
private final int _height;
|
|
||||||
public int LeftBorder(){return _x;}
|
|
||||||
public int TopBorder(){return _y;}
|
|
||||||
public int RightBorder(){return _x + _width;}
|
|
||||||
public int DownBorder(){return _y + _height;}
|
|
||||||
public int ObjectMiddleHorizontal(){return _x + _width / 2;}
|
|
||||||
public int ObjectMiddleVertical(){return _y + _height / 2;}
|
|
||||||
public ObjectParameters(int x, int y, int width, int height)
|
|
||||||
{
|
|
||||||
_x = x;
|
|
||||||
_y = y;
|
|
||||||
_width = width;
|
|
||||||
_height = height;
|
|
||||||
}
|
|
||||||
}
|
|
135
RandomFrame.java
135
RandomFrame.java
@ -1,135 +0,0 @@
|
|||||||
import javax.swing.*;
|
|
||||||
import java.awt.*;
|
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
public class RandomFrame extends JFrame {
|
|
||||||
RandomPanel panel = new RandomPanel();
|
|
||||||
RandomFrame() {
|
|
||||||
this.setSize(710, 535);
|
|
||||||
this.setTitle("CruiserRandom");
|
|
||||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
||||||
this.setResizable(false);
|
|
||||||
this.setLocationRelativeTo(null);
|
|
||||||
this.add(panel);
|
|
||||||
this.setVisible(true);
|
|
||||||
}
|
|
||||||
public class RandomPanel extends JPanel {
|
|
||||||
static final int SCREEN_W = 700;
|
|
||||||
static final int SCREEN_H = 500;
|
|
||||||
GenericCreate<EntityCruiser, IDop> _genericCreate = new GenericCreate<>(10, 10);
|
|
||||||
ComponentsPanel entitiesPanel = new ComponentsPanel();
|
|
||||||
ComponentsPanel wheelsPanel = new ComponentsPanel();
|
|
||||||
DrawingCruiser generatedCruiser;
|
|
||||||
RandomPanel() {
|
|
||||||
this.setLayout(null);
|
|
||||||
this.setPreferredSize(new Dimension(SCREEN_W, SCREEN_H));
|
|
||||||
JButton buttonCruiser = new JButton("Создать простой объект");
|
|
||||||
buttonCruiser.setBounds(20, 20, 130, 30);
|
|
||||||
buttonCruiser.addActionListener(new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
GameFrame dialogWindow = new GameFrame();
|
|
||||||
if (dialogWindow.getSelectedCruiser() != null){
|
|
||||||
if (dialogWindow.getSelectedCruiser() instanceof DrawingAdvancedCruiser) {
|
|
||||||
_genericCreate.Add(((DrawingAdvancedCruiser) dialogWindow.getSelectedCruiser()).getEntityCruiser());
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
_genericCreate.Add(dialogWindow.getSelectedCruiser().EntityCruiser);
|
|
||||||
}
|
|
||||||
repaint();}
|
|
||||||
|
|
||||||
else{
|
|
||||||
System.out.println("Selected cruiser is null!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
this.add(buttonCruiser);
|
|
||||||
JButton buttonIDop = new JButton("Создать палубы");
|
|
||||||
buttonIDop.addActionListener(new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
Random random = new Random();
|
|
||||||
IDop interWheels;
|
|
||||||
switch(random.nextInt(1, 4)){
|
|
||||||
case 1:
|
|
||||||
interWheels = new NumberOfWheels(random.nextInt(2, 5));
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
interWheels = new DopClassRect(random.nextInt(2, 5));
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
interWheels = new DopClassMixed(random.nextInt(2, 5));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
_genericCreate.Add(interWheels);
|
|
||||||
repaint();
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
buttonIDop.setBounds(20 + 130 + 20, 20, 130, 30);
|
|
||||||
this.add(buttonIDop);
|
|
||||||
JButton buttonCreateRandomCruiser = new JButton("Сгенерировать объект");
|
|
||||||
buttonCreateRandomCruiser.addActionListener(new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
generatedCruiser = _genericCreate.DrawingGeneratedCruiser();
|
|
||||||
if (generatedCruiser != null) {
|
|
||||||
generatedCruiser.SetPosition(430, 160);
|
|
||||||
}
|
|
||||||
repaint();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
buttonCreateRandomCruiser.setBounds(20 + 130 + 20 + 235, 20 + 80, 190, 30);
|
|
||||||
this.add(buttonCreateRandomCruiser);
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public void paintComponent(Graphics g) {
|
|
||||||
super.paintComponent(g);
|
|
||||||
draw(g);
|
|
||||||
}
|
|
||||||
public void draw(Graphics g) {
|
|
||||||
int startX = 20 ;
|
|
||||||
int startY = 70;
|
|
||||||
int startXForWheels = 170;
|
|
||||||
int startYForWheels = 30;
|
|
||||||
int height = 70;
|
|
||||||
int width = 110;
|
|
||||||
_genericCreate.DrawEntitiesCruiser(g, startX, startY);
|
|
||||||
for (int i=0; i < _genericCreate.getWheels().size(); i++) {
|
|
||||||
_genericCreate.getWheels().get(i).drawWheels(g, startXForWheels, startYForWheels + i * 30, Color.black);
|
|
||||||
}
|
|
||||||
if (generatedCruiser != null){
|
|
||||||
generatedCruiser.DrawTransport(g);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class ComponentsPanel extends JPanel {
|
|
||||||
static final int SCREEN_W = 130;
|
|
||||||
static final int SCREEN_H = 400;
|
|
||||||
|
|
||||||
ComponentsPanel() {
|
|
||||||
this.setSize(SCREEN_W, SCREEN_H);
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public void paintComponent(Graphics g) {
|
|
||||||
super.paintComponent(g);
|
|
||||||
}
|
|
||||||
public void draw(Graphics g) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public class CarRandomPanel extends JPanel {
|
|
||||||
static final int SCREEN_W = 200;
|
|
||||||
static final int SCREEN_H = 200;
|
|
||||||
@Override
|
|
||||||
public void paintComponent(Graphics g) {
|
|
||||||
super.paintComponent(g);
|
|
||||||
draw(g);
|
|
||||||
}
|
|
||||||
public void draw(Graphics g) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,52 +0,0 @@
|
|||||||
public class SetGeneric<T extends Object> {
|
|
||||||
private Object[] _places;
|
|
||||||
|
|
||||||
public int Count() {
|
|
||||||
return _places.length;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SetGeneric(int count)
|
|
||||||
{
|
|
||||||
_places = new Object[count];
|
|
||||||
}
|
|
||||||
|
|
||||||
public int Insert(T car)
|
|
||||||
{
|
|
||||||
return Insert(car,0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int Insert(T car, int position)
|
|
||||||
{
|
|
||||||
if (!(position >= 0 && position < Count()))
|
|
||||||
return -1;
|
|
||||||
if (_places[position] != null)
|
|
||||||
{
|
|
||||||
int indexEnd = position + 1;
|
|
||||||
while (_places[indexEnd] != null)
|
|
||||||
{
|
|
||||||
indexEnd++;
|
|
||||||
}
|
|
||||||
for (int i = indexEnd + 1; i > position; i--)
|
|
||||||
{
|
|
||||||
_places[i] = _places[i - 1];
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
_places[position] = car;
|
|
||||||
return position;
|
|
||||||
}
|
|
||||||
public boolean Remove(int position)
|
|
||||||
{
|
|
||||||
if (position < Count() && position >= 0)
|
|
||||||
{
|
|
||||||
_places[position] = null;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
public T Get(int position)
|
|
||||||
{
|
|
||||||
if (position < Count() && position >= 0) { return (T)_places[position]; }
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,5 +0,0 @@
|
|||||||
public enum Status {
|
|
||||||
NotInit,
|
|
||||||
InProgress,
|
|
||||||
Finish
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user