diff --git a/.idea/workspace.xml b/.idea/workspace.xml index b3f7216..6892226 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -1,12 +1,31 @@ + + - + + + + + + + + + + + + @@ -16,12 +35,17 @@ \ No newline at end of file diff --git a/src/CountDecks.java b/src/CountDecks.java new file mode 100644 index 0000000..8114f64 --- /dev/null +++ b/src/CountDecks.java @@ -0,0 +1,5 @@ +public enum CountDecks { + OneDeck, + TwoDecks, + ThreeDecks +} diff --git a/src/Direction.java b/src/Direction.java new file mode 100644 index 0000000..a641b80 --- /dev/null +++ b/src/Direction.java @@ -0,0 +1,6 @@ +public enum Direction { + Up, + Down, + Left, + Right +} diff --git a/src/DrawingDecks.java b/src/DrawingDecks.java new file mode 100644 index 0000000..fbb6fe2 --- /dev/null +++ b/src/DrawingDecks.java @@ -0,0 +1,41 @@ +import java.awt.*; +public class DrawingDecks { + private CountDecks countDecks; + private int NumberDecks; + public void SetCountDecks(int value){ + NumberDecks = value; + switch (value){ + case 2: + countDecks = CountDecks.TwoDecks; + break; + case 3: + countDecks = CountDecks.ThreeDecks; + break; + default: + countDecks = CountDecks.OneDeck; + } + }; + public void DrawDeck(int x, int y, int width, int heght, Graphics g, Color BodyColor){ + g.setColor(BodyColor); + g.fillRect(x, y, width, heght); + g.setColor(Color.black); + g.drawRect(x, y, width, heght); + } + + public void DrawingDecks(int _startPosX, int _startPosY, Color BodyColor, Graphics g){ + switch (countDecks){ + case OneDeck: + DrawDeck(_startPosX + 25, _startPosY + 80, 130, 30, g, BodyColor); + break; + case TwoDecks: + DrawDeck(_startPosX + 25, _startPosY + 80, 130, 30, g, BodyColor); + DrawDeck(_startPosX + 40, _startPosY + 55, 100, 25, g, BodyColor); + break; + case ThreeDecks: + DrawDeck(_startPosX + 25, _startPosY + 80, 130, 30, g, BodyColor); + DrawDeck(_startPosX + 40, _startPosY + 55, 100, 25, g, BodyColor); + DrawDeck(_startPosX + 45, _startPosY + 30, 75, 25, g, BodyColor); + break; + } + } +} \ No newline at end of file diff --git a/src/EntityShip.java b/src/EntityShip.java new file mode 100644 index 0000000..7d537cd --- /dev/null +++ b/src/EntityShip.java @@ -0,0 +1,57 @@ +import java.awt.*; +public class EntityShip { + private int Speed; + public int GetSpeed(){ + return Speed; + } + private void SetSpeed(int speed){ + Speed = speed; + } + private double Weight; + public double GetWeight(){ + return Weight; + } + private void SetWeight(int weight){ + Weight = weight; + } + private Color BodyColor; + public Color GetBodyColor(){ + return BodyColor; + } + private void SetBodyColor(Color bodyColor){ + BodyColor = bodyColor; + } + private Color AdditionlaColor; + public Color GetAddColor(){ + return AdditionlaColor; + } + private void SetAddColor(Color addColor){ + AdditionlaColor = addColor; + } + private boolean Pipes; + public boolean GetPipes(){ + return Pipes; + } + private void SetPipes(boolean pipes){ + Pipes = pipes; + } + private boolean Section; + public boolean GetSection(){ + return Section; + } + private void SetSection(boolean section){ + Section = section; + } + private double Step; + public double GetStep() { + return (double)Speed * 100 / Weight; + } + public void Init(int speed, double weight, Color bodyColor, Color addColor, boolean pipes, boolean section){ + Speed = speed; + Weight = weight; + BodyColor = bodyColor; + AdditionlaColor = addColor; + Pipes = pipes; + Section = section; + } +} diff --git a/src/FormWarmlyShip.java b/src/FormWarmlyShip.java new file mode 100644 index 0000000..f2277cf --- /dev/null +++ b/src/FormWarmlyShip.java @@ -0,0 +1,116 @@ +import javax.swing.*; +import java.awt.*; +import java.awt.Graphics; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.*; + +public class FormWarmlyShip{ + private DrawingShip _drawingShip; + Canvas canv; + public void Draw(){ + canv.repaint(); + } + public FormWarmlyShip(){ + JFrame frame = new JFrame("Warmly Ship"); + JButton buttonCreate = new JButton("Создать"); + buttonCreate.setFocusPainted(false); + buttonCreate.setContentAreaFilled(false); + JButton buttonUp = new JButton(); + buttonUp.setFocusPainted(false); //контур вокруг текста + buttonUp.setContentAreaFilled(false); //раскраска конпки + buttonUp.setName("up"); //имя кнопки при обработке нажания + buttonUp.setIcon(new ImageIcon(((new ImageIcon("resources/upper-arrow.png")).getImage()).getScaledInstance(35, 35, java.awt.Image.SCALE_SMOOTH))); + JButton buttonDown = new JButton(); + buttonDown.setFocusPainted(false); + buttonDown.setContentAreaFilled(false); + buttonDown.setName("down"); + buttonDown.setIcon(new ImageIcon(((new ImageIcon("resources/down-arrow.png")).getImage()).getScaledInstance(35, 35, java.awt.Image.SCALE_SMOOTH))); + JButton buttonLeft = new JButton(); + buttonLeft.setFocusPainted(false); + buttonLeft.setContentAreaFilled(false); + buttonLeft.setName("left"); + buttonLeft.setIcon(new ImageIcon(((new ImageIcon("resources/left-arrow.png")).getImage()).getScaledInstance(35, 35, java.awt.Image.SCALE_SMOOTH))); + JButton buttonRight = new JButton(); + buttonRight.setFocusPainted(false); + buttonRight.setContentAreaFilled(false); + buttonRight.setName("right"); + buttonRight.setIcon(new ImageIcon(((new ImageIcon("resources/right-arrow.png")).getImage()).getScaledInstance(35, 35, java.awt.Image.SCALE_SMOOTH))); + buttonCreate.addActionListener( + new ActionListener() { + public void actionPerformed(ActionEvent e) { + System.out.println(e.getActionCommand()); + Random random = new Random(); + _drawingShip = new DrawingShip(); + _drawingShip.Init( + random.nextInt(200) + 100, + random.nextInt(2000) + 1000, + new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)), + new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)), + random.nextBoolean(), random.nextBoolean(), 900, 460, random.nextInt(3) + 1); + _drawingShip.SetPosition(random.nextInt(90) + 10, random.nextInt(90) + 10); + canv._drawingShip = _drawingShip; + Draw(); + } + } + ); + ActionListener actionListener = new ActionListener() { + public void actionPerformed(ActionEvent e) { + System.out.println(((JButton)(e.getSource())).getName()); + if (_drawingShip == null){ + return; + } + switch ((((JButton)(e.getSource())).getName())){ + case "up": + _drawingShip.MoveTransport(Direction.Up); + break; + case "down": + _drawingShip.MoveTransport(Direction.Down); + break; + case "left": + _drawingShip.MoveTransport(Direction.Left); + break; + case "right": + _drawingShip.MoveTransport(Direction.Right); + break; + } + Draw(); + } + }; + buttonUp.addActionListener(actionListener); + buttonDown.addActionListener(actionListener); + buttonLeft.addActionListener(actionListener); + buttonRight.addActionListener(actionListener); + frame.setSize(920, 500); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.setLayout(null); + canv = new Canvas(); + canv.setBounds(0, 0, 900, 500); + buttonCreate.setBounds(10, 400, 100, 40); + buttonUp.setBounds(800, 360, 40, 40); + buttonDown.setBounds(800, 400, 40, 40); + buttonLeft.setBounds(760, 400, 40, 40); + buttonRight.setBounds(840, 400, 40, 40); + frame.add(canv); + frame.add(buttonCreate); + frame.add(buttonUp); + frame.add(buttonDown); + frame.add(buttonLeft); + frame.add(buttonRight); + frame.setVisible(true); + } + class Canvas extends JComponent{ + public DrawingShip _drawingShip; + public Canvas(){} + + public void paintComponent(Graphics g){ + if (_drawingShip == null){ + return; + } + super.paintComponents(g); + Graphics2D g2d = (Graphics2D)g; + _drawingShip.DrawTransport(g2d); + super.repaint(); + } + } +} \ No newline at end of file diff --git a/src/Main.java b/src/Main.java index 3e59c38..ea4aaa3 100644 --- a/src/Main.java +++ b/src/Main.java @@ -1,5 +1,5 @@ public class Main { public static void main(String[] args) { - System.out.println("Hello world!"); + new FormWarmlyShip(); } } \ No newline at end of file