PIBD-13_Fomichev_V.S._LabWork02_Hard #2

Closed
slavaxom9k wants to merge 6 commits from labwork02 into labwork01
2 changed files with 27 additions and 50 deletions
Showing only changes of commit 13023d2b3c - Show all commits

View File

@ -37,23 +37,39 @@ public class DrawningRollersCircle implements IDifferentRollers {
}
//нижние катки ЦВЕТ
g.setColor(Color.GRAY);
g.fillOval(_startPosX + 40, _startPosY + 90, 15, 15);
g.fillOval(_startPosX + 55, _startPosY + 90, 15, 15);
for (int i = 0; i < 10; ++i) {
drawRollers(g, _startPosX + 19 + i * 8, _startPosY + 21);
}
if (_rollers != CountRollers.FourRollers) {
g.fillOval(_startPosX + 70, _startPosY + 90, 15, 15);
for (int i = 0; i < 5; ++i) {
drawRollers(g, _startPosX - 15 + i * 5, _startPosY + 28);
drawRollers(g, _startPosX + 115 + i * 5, _startPosY + 28);
}
}
if (_rollers == CountRollers.SixRollers) {
g.fillOval(_startPosX + 85, _startPosY + 90, 15, 15);
for (int i = 0; i < 10; ++i) {
drawRollers(g, _startPosX + 19 + i * 8, _startPosY + 37);
}
}
//нижние катки ОТРИСОВКА
g.setColor(Color.BLACK);
g.drawOval(_startPosX + 40, _startPosY + 90, 15, 15);
g.drawOval( _startPosX + 55, _startPosY + 90, 15, 15);
for (int i = 0; i < 10; ++i) {
drawRollers(g, _startPosX + 19 + i * 8, _startPosY + 21);
}
if (_rollers != CountRollers.FourRollers) {
g.drawOval( _startPosX+ 70, _startPosY + 90, 15, 15);
for (int i = 0; i < 5; ++i) {
drawRollers(g, _startPosX - 15 + i * 5, _startPosY + 28);
drawRollers(g, _startPosX + 115 + i * 5, _startPosY + 28);
}
}
if (_rollers == CountRollers.SixRollers) {
g.drawOval(_startPosX + 85, _startPosY + 90, 15, 15);
for (int i = 0; i < 10; ++i) {
drawRollers(g, _startPosX + 19 + i * 8, _startPosY + 37);
}
}
}
}

View File

@ -15,11 +15,6 @@ public class FormAntiAircraftGun extends JFrame {
private DrawningArmoredCar _drawningArmoredCar;
private AbstractStrategy _abstractStrategy;
private Canvas canvas;
// выбор кол-ва катков
JLabel labelCount;
private JTextField fieldCount;
// выбор стратегии
JLabel labelStrategy;
JComboBox comboBoxStrategy;
@ -39,9 +34,6 @@ public class FormAntiAircraftGun extends JFrame {
private void InitializeComponent() {
canvas = new Canvas();
labelCount = new JLabel("Введите число катков:");
fieldCount = new JTextField();
labelStrategy = new JLabel("Шаг стратегии:");
comboBoxStrategy = new JComboBox(new String[]{"К центру", "К краю"});
buttonStrategy = new JButton("Выбрать стратегию");
@ -69,16 +61,13 @@ public class FormAntiAircraftGun extends JFrame {
buttonDown.setName("down");
buttonDown.setIcon(new ImageIcon("src/images/down.jpg"));
setSize(800, 500);
setSize(800, 600);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(null);
buttonCreateAntiAircraftGun.setBounds(12, 355, 146, 33);
buttonCreateArmoredCar.setBounds(182, 355, 146, 33);
labelCount.setBounds(42, 405, 240, 20);
fieldCount.setBounds(240, 407, 48, 20);
labelStrategy.setBounds(630, 20, 146, 33);
comboBoxStrategy.setBounds(630, 50, 146, 20);
buttonStrategy.setBounds(630, 80, 146, 33);
@ -87,14 +76,10 @@ public class FormAntiAircraftGun extends JFrame {
buttonRight.setBounds(728, 358, 48, 44);
buttonLeft.setBounds(630, 358, 48, 44);
buttonDown.setBounds(679, 358, 48, 44);
labelCount.setBounds(12, 405, 240, 20);
fieldCount.setBounds(210, 407, 48, 20);
canvas.setBounds(0, 0, 790, 460);
add(buttonCreateAntiAircraftGun);
add(buttonCreateArmoredCar);
add(labelCount);
add(fieldCount);
add(labelStrategy);
add(comboBoxStrategy);
add(buttonStrategy);
@ -102,8 +87,6 @@ public class FormAntiAircraftGun extends JFrame {
add(buttonRight);
add(buttonDown);
add(buttonLeft);
add(labelCount);
add(fieldCount);
add(canvas);
// логика формы
@ -118,21 +101,10 @@ public class FormAntiAircraftGun extends JFrame {
ActionListener buttonCreateAntiAircraftGunListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
int countRollers;
try {
countRollers = Integer.parseInt(fieldCount.getText());
} catch (Exception ex) {
countRollers = 0;
}
if (countRollers != 4 && countRollers != 5 && countRollers != 6) {
JOptionPane.showMessageDialog(null, "Число должно быть равно 4, 5 или 6.\nКол-во катков приравнено к 4");
countRollers = 4;
}
Random rand = new Random();
_drawningArmoredCar = new DrawningArmoredCar(rand.nextInt(200) + 100, rand.nextInt(2000) + 1000,
new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256)),
countRollers,
rand.nextInt(4,7),
canvas.getWidth(), canvas.getHeight());
_drawningArmoredCar.SetPosition(rand.nextInt(100) + 10, rand.nextInt(100) + 10);
@ -143,21 +115,10 @@ public class FormAntiAircraftGun extends JFrame {
ActionListener buttonCreateArmoredCarListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
int countRollers;
try {
countRollers = Integer.parseInt(fieldCount.getText());
} catch (Exception ex) {
countRollers = 0;
}
if (countRollers != 4 && countRollers != 5 && countRollers != 6) {
JOptionPane.showMessageDialog(null, "Число должно быть равно 4, 5 или 6.\nКол-во катков приравнено к 4");
countRollers = 4;
}
Random rand = new Random();
_drawningArmoredCar = new DrawningAntiAircraftGun(rand.nextInt(200) + 100, rand.nextInt(2000) + 1000,
new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256)),
countRollers,
rand.nextInt(4,7),
new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256)),
rand.nextBoolean(), rand.nextBoolean(),
canvas.getWidth(), canvas.getHeight());