Done
This commit is contained in:
parent
2cf68f3de9
commit
beff4a4b13
@ -1,10 +1,12 @@
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.ListSelectionEvent;
|
||||
import javax.swing.event.ListSelectionListener;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.List;
|
||||
public class CruiserCollectionFrame extends JFrame {
|
||||
private CruiserGenericCollection<DrawingCruiser, DrawingObjectCruiser> _cruiser;
|
||||
|
||||
private CruiserGenericCollection<DrawingCruiser, DrawingObjectCruiser> _cruisers;
|
||||
public CruiserCollectionFrame() {
|
||||
this.setSize(800, 600);
|
||||
this.setTitle("Collection");
|
||||
@ -16,9 +18,15 @@ public class CruiserCollectionFrame extends JFrame {
|
||||
this.setVisible(true);
|
||||
}
|
||||
public class CollectionPanel extends JPanel {
|
||||
private CruiserGenericStorage _storage;
|
||||
TrashCollection<DrawingCruiser> _trash = new TrashCollection<>();
|
||||
private JList<String> listBoxStoragesJList;
|
||||
private DefaultListModel<String> listBoxStorages;
|
||||
static final int SCREEN_W = 800;
|
||||
static final int SCREEN_H = 600;
|
||||
CollectionPanel() {
|
||||
_storage = new CruiserGenericStorage(SCREEN_W,
|
||||
SCREEN_H);
|
||||
this.setLayout(null);
|
||||
this.setPreferredSize(new Dimension(SCREEN_W, SCREEN_H));
|
||||
JTextField textFieldRemove = new JTextField();
|
||||
@ -29,11 +37,14 @@ public class CruiserCollectionFrame extends JFrame {
|
||||
ButtonAddCruiser.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if(listBoxStoragesJList.getSelectedIndex() == -1) {
|
||||
return;
|
||||
}
|
||||
CruiserGenericCollection<DrawingCruiser, DrawingObjectCruiser> _cruisers = _storage.Get(listBoxStoragesJList.getSelectedValue());
|
||||
GameFrame form = new GameFrame();
|
||||
if (form.getSelectedCruiser() != null) {
|
||||
if (_cruiser.plus(_cruiser, form.SelectedCruiser) != -1) {
|
||||
if (form.getSelectedCar() != null) {
|
||||
if (_cruisers.plus(_cruisers, form.SelectedCar)) {
|
||||
JOptionPane.showMessageDialog(null, "Объект добавлен");
|
||||
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(null, "Не удалось добавить объект");
|
||||
}
|
||||
@ -42,12 +53,16 @@ public class CruiserCollectionFrame extends JFrame {
|
||||
}
|
||||
});
|
||||
this.add(ButtonAddCruiser);
|
||||
JButton ButtonRemoveCruiser = new JButton("Удалить объект");
|
||||
ButtonRemoveCruiser.setBounds(600, 250, 150, 30);
|
||||
ButtonRemoveCruiser.addActionListener(new ActionListener() {
|
||||
JButton ButtonRemoveCar = new JButton("Удалить объект");
|
||||
ButtonRemoveCar.setBounds(600, 250, 150, 30);
|
||||
ButtonRemoveCar.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (_cruiser == null) {
|
||||
if(listBoxStoragesJList.getSelectedIndex() == -1) {
|
||||
return;
|
||||
}
|
||||
CruiserGenericCollection<DrawingCruiser, DrawingObjectCruiser> _cruisers = _storage.Get(listBoxStoragesJList.getSelectedValue());
|
||||
if (_cruisers == null) {
|
||||
return;
|
||||
}
|
||||
String tmp = textFieldRemove.getText();
|
||||
@ -58,25 +73,99 @@ public class CruiserCollectionFrame extends JFrame {
|
||||
JOptionPane.showMessageDialog(null, "Введите число", "Информация", JOptionPane.INFORMATION_MESSAGE);
|
||||
return;
|
||||
}
|
||||
_cruiser.minus(_cruiser, num);
|
||||
DrawingCruiser deletedCruiser = _cruisers.Get(num);
|
||||
_trash.Add(deletedCruiser);
|
||||
_cruisers.minus(_cruisers, num);
|
||||
JOptionPane.showMessageDialog(null, "Объект удален", "Информация", JOptionPane.INFORMATION_MESSAGE);
|
||||
repaint();
|
||||
}
|
||||
});
|
||||
this.add(ButtonRemoveCruiser);
|
||||
this.add(ButtonRemoveCar);
|
||||
JButton ButtonRefresh = new JButton("Обновить");
|
||||
ButtonRefresh.setBounds(600, 300, 150, 30);
|
||||
ButtonRefresh.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (_cruiser == null) {
|
||||
if(listBoxStoragesJList.getSelectedIndex() == -1) {
|
||||
return;
|
||||
}
|
||||
_cruisers = _storage.Get(listBoxStoragesJList.getSelectedValue());
|
||||
repaint();
|
||||
}
|
||||
});
|
||||
this.add(ButtonRefresh);
|
||||
_cruiser = new CruiserGenericCollection<DrawingCruiser, DrawingObjectCruiser>(SCREEN_W, SCREEN_H);
|
||||
JButton ButtonDelStorage = new JButton("Удалить набор");
|
||||
ButtonDelStorage.setBounds(600, 450, 170, 30);
|
||||
ButtonDelStorage.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if(listBoxStoragesJList.getSelectedIndex() == -1) {
|
||||
return;
|
||||
}
|
||||
_storage.DelSet(listBoxStoragesJList.getSelectedValue());
|
||||
ReloadObjects();
|
||||
}
|
||||
});
|
||||
this.add(ButtonDelStorage);
|
||||
JButton ButtonTrash = new JButton("Удаленные объекты");
|
||||
ButtonTrash.setBounds(600, 500, 170, 30);
|
||||
ButtonTrash.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if(_trash.GetSize() == 0)
|
||||
return;
|
||||
GameFrame form = new GameFrame(_trash.GetLast());
|
||||
_trash.PopHead();
|
||||
}
|
||||
});
|
||||
this.add(ButtonTrash);
|
||||
JTextField textBoxStorageName = new JTextField();
|
||||
textBoxStorageName.setBounds(600, 10, 150, 30);
|
||||
this.add(textBoxStorageName);
|
||||
JButton ButtonAddObject = new JButton("Добавить набор");
|
||||
ButtonAddObject.setBounds(600, 40, 150, 30);
|
||||
ButtonAddObject.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (textBoxStorageName.getText().equals( "") || textBoxStorageName.getText().equals(null))
|
||||
{
|
||||
return;
|
||||
}
|
||||
_storage.AddSet(textBoxStorageName.getText());
|
||||
ReloadObjects();
|
||||
repaint();
|
||||
}});
|
||||
this.add(ButtonAddObject);
|
||||
listBoxStorages = new DefaultListModel<>();
|
||||
listBoxStoragesJList = new JList<>(listBoxStorages);
|
||||
listBoxStoragesJList.setBounds(600, 350, 150, 70);
|
||||
listBoxStoragesJList.addListSelectionListener(new ListSelectionListener() {
|
||||
@Override
|
||||
public void valueChanged(ListSelectionEvent evt) {
|
||||
if (!evt.getValueIsAdjusting()) {
|
||||
if(listBoxStoragesJList.getSelectedIndex() == -1) {
|
||||
return;
|
||||
}
|
||||
_cruisers = _storage.Get(listBoxStoragesJList.getSelectedValue());
|
||||
repaint();
|
||||
}
|
||||
}
|
||||
});
|
||||
this.add(listBoxStoragesJList);
|
||||
_cruisers = new CruiserGenericCollection<DrawingCruiser, DrawingObjectCruiser>(SCREEN_W, SCREEN_H);
|
||||
}
|
||||
private void ReloadObjects()
|
||||
{
|
||||
int index = listBoxStoragesJList.getSelectedIndex();
|
||||
listBoxStorages.clear();
|
||||
List<String> keys = _storage.Keys();
|
||||
for(int i = 0; i < keys.size(); i++){
|
||||
listBoxStorages.addElement(keys.get(i));
|
||||
}
|
||||
if(listBoxStorages.size() > 0 && (index == -1 || index >= listBoxStorages.size()))
|
||||
listBoxStoragesJList.setSelectedIndex(0);
|
||||
else if(listBoxStorages.size() > 0)
|
||||
listBoxStoragesJList.setSelectedIndex(index);
|
||||
}
|
||||
@Override
|
||||
public void paintComponent(Graphics g) {
|
||||
@ -84,7 +173,10 @@ public class CruiserCollectionFrame extends JFrame {
|
||||
draw(g);
|
||||
}
|
||||
public void draw(Graphics g) {
|
||||
_cruiser.ShowCruiser(g);
|
||||
if (listBoxStoragesJList.getSelectedIndex() != -1) {
|
||||
_storage.getByIndex(listBoxStorages.get(listBoxStoragesJList.getSelectedIndex())).ShowCars(g);
|
||||
_cruisers.ShowCars(g);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,4 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class CruiserGenericCollection<T extends DrawingCruiser, U extends IMoveableObject> {
|
||||
private int _pictureWidth;
|
||||
private int _pictureHeight;
|
||||
@ -14,11 +13,11 @@ public class CruiserGenericCollection<T extends DrawingCruiser, U extends IMovea
|
||||
_pictureHeight = picHeight;
|
||||
_collection = new SetGeneric<T>(width * height);
|
||||
}
|
||||
public int plus(CruiserGenericCollection<T, U> collect, T obj)
|
||||
public boolean plus(CruiserGenericCollection<T, U> collect, T obj)
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
return -1;
|
||||
return false;
|
||||
}
|
||||
return collect._collection.Insert(obj);
|
||||
}
|
||||
@ -38,18 +37,24 @@ public class CruiserGenericCollection<T extends DrawingCruiser, U extends IMovea
|
||||
return null;
|
||||
return (U)ans.GetMoveableObject();
|
||||
}
|
||||
public void ShowCruiser(Graphics gr)
|
||||
public T Get(int position){
|
||||
if(position < 0 || position >= _collection.Count())
|
||||
return null;
|
||||
return _collection.Get(position);
|
||||
}
|
||||
public void ShowCars(Graphics gr)
|
||||
{
|
||||
DrawBackground(gr);
|
||||
DrawObjects(gr);
|
||||
}
|
||||
private void DrawBackground(Graphics g)
|
||||
{
|
||||
g.setColor(Color.BLACK);
|
||||
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);
|
||||
@ -60,16 +65,22 @@ public class CruiserGenericCollection<T extends DrawingCruiser, U extends IMovea
|
||||
}
|
||||
private void DrawObjects(Graphics g)
|
||||
{
|
||||
DrawingCruiser cruiser;
|
||||
DrawingCruiser car;
|
||||
int numPlacesInRow = _pictureWidth / _placeSizeWidth;
|
||||
for (int i = 0; i < _collection.Count(); i++)
|
||||
{
|
||||
cruiser = _collection.Get(i);
|
||||
if (cruiser != null)
|
||||
// TODO получение объекта
|
||||
// TODO установка позиции
|
||||
// TODO прорисовка объекта
|
||||
car = _collection.Get(i);
|
||||
if (car != null)
|
||||
{
|
||||
cruiser.SetPosition((i % numPlacesInRow) * _placeSizeWidth + _placeSizeWidth / 20, _placeSizeHeight * (i / numPlacesInRow) + _placeSizeHeight / 10);
|
||||
cruiser.DrawTransport(g);
|
||||
car.SetPosition((i % numPlacesInRow) * _placeSizeWidth + _placeSizeWidth / 20, _placeSizeHeight * (i / numPlacesInRow) + _placeSizeHeight / 10);
|
||||
//car.SetPosition(_placeSizeWidth * (i/ numPlacesInColumn) + _placeSizeWidth / 20, (i % numPlacesInColumn ) *_placeSizeHeight + _placeSizeHeight / 10);
|
||||
car.DrawTransport(g);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
51
CruiserGenericStorage.java
Normal file
51
CruiserGenericStorage.java
Normal file
@ -0,0 +1,51 @@
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class CruiserGenericStorage {
|
||||
Map<String, CruiserGenericCollection<DrawingCruiser, DrawingObjectCruiser>> _carStorages;
|
||||
public List<String> Keys;
|
||||
|
||||
public List<String> Keys(){
|
||||
if(_carStorages == null)
|
||||
return null;
|
||||
return _carStorages.keySet().stream().collect(Collectors.toList());
|
||||
}
|
||||
private int _pictureWidth;
|
||||
private int _pictureHeight;
|
||||
public CruiserGenericStorage(int pictureWidth, int pictureHeight)
|
||||
{
|
||||
_carStorages = new HashMap<String,
|
||||
CruiserGenericCollection<DrawingCruiser, DrawingObjectCruiser>>();
|
||||
_pictureWidth = pictureWidth;
|
||||
_pictureHeight = pictureHeight;
|
||||
}
|
||||
public void AddSet(String name)
|
||||
{
|
||||
_carStorages.put(name, new CruiserGenericCollection<DrawingCruiser, DrawingObjectCruiser>(_pictureWidth, _pictureHeight));
|
||||
}
|
||||
public void DelSet(String name)
|
||||
{
|
||||
if (!_carStorages.containsKey(name))
|
||||
{
|
||||
return;
|
||||
}
|
||||
_carStorages.remove(name);
|
||||
}
|
||||
public CruiserGenericCollection<DrawingCruiser, DrawingObjectCruiser> getByIndex(String indexOfDict){
|
||||
if (_carStorages.containsKey(indexOfDict)){
|
||||
return _carStorages.get(indexOfDict);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public CruiserGenericCollection<DrawingCruiser, DrawingObjectCruiser> Get(String name){
|
||||
if(!_carStorages.containsKey(name))
|
||||
return null;
|
||||
return _carStorages.get(name);
|
||||
}
|
||||
public DrawingCruiser Get(String collectionName, int position){
|
||||
return _carStorages.get(collectionName).Get(position);
|
||||
}
|
||||
|
||||
}
|
146
GameFrame.java
146
GameFrame.java
@ -5,115 +5,153 @@ import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.Random;
|
||||
|
||||
|
||||
public class GameFrame extends JDialog {
|
||||
protected DrawingCruiser SelectedCruiser;
|
||||
protected DrawingCruiser SelectedCar;
|
||||
GamePanel panel;
|
||||
public DrawingCruiser _drawningCar;
|
||||
|
||||
GameFrame() {
|
||||
this.setSize(710, 535);
|
||||
this.setTitle("Cruiser");
|
||||
this.setTitle("DumpTruck");
|
||||
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();
|
||||
|
||||
panel = new GamePanel();
|
||||
this.add(panel);
|
||||
|
||||
this.setVisible(true);
|
||||
}
|
||||
public DrawingCruiser getSelectedCruiser(){
|
||||
return SelectedCruiser;
|
||||
GameFrame(DrawingCruiser newCar){
|
||||
_drawningCar = newCar;
|
||||
this.setSize(710, 535);
|
||||
this.setTitle("DumpTruck");
|
||||
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
this.setModalExclusionType(ModalExclusionType.APPLICATION_EXCLUDE);
|
||||
this.setModalityType(ModalityType.APPLICATION_MODAL);
|
||||
this.setResizable(false);
|
||||
this.setLocationRelativeTo(null);
|
||||
|
||||
panel = new GamePanel();
|
||||
this.add(panel);
|
||||
|
||||
this.setVisible(true);
|
||||
|
||||
}
|
||||
public DrawingCruiser getSelectedCar(){
|
||||
return SelectedCar;
|
||||
}
|
||||
public void ChangeCar(DrawingCruiser newCar){panel.ChangeCarOnPanel(newCar);}
|
||||
|
||||
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() {
|
||||
if (_drawningCar != null){repaint();}
|
||||
this.setLayout(null);
|
||||
this.setPreferredSize(new Dimension(SCREEN_W, SCREEN_H));
|
||||
GridBagConstraints layers = new GridBagConstraints();
|
||||
JButton buttonCruiser = new JButton("Создать объект");
|
||||
buttonCruiser.addActionListener(new ActionListener() {
|
||||
|
||||
JButton buttonCar = new JButton("Создать грузовик");
|
||||
buttonCar.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),
|
||||
|
||||
_drawningCar = 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,
|
||||
_drawningCar.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));
|
||||
_drawningCar.wheels = new NumberOfWheels(random.nextInt(2, 5));
|
||||
break;
|
||||
case 2:
|
||||
_drawningCruiser.wheels = new DopClassRect(random.nextInt(2, 5));
|
||||
_drawningCar.wheels = new DopClassRect(random.nextInt(2, 5));
|
||||
break;
|
||||
default:
|
||||
_drawningCruiser.wheels = new DopClassMixed(random.nextInt(2, 5));
|
||||
_drawningCar.wheels = new DopClassMixed(random.nextInt(2, 5));
|
||||
break;
|
||||
}
|
||||
repaint();
|
||||
}
|
||||
});
|
||||
buttonCruiser.setBounds(20 + 150, 390, 120, 30);
|
||||
this.add(buttonCruiser);
|
||||
buttonCar.setBounds(20 + 150, 390, 120, 30);
|
||||
this.add(buttonCar);
|
||||
|
||||
JButton buttonAdvancedCruiser = new JButton("Создать продвинутый объект");
|
||||
buttonAdvancedCruiser.addActionListener(new ActionListener() {
|
||||
JButton buttonDumpCar = new JButton("Создать самосвал");
|
||||
buttonDumpCar.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),
|
||||
|
||||
_drawningCar = 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,
|
||||
GamePanel.SCREEN_W, GamePanel.SCREEN_H); //TODO
|
||||
_drawningCar.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));
|
||||
_drawningCar.wheels = new NumberOfWheels(random.nextInt(2, 5));
|
||||
break;
|
||||
case 2:
|
||||
_drawningCruiser.wheels = new DopClassRect(random.nextInt(2, 5));
|
||||
_drawningCar.wheels = new DopClassRect(random.nextInt(2, 5));
|
||||
break;
|
||||
default:
|
||||
_drawningCruiser.wheels = new DopClassMixed(random.nextInt(2, 5));
|
||||
_drawningCar.wheels = new DopClassMixed(random.nextInt(2, 5));
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
repaint();
|
||||
}
|
||||
});
|
||||
buttonAdvancedCruiser.setBounds( 20, 390, 120, 30);
|
||||
this.add(buttonAdvancedCruiser);
|
||||
buttonDumpCar.setBounds( 20, 390, 120, 30);
|
||||
this.add(buttonDumpCar);
|
||||
|
||||
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)
|
||||
if (_drawningCar == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -129,14 +167,18 @@ public class GameFrame extends JDialog {
|
||||
_abstractStrategy = new MoveToBorder();
|
||||
break;
|
||||
};
|
||||
|
||||
if (_abstractStrategy == null)
|
||||
{
|
||||
|
||||
return;
|
||||
}
|
||||
_abstractStrategy.SetData((IMoveableObject) _drawningCruiser, SCREEN_W, SCREEN_H);
|
||||
_abstractStrategy.SetData((IMoveableObject) _drawningCar, SCREEN_W, SCREEN_H);
|
||||
//textStrategy.setText();
|
||||
}
|
||||
if (_abstractStrategy == null)
|
||||
{
|
||||
|
||||
return;
|
||||
}
|
||||
System.out.println("step");
|
||||
@ -144,17 +186,19 @@ public class GameFrame extends JDialog {
|
||||
repaint();
|
||||
if (_abstractStrategy.GetStatus() == Status.Finish)
|
||||
{
|
||||
//comboBoxStrategy.Enabled = true;
|
||||
_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);
|
||||
_drawningCar.MoveTransport(Direction.Up);
|
||||
repaint();
|
||||
}
|
||||
});
|
||||
@ -162,7 +206,7 @@ public class GameFrame extends JDialog {
|
||||
left.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
_drawningCruiser.MoveTransport(Direction.Left);
|
||||
_drawningCar.MoveTransport(Direction.Left);
|
||||
repaint();
|
||||
}
|
||||
});
|
||||
@ -170,7 +214,7 @@ public class GameFrame extends JDialog {
|
||||
down.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
_drawningCruiser.MoveTransport(Direction.Down);
|
||||
_drawningCar.MoveTransport(Direction.Down);
|
||||
repaint();
|
||||
}
|
||||
});
|
||||
@ -178,52 +222,74 @@ public class GameFrame extends JDialog {
|
||||
right.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
_drawningCruiser.MoveTransport(Direction.Right);
|
||||
_drawningCar.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() {
|
||||
|
||||
JButton buttonSelectedCar = new JButton("Выбрать машину");
|
||||
|
||||
buttonSelectedCar.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
SelectedCruiser = _drawningCruiser;
|
||||
SelectedCar = _drawningCar;
|
||||
dispose();
|
||||
|
||||
}
|
||||
});
|
||||
buttonSelectedCruiser.setBounds(510, 100, 150, 30);
|
||||
this.add(buttonSelectedCruiser);
|
||||
buttonSelectedCar.setBounds(510, 100, 150, 30);
|
||||
this.add(buttonSelectedCar);
|
||||
}
|
||||
private void Draw()
|
||||
{
|
||||
if (_drawningCruiser == null)
|
||||
if (_drawningCar == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Graphics gr =new DebugGraphics();
|
||||
_drawningCruiser.DrawTransport(gr);
|
||||
_drawningCar.DrawTransport(gr);
|
||||
|
||||
}
|
||||
@Override
|
||||
public void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
draw(g);
|
||||
}
|
||||
|
||||
public void draw(Graphics g) {
|
||||
if (_drawningCruiser != null) {
|
||||
_drawningCruiser.DrawTransport(g);
|
||||
if (_drawningCar != null) {
|
||||
_drawningCar.DrawTransport(g);
|
||||
}
|
||||
}
|
||||
|
||||
public void ChangeCarOnPanel(DrawingCruiser newCar){
|
||||
newCar.SetPosition(0,0);
|
||||
_drawningCar = newCar;
|
||||
repaint();
|
||||
|
||||
}
|
||||
}
|
||||
public Color ChooseColor(JFrame MonorailFrame){
|
||||
JColorChooser dialog = new JColorChooser();
|
||||
Color res = JColorChooser.showDialog(MonorailFrame, "Выберите цвет", Color.WHITE);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
RandomFrame frame = new RandomFrame();
|
||||
CruiserCollectionFrame frame = new CruiserCollectionFrame();
|
||||
}
|
||||
}
|
@ -31,12 +31,12 @@ public class RandomFrame extends JFrame {
|
||||
@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());
|
||||
if (dialogWindow.getSelectedCar() != null){
|
||||
if (dialogWindow.getSelectedCar() instanceof DrawingAdvancedCruiser) {
|
||||
_genericCreate.Add(((DrawingAdvancedCruiser) dialogWindow.getSelectedCar()).getEntityCruiser());
|
||||
}
|
||||
else {
|
||||
_genericCreate.Add(dialogWindow.getSelectedCruiser().EntityCruiser);
|
||||
_genericCreate.Add(dialogWindow.getSelectedCar().EntityCruiser);
|
||||
}
|
||||
repaint();}
|
||||
|
||||
|
@ -1,52 +1,50 @@
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SetGeneric<T extends Object> {
|
||||
private Object[] _places;
|
||||
private final List<T> _places;
|
||||
private final int _maxCount;
|
||||
public int Count;
|
||||
|
||||
public int Count() {
|
||||
return _places.length;
|
||||
return Count;
|
||||
}
|
||||
|
||||
public SetGeneric(int count)
|
||||
{
|
||||
_places = new Object[count];
|
||||
_places = new ArrayList<>();
|
||||
_maxCount = count;
|
||||
}
|
||||
|
||||
public int Insert(T car)
|
||||
{
|
||||
return Insert(car,0);
|
||||
public boolean Insert(T car){
|
||||
if(_places.size() == _maxCount)
|
||||
return false;
|
||||
Insert(car, 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
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 Insert(T monorail, int position){
|
||||
if (!(position >= 0 && position <= _places.size() && _places.size() < _maxCount))
|
||||
return false;
|
||||
_places.add(position, monorail);
|
||||
Count++;
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean Remove(int position)
|
||||
{
|
||||
if (position < Count() && position >= 0)
|
||||
if(!(position >= 0 && position < _places.size()))
|
||||
{
|
||||
_places[position] = null;
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
_places.remove(position);
|
||||
Count--;
|
||||
return true;
|
||||
}
|
||||
|
||||
public T Get(int position)
|
||||
{
|
||||
if (position < Count() && position >= 0) { return (T)_places[position]; }
|
||||
if (position < Count() && position >= 0) { return (T)_places.get(position); }
|
||||
return null;
|
||||
}
|
||||
}
|
23
TrashCollection.java
Normal file
23
TrashCollection.java
Normal file
@ -0,0 +1,23 @@
|
||||
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
public class TrashCollection <T extends DrawingCruiser>{
|
||||
LinkedList<T> linkedList;
|
||||
|
||||
public TrashCollection(){
|
||||
linkedList = new LinkedList<>();
|
||||
}
|
||||
public void Add(T car){
|
||||
linkedList.add(car);
|
||||
}
|
||||
public void PopHead(){
|
||||
if(linkedList.size() ==0)
|
||||
return;
|
||||
linkedList.remove();
|
||||
}
|
||||
public T GetLast(){
|
||||
return linkedList.getFirst();
|
||||
}
|
||||
public int GetSize(){return linkedList.size();}
|
||||
}
|
Loading…
Reference in New Issue
Block a user