diff --git a/laba1Loco/Direction.java b/laba1Loco/Direction.java deleted file mode 100644 index f6f3a67..0000000 --- a/laba1Loco/Direction.java +++ /dev/null @@ -1,21 +0,0 @@ -package laba1Loco; - -public enum Direction - { - /// - /// Вверх - /// - Up, - /// - /// Вниз - /// - Down, - /// - /// Влево - /// - Left, - /// - /// Вправо - /// - Right - } \ No newline at end of file diff --git a/laba1Loco/DrawingLoco.java b/laba1Loco/DrawingLoco.java deleted file mode 100644 index 22c71c9..0000000 --- a/laba1Loco/DrawingLoco.java +++ /dev/null @@ -1,327 +0,0 @@ -package laba1Loco; - -import java.awt.*; -import java.util.*; -import javax.swing.*; -import javax.swing.Timer; -import java.awt.event.*; - -public class DrawingLoco{ - - public class WheelDrawing{ - private NumWheel numWheel; - - public NumWheel getSomeProperty() { - return numWheel; - } - - public void setNumWheel(int kwheel){ - switch(kwheel){ - case 2: - numWheel = NumWheel.TwoWheel; - break; - case 3: - numWheel = NumWheel.ThreeWheel; - break; - case 4: - numWheel = NumWheel.FourWheel; - break; - default: - numWheel = NumWheel.TwoWheel; - System.out.println("ВСё плохо, колво колёс почему то не соответтвовало критериям, количество колёс:" + Integer.toString(kwheel) + "но вывели мы как будто их было 2"); - break; - } - } - - void Draw(int _startPosX, int _startPosY, boolean fuelTank, Color color, Graphics2D g2d){ - - g2d.setColor(color); - - g2d.fillOval(_startPosX + 3, _startPosY + 34, 8, 8); - g2d.fillOval(_startPosX + 4, _startPosY + 35, 6, 6); - g2d.fillOval(_startPosX + 26, _startPosY + 34, 8, 8); - g2d.fillOval(_startPosX + 27, _startPosY + 35, 6, 6); - g2d.fillOval(_startPosX + 46, _startPosY + 34, 8, 8); - g2d.fillOval(_startPosX + 47, _startPosY + 35, 6, 6); - g2d.fillOval(_startPosX + 72, _startPosY + 34, 8, 8); - g2d.fillOval(_startPosX + 73, _startPosY + 35, 6, 6); - if (numWheel == NumWheel.TwoWheel){ - g2d.fillOval(_startPosX + 14, _startPosY + 34, 8, 8); - g2d.fillOval(_startPosX + 15, _startPosY + 35, 6, 6); - g2d.fillOval(_startPosX + 59, _startPosY + 34, 8, 8); - g2d.fillOval(_startPosX + 60, _startPosY + 35, 6, 6); - } - if (numWheel == NumWheel.FourWheel){ - g2d.fillOval(_startPosX + 11, _startPosY + 34, 8, 8); - g2d.fillOval(_startPosX + 12, _startPosY + 35, 6, 6); - g2d.fillOval(_startPosX + 18, _startPosY + 34, 8, 8); - g2d.fillOval(_startPosX + 19, _startPosY + 35, 6, 6); - g2d.fillOval(_startPosX + 55, _startPosY + 34, 8, 8); - g2d.fillOval(_startPosX + 56, _startPosY + 35, 6, 6); - g2d.fillOval(_startPosX + 63, _startPosY + 34, 8, 8); - g2d.fillOval(_startPosX + 64, _startPosY + 35, 6, 6); - } - - if (fuelTank){ - g2d.fillOval(_startPosX + 3+85, _startPosY + 34, 8, 8); - g2d.fillOval(_startPosX + 4+85, _startPosY + 35, 6, 6); - g2d.fillOval(_startPosX + 26+85, _startPosY + 34, 8, 8); - g2d.fillOval(_startPosX + 27+85, _startPosY + 35, 6, 6); - g2d.fillOval(_startPosX + 46+85, _startPosY + 34, 8, 8); - g2d.fillOval(_startPosX + 47+85, _startPosY + 35, 6, 6); - g2d.fillOval(_startPosX + 72+85, _startPosY + 34, 8, 8); - g2d.fillOval(_startPosX + 73+85, _startPosY + 35, 6, 6); - if (numWheel == NumWheel.TwoWheel){ - g2d.fillOval(_startPosX + 14+85, _startPosY + 34, 8, 8); - g2d.fillOval(_startPosX + 15+85, _startPosY + 35, 6, 6); - g2d.fillOval(_startPosX + 59+85, _startPosY + 34, 8, 8); - g2d.fillOval(_startPosX + 60+85, _startPosY + 35, 6, 6); - } - if (numWheel == NumWheel.FourWheel){ - g2d.fillOval(_startPosX + 11+85, _startPosY + 34, 8, 8); - g2d.fillOval(_startPosX + 12+85, _startPosY + 35, 6, 6); - g2d.fillOval(_startPosX + 18+85, _startPosY + 34, 8, 8); - g2d.fillOval(_startPosX + 19+85, _startPosY + 35, 6, 6); - g2d.fillOval(_startPosX + 55+85, _startPosY + 34, 8, 8); - g2d.fillOval(_startPosX + 56+85, _startPosY + 35, 6, 6); - g2d.fillOval(_startPosX + 63+85, _startPosY + 34, 8, 8); - g2d.fillOval(_startPosX + 64+85, _startPosY + 35, 6, 6); - } - } - } - } - - private WheelDrawing wheelDrawing; - - /// - /// Класс-сущность - /// - public EntityLoco _EntityLoco; - /// - /// Ширина окна - /// - private int _pictureWidth; - /// - /// Высота окна - /// - private int _pictureHeight; - /// - /// Левая координата прорисовки локомотива - /// - private int _startPosX; - /// - /// Верхняя кооридната прорисовки локомотива - /// - private int _startPosY; - /// - /// Ширина прорисовки локомотива - /// - private int _locoWidth = 83; - /// - /// Высота прорисовки локомотива - /// - private int _locoHeight = 41; - /// - /// Инициализация свойств - /// - /// Скорость - /// Вес - /// Цвет кузова - /// Дополнительный цвет - /// Признак наличия трубы - /// Признак наличия бака - /// Признак наличия паровозной полосы - /// Ширина картинки - /// Высота картинки - /// true - объект создан, false - проверка не пройдена, нельзя создать объект в этих размерах - public boolean Init(int speed, double weight, Color bodyColor, Color additionalColor, boolean tube, boolean fuelTank, boolean locoLine, int numWheel, int width, int height) - { - _pictureWidth = width; - _pictureHeight = height; - if (_pictureHeight < _locoHeight || _pictureWidth < _locoWidth) - return false; - _EntityLoco = new EntityLoco(); - _EntityLoco.Init(speed, weight, bodyColor, additionalColor, tube, fuelTank, locoLine, numWheel); - if (fuelTank) - _locoWidth = 169; - wheelDrawing = new WheelDrawing(); - wheelDrawing.setNumWheel(numWheel); - return true; - } - /// - /// Установка позиции - /// - /// Координата X - /// Координата Y - public void SetPosition(int x, int y) - { - _startPosX = Math.min(x, _pictureWidth-_locoWidth); - _startPosY = Math.min(y, _pictureHeight-_locoHeight); - } - /// - /// Изменение направления перемещения - /// - /// Направление - public void MoveTransport(Direction direction) - { - if (_EntityLoco == null){ - return; - } - switch (direction) - { - //влево - case Left: - if (_startPosX - _EntityLoco.Step > 0) - { - _startPosX -= (int)_EntityLoco.Step; - } - break; - //вверх - case Up: - if (_startPosY - _EntityLoco.Step > 0) - { - _startPosY -= (int)_EntityLoco.Step; - } - break; - // вправо - case Right: - if (_startPosX + _locoWidth + _EntityLoco.Step < _pictureWidth) - { - _startPosX += (int)_EntityLoco.Step; - } - break; - //вниз - case Down: - if (_startPosY + _locoHeight + _EntityLoco.Step < _pictureHeight) - { - _startPosY += (int)_EntityLoco.Step; - } - break; - } - } - /// - /// Прорисовка объекта - /// - /// - public void DrawTransport(Graphics2D g2d) - { - - if (_EntityLoco == null) - { - return; - } - - // body - g2d.setColor(_EntityLoco.BodyColor); - g2d.drawPolyline(new int[]{ - _startPosX + 8, _startPosX + 79, _startPosX + 79, _startPosX + 4, _startPosX + 4, _startPosX + 8, - }, new int[]{ - _startPosY+10, _startPosY+10, _startPosY+32, _startPosY+32, _startPosY+20, _startPosY+10 - }, 6); - g2d.drawPolyline(new int[]{ - _startPosX + 4, _startPosX + 29, _startPosX + 29, _startPosX + 37, _startPosX + 37, _startPosX + 79, _startPosX + 37, _startPosX + 37, _startPosX + 29, _startPosX + 29, - }, new int[]{ - _startPosY+21, _startPosY+21, _startPosY+14, _startPosY+14, _startPosY+21, _startPosY+21, _startPosY+21, _startPosY+29, _startPosY+29, _startPosY+21 - }, 10); - - // trucks - g2d.fillPolygon(new int[]{ -_startPosX + 0,_startPosX + 5,_startPosX + 32,_startPosX + 36, - }, new int[]{ -_startPosY+37,_startPosY+33,_startPosY+33,_startPosY+37 - }, 4); - g2d.fillPolygon(new int[]{ -_startPosX + 44,_startPosX + 49,_startPosX + 76,_startPosX + 80, - }, new int[]{ -_startPosY+37,_startPosY+33,_startPosY+33,_startPosY+37 - }, 4); - - //back - g2d.fillPolygon(new int[]{ -_startPosX + 79,_startPosX + 82,_startPosX + 82,_startPosX + 79, - }, new int[]{ -_startPosY+12,_startPosY+12,_startPosY+30,_startPosY+30 - }, 4); - - - //windows - g2d.setColor(Color.BLUE); - g2d.drawRect(_startPosX + 10, _startPosY + 12, 6, 7); - g2d.drawRect(_startPosX + 19, _startPosY + 12, 6, 7); - g2d.drawRect(_startPosX + 72, _startPosY + 12, 6, 7); - - //wheels - wheelDrawing.Draw(_startPosX, _startPosY, _EntityLoco.FuelTank, _EntityLoco.BodyColor, g2d); - - g2d.setColor(_EntityLoco.AdditionalColor); - if (_EntityLoco.Tube) - { - g2d.drawPolyline(new int[] { -_startPosX + 40,_startPosX + 40,_startPosX + 45,_startPosX + 41,_startPosX + 41,_startPosX + 44,_startPosX + 44,_startPosX + 45,_startPosX + 45, - },new int[] { -_startPosY+9,_startPosY+3,_startPosY+3,_startPosY+3,_startPosY,_startPosY,_startPosY+3,_startPosY+3,_startPosY+9, - },9); - } - if (_EntityLoco.LocoLine) - { - g2d.drawPolyline(new int[] { - _startPosX + 60,_startPosX + 38, - },new int[] { - _startPosY+10,_startPosY+32 - },2); - g2d.drawPolyline(new int[] { - _startPosX + 65,_startPosX + 43, - },new int[] { - _startPosY+10,_startPosY+32 - },2); - g2d.drawPolyline(new int[] { - _startPosX + 70,_startPosX + 48, - },new int[] { - _startPosY+10,_startPosY+32 - },2); - } - if (_EntityLoco.FuelTank) - { - // body - g2d.setColor(_EntityLoco.BodyColor); - g2d.drawPolyline(new int[]{ - _startPosX + 89, _startPosX + 164, _startPosX + 164, _startPosX + 89, _startPosX + 89, - }, new int[]{ - _startPosY+10, _startPosY+10, _startPosY+32, _startPosY+32, _startPosY+10 - }, 5); - g2d.drawPolyline(new int[]{ - _startPosX + 89, _startPosX + 164, - }, new int[]{ - _startPosY+21, _startPosY+21, - }, 2); - - // trucks - g2d.fillPolygon(new int[]{ -_startPosX + 0+85,_startPosX + 5+85,_startPosX + 32+85,_startPosX + 36+85, - }, new int[]{ -_startPosY+37,_startPosY+33,_startPosY+33,_startPosY+37 - }, 4); - g2d.fillPolygon(new int[]{ -_startPosX + 44+85,_startPosX + 49+85,_startPosX + 76+85,_startPosX + 80+85, - }, new int[]{ -_startPosY+37,_startPosY+33,_startPosY+33,_startPosY+37 - }, 4); - - //back - g2d.fillPolygon(new int[]{ -_startPosX + 79+85,_startPosX + 82+85,_startPosX + 82+85,_startPosX + 79+85, - }, new int[]{ -_startPosY+12,_startPosY+12,_startPosY+30,_startPosY+30 - }, 4); - - - //front - g2d.fillPolygon(new int[]{ -_startPosX + 86,_startPosX + 89,_startPosX + 89,_startPosX + 86, - }, new int[]{ -_startPosY+12,_startPosY+12,_startPosY+30,_startPosY+30 - }, 4); - - } - } -} \ No newline at end of file diff --git a/laba1Loco/EntityLoco.java b/laba1Loco/EntityLoco.java deleted file mode 100644 index fa6f254..0000000 --- a/laba1Loco/EntityLoco.java +++ /dev/null @@ -1,69 +0,0 @@ -package laba1Loco; - -import java.awt.*; -import java.util.*; -import javax.swing.*; -import javax.swing.Timer; -import java.awt.event.*; - -public class EntityLoco{ - /// - /// Скорость - /// - public int Speed; - /// - /// Вес - /// - public double Weight; - /// - /// Основной цвет - /// - public Color BodyColor; - /// - /// Дополнительный цвет (для опциональных элементов) - /// - public Color AdditionalColor; - /// - /// Признак (опция) наличия трубы - /// - public boolean Tube; - /// - /// Признак (опция) наличия бака - /// - public boolean FuelTank; - /// - /// Признак (опция) наличия паровозной полосы - /// - public boolean LocoLine; - /// - /// Шаг перемещения автомобиля - /// - public double Step; - /// - /// количество колёс [2;4] - /// - public int numWheel; - /// - /// Инициализация полей объекта-класса спортивного автомобиля - /// - /// Скорость - /// Вес автомобиля - /// Основной цвет - /// Дополнительный цвет - /// Признак наличия трубы - /// Признак наличия бака - /// Признак паровозной гоночной полосы - public void Init(int speed, double weight, Color bodyColor, Color - additionalColor, boolean tube, boolean fuelTank, boolean locoLine, int _numWheel) - { - numWheel = _numWheel; - Speed = speed; - Weight = weight; - BodyColor = bodyColor; - AdditionalColor = additionalColor; - Tube = tube; - FuelTank = fuelTank; - LocoLine = locoLine; - Step = (double)Speed * 100 / Weight; - } -} \ No newline at end of file diff --git a/laba1Loco/Form1.java b/laba1Loco/Form1.java deleted file mode 100644 index 988f589..0000000 --- a/laba1Loco/Form1.java +++ /dev/null @@ -1,124 +0,0 @@ -package laba1Loco; - -import java.awt.*; -import java.util.*; -import javax.swing.*; -import javax.swing.Timer; -import java.awt.event.*; - -public class Form1{ - private DrawingLoco _drawingLoco; - Canvas canv; - - public void Draw(){ - canv.repaint(); - } - - public Form1(){ - JFrame w=new JFrame ("Loco"); - JButton buttonCreate = new JButton("create"); - JButton up = new JButton(); - up.setBorderPainted(false); - up.setFocusPainted(false); - up.setContentAreaFilled(false); - up.setName("up"); - up.setIcon(new ImageIcon("images/arowUp340x259.png")); - JButton down = new JButton(); - down.setBorderPainted(false); - down.setFocusPainted(false); - down.setContentAreaFilled(false); - down.setName("down"); - down.setIcon(new ImageIcon("images/arowDown340x259.png")); - JButton left = new JButton(); - left.setBorderPainted(false); - left.setFocusPainted(false); - left.setContentAreaFilled(false); - left.setName("left"); - left.setIcon(new ImageIcon("images/arowL340x259.png")); - JButton right = new JButton(); - right.setBorderPainted(false); - right.setFocusPainted(false); - right.setContentAreaFilled(false); - right.setName("right"); - right.setIcon(new ImageIcon("images/arowR340x259.png")); - - buttonCreate.addActionListener( - new ActionListener() { - public void actionPerformed(ActionEvent e){ - System.out.println(e.getActionCommand()); - Random random = new Random(); - _drawingLoco = new DrawingLoco(); - _drawingLoco.Init(random.nextInt(100, 300), random.nextInt(1000, 3000), - new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256)), - new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256)), - random.nextInt(0, 2) == 1, random.nextInt(0, 2) == 1, random.nextInt(0, 2) == 1, - random.nextInt(2, 5), 1000, 560); - _drawingLoco.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100)); - canv._drawingLoco = _drawingLoco; - Draw(); - } - } - ); - ActionListener actioListener = new ActionListener() { - public void actionPerformed(ActionEvent e){ - System.out.println(((JButton)(e.getSource())).getName()); - if (_drawingLoco == null) - { - return; - } - switch(((JButton)(e.getSource())).getName()){ - case "up": - _drawingLoco.MoveTransport(Direction.Up); - break; - case "down": - _drawingLoco.MoveTransport(Direction.Down); - break; - case "left": - _drawingLoco.MoveTransport(Direction.Left); - break; - case "right": - _drawingLoco.MoveTransport(Direction.Right); - break; - } - Draw(); - } - }; - up.addActionListener(actioListener); - down.addActionListener(actioListener); - left.addActionListener(actioListener); - right.addActionListener(actioListener); - - w.setSize (1000, 600); - w.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); - w.setLayout(null); - canv = new Canvas(); - canv.setBounds(0, 0, 1000, 600); - buttonCreate.setBounds(2, 540, 100, 20); - up.setBounds(900, 480, 40, 40); - down.setBounds(900, 520, 40, 40); - left.setBounds(860, 520, 40, 40); - right.setBounds(940, 520, 40, 40); - w.add(canv); - w.add(buttonCreate); - w.add(up); - w.add(down); - w.add(left); - w.add(right); - w.setVisible (true); - } -} - -class Canvas extends JComponent{ - public DrawingLoco _drawingLoco; - public Canvas(){ - } - public void paintComponent (Graphics g){ - if (_drawingLoco == null){ - return; - } - super.paintComponents (g) ; - Graphics2D g2d = (Graphics2D)g; - _drawingLoco.DrawTransport(g2d); - super.repaint(); - } -} \ No newline at end of file diff --git a/laba1Loco/Main.java b/laba1Loco/Main.java deleted file mode 100644 index 21414f2..0000000 --- a/laba1Loco/Main.java +++ /dev/null @@ -1,7 +0,0 @@ -package laba1Loco; - -public class Main{ - public static void main(String[] args) { - Form1 form1 = new Form1(); - } -} \ No newline at end of file diff --git a/laba1Loco/NumWheel.java b/laba1Loco/NumWheel.java deleted file mode 100644 index fff8072..0000000 --- a/laba1Loco/NumWheel.java +++ /dev/null @@ -1,17 +0,0 @@ -package laba1Loco; - -public enum NumWheel - { - /// - /// 2 колеса - /// - TwoWheel, - /// - /// 3 колеса - /// - ThreeWheel, - /// - /// 4 колеса - /// - FourWheel - } \ No newline at end of file diff --git a/laba1Loco/images/arowDown340x259.png b/laba1Loco/images/arowDown340x259.png deleted file mode 100644 index 1aef4dc..0000000 Binary files a/laba1Loco/images/arowDown340x259.png and /dev/null differ diff --git a/laba1Loco/images/arowL340x259.png b/laba1Loco/images/arowL340x259.png deleted file mode 100644 index a2e6f8b..0000000 Binary files a/laba1Loco/images/arowL340x259.png and /dev/null differ diff --git a/laba1Loco/images/arowR340x259.png b/laba1Loco/images/arowR340x259.png deleted file mode 100644 index 464963a..0000000 Binary files a/laba1Loco/images/arowR340x259.png and /dev/null differ diff --git a/laba1Loco/images/arowUp340x259.png b/laba1Loco/images/arowUp340x259.png deleted file mode 100644 index 3d8743b..0000000 Binary files a/laba1Loco/images/arowUp340x259.png and /dev/null differ