diff --git a/AbstractMap.java b/AbstractMap.java index 9e9e2a0..a672a1f 100644 --- a/AbstractMap.java +++ b/AbstractMap.java @@ -91,7 +91,6 @@ public abstract class AbstractMap { break; } - if (isMove) { _drawningObject.MoveObject(direction); diff --git a/DrawningBlocks.java b/DrawningBlocks.java index 727b698..fec7e46 100644 --- a/DrawningBlocks.java +++ b/DrawningBlocks.java @@ -3,40 +3,10 @@ import java.awt.*; public class DrawningBlocks implements IDrawningBlocks { private DirectionBlocksOnDeck blocksCount = DirectionBlocksOnDeck.Two; private Color color; - public void SetNewBlocks(int countBlocks){ - if (countBlocks == 4) { - blocksCount = DirectionBlocksOnDeck.Four; - } else if (countBlocks == 6) { - blocksCount = DirectionBlocksOnDeck.Six; - } - else { - blocksCount = DirectionBlocksOnDeck.Two; - } - } public DrawningBlocks(int count, Color color){ SetBlocks(count); this.color = color; } - public void Draw(Graphics2D g, int x, int y) { - g.setColor(color != null ? color : Color.BLACK); - switch (blocksCount) { - case Four -> { - g.fillRect(x + 36, y + 5, 10, 5); - g.fillRect(x + 48, y + 5, 10, 5); - g.fillRect(x + 38, y + 40, 10, 5); - g.fillRect(x + 46, y + 40, 10, 5); - } - case Six -> { - g.fillRect(x + 14, y + 5, 10, 5); - g.fillRect(x + 26, y + 5, 10, 5); - g.fillRect(x + 38, y + 5, 10, 5); - g.fillRect(x + 38, y + 40, 10, 5); - g.fillRect(x + 26, y + 40, 10, 5); - g.fillRect(x + 14, y + 40, 10, 5); - } - } - } - @Override public void DrawBlocks(Graphics g, int x, int y, Color bodyColor) { g.setColor(color != null ? color : Color.BLACK); diff --git a/DrawningLinkor.java b/DrawningLinkor.java index 8be96de..565fd10 100644 --- a/DrawningLinkor.java +++ b/DrawningLinkor.java @@ -27,7 +27,6 @@ public class DrawningLinkor extends DrawningBattleship { g.fillRect((int)_startPosX + 20, (int)_startPosY+5, 23, 7); g.fillRect((int)_startPosX + 20,(int) _startPosY + 37, 23, 7); - } if (entityLinkor.missileBay) { @@ -37,8 +36,6 @@ public class DrawningLinkor extends DrawningBattleship { g.setColor(entityLinkor.dopColor); g.fillOval((int)_startPosX+5,(int) _startPosY + 20, 10, 10); - - } } } diff --git a/DrawningTriangleBlocks.java b/DrawningTriangleBlocks.java index cf4cd97..4557e57 100644 --- a/DrawningTriangleBlocks.java +++ b/DrawningTriangleBlocks.java @@ -15,10 +15,7 @@ public class DrawningTriangleBlocks implements IDrawningBlocks { g.fillPolygon(new int[]{x + 58, x + 66, x+ 72}, new int[]{y + 7, y, y + 7}, 3); g.fillPolygon(new int[]{x + 58, x + 66, x+72}, new int[]{y + 49, y + 42, y + 49}, 3); -// g.fillOval(x + 26, y + 10, 8, 8); -// g.fillOval(x + 38, y + 10, 8, 8); -// g.fillOval(x + 38, y + 35, 8, 8); -// g.fillOval(x + 26, y + 35, 8, 8); + } case Six -> { @@ -28,12 +25,6 @@ public class DrawningTriangleBlocks implements IDrawningBlocks { g.fillPolygon(new int[]{x + 66, x + 64, x+ 80 }, new int[]{y + 49, y + 42, y + 49}, 3); g.fillPolygon(new int[]{x + 58, x + 66, x+ 72}, new int[]{y + 7, y, y + 7}, 3); g.fillPolygon(new int[]{x + 58, x + 66, x+72}, new int[]{y + 49, y + 42, y + 49}, 3); - // g.fillOval(x + 14, y + 10, 8, 8); -// g.fillOval(x + 26, y + 10, 8, 8); -// g.fillOval(x + 38, y + 10, 8, 8); -// g.fillOval(x + 38, y + 35, 8, 8); -// g.fillOval(x + 26, y + 35, 8, 8); -// g.fillOval(x + 14, y + 35, 8, 8); }} } diff --git a/EntityLinkor.java b/EntityLinkor.java index 59f0341..f6edc34 100644 --- a/EntityLinkor.java +++ b/EntityLinkor.java @@ -10,6 +10,5 @@ public class EntityLinkor extends EntityBattleship { dopColor = DopColor; missileBay = MissileBay; turret = Turret; - } } diff --git a/FormBattleship.java b/FormBattleship.java deleted file mode 100644 index b9fa9da..0000000 --- a/FormBattleship.java +++ /dev/null @@ -1,129 +0,0 @@ -import javax.swing.*; -import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.ComponentEvent; -import java.awt.event.ComponentListener; -import java.util.Random; -public class FormBattleship extends JComponent { - private DrawningBattleship _battleship; - private EntityBattleship _entityBattleship; - public static void main(String[] args) { - FormMap formMap = new FormMap(); - } - public FormBattleship() { - JFrame form = new JFrame("Военный корабль"); - form.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - form.setSize(800, 500); - form.setVisible(true); - form.setLocationRelativeTo(null); - form.addComponentListener(new ComponentListener() { - @Override - public void componentResized(ComponentEvent e) { - if(_battleship != null) _battleship.ChangeBorders(getWidth(), getHeight()); - repaint(); - } - - @Override - public void componentMoved(ComponentEvent e) { - } - - @Override - public void componentShown(ComponentEvent e) { - } - - @Override - public void componentHidden(ComponentEvent e) { - } - }); - Panel statusPanel = new Panel(); - statusPanel.setBackground(Color.WHITE); - statusPanel.setLayout(new FlowLayout()); - setLayout(new BorderLayout()); - form.add(statusPanel, BorderLayout.SOUTH); - Label speedLabel = new Label("Скорость: "); - Label weightLabel = new Label("Вес: "); - Label colorLabel = new Label("Цвет: "); - - - JButton createButton = new JButton("Создать"); - createButton.addActionListener(e -> { - int[] countBlocks = {2, 4, 6}; - Random rnd = new Random(); - - _battleship = new DrawningBattleship(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000), - Color.getHSBColor(rnd.nextInt(0, 256), rnd.nextInt(0, 256), - rnd.nextInt(0, 256))); - _battleship.SetPosition(10 + rnd.nextInt(90), 10 + rnd.nextInt(90), form.getWidth(), form.getHeight() - 75); - speedLabel.setText("Скорость: " + _battleship.Battleship.GetSpeed()); - weightLabel.setText("Вес: " + (int)_battleship.Battleship.GetWeight()); - colorLabel.setText("Цвет: " + _battleship.Battleship.GetBodyColor().getRed() + " " + - _battleship.Battleship.GetBodyColor().getGreen() + " " + _battleship.Battleship.GetBodyColor().getBlue() ); - repaint(); - - }); - JButton modifiedButton = new JButton("Модификация"); - modifiedButton.addActionListener(e -> { - Random rnd = new Random(); - - Color colorFirst = JColorChooser.showDialog(null, "Color", new Color(rnd.nextInt(256), rnd.nextInt(256),rnd.nextInt(256))); - Color colorSecond = JColorChooser.showDialog(null, "Color", new Color(rnd.nextInt(256), rnd.nextInt(256),rnd.nextInt(256))); - - _battleship = new DrawningLinkor(rnd.nextInt(200) + 100, rnd.nextInt(1000) + 1000, - colorFirst, - colorSecond, - rnd.nextBoolean(), - rnd.nextBoolean()); - _battleship.SetPosition(10 + rnd.nextInt(90), 10 + rnd.nextInt(90), 800, 500 - 75); -// speedLabel.setText("Speed: " + _locomotive.Locomotive.getSpeed()); -// weightLabel.setText("Weight: " + (int)_locomotive.Locomotive.getWeight()); -// colorLabel.setText("Color: " + _locomotive.Locomotive.getBodyColor().getRed() + " " + _locomotive.Locomotive.getBodyColor().getGreen() + " " + _locomotive.Locomotive.getBodyColor().getBlue() ); - repaint(); - }); - statusPanel.add(createButton); - statusPanel.add(modifiedButton); - statusPanel.add(speedLabel); - statusPanel.add(weightLabel); - statusPanel.add(colorLabel); - JButton upButton = new JButton("↑"); - JButton rightButton = new JButton("→"); - JButton leftButton = new JButton("←"); - JButton downButton = new JButton("↓"); - upButton.addActionListener(e -> { - if (_battleship != null) _battleship.MoveTransport(Direction.Up); - repaint(); - }); - - - rightButton.addActionListener(e -> { - if (_battleship != null) _battleship.MoveTransport(Direction.Right); - repaint(); - }); - - - leftButton.addActionListener(e -> { - if (_battleship != null) _battleship.MoveTransport(Direction.Left); - repaint(); - }); - - - downButton.addActionListener(e -> { - if (_battleship != null) _battleship.MoveTransport(Direction.Down); - repaint(); - }); - - statusPanel.add(leftButton); - statusPanel.add(upButton); - statusPanel.add(rightButton); - statusPanel.add(downButton); - - form.getContentPane().add(this); - } - protected void paintComponent(Graphics g) { - super.paintComponent(g); - Graphics2D g2 = (Graphics2D)g; - if (_battleship != null) _battleship.DrawTransport(g2); - super.repaint(); - } - -} diff --git a/FormMap.java b/FormMap.java index cf2bd04..286fce5 100644 --- a/FormMap.java +++ b/FormMap.java @@ -19,25 +19,6 @@ public class FormMap extends JComponent { form.setSize(1000, 500); form.setVisible(true); form.setLocationRelativeTo(null); -// form.addComponentListener(new ComponentListener() { -// @Override -// public void componentResized(ComponentEvent e) { -// if(_battleship != null) _battleship.ChangeBorders(getWidth(), getHeight()); -// repaint(); -// } -// -// @Override -// public void componentMoved(ComponentEvent e) { -// } -// -// @Override -// public void componentShown(ComponentEvent e) { -// } -// -// @Override -// public void componentHidden(ComponentEvent e) { -// } -// }); Panel statusPanel = new Panel(); statusPanel.setBackground(Color.WHITE); statusPanel.setLayout(new FlowLayout()); @@ -48,8 +29,8 @@ public class FormMap extends JComponent { Label colorLabel = new Label("Цвет: "); String[] maps = { - "Simple Map", - "Sea Map" + "Простая карта", + "Морская карта" }; JComboBox mapSelectComboBox = new JComboBox(maps); @@ -60,10 +41,10 @@ public class FormMap extends JComponent { String item = (String)mapSelectComboBox.getSelectedItem(); if (item == null) return; switch (item) { - case ("Simple Map"): + case ("Простая карта"): _abstractMap = new SimpleMap(); break; - case ("Sea Map"): + case ("Морская карта"): _abstractMap = new SeaMap(); break; @@ -99,9 +80,9 @@ public class FormMap extends JComponent { rnd.nextBoolean(), rnd.nextBoolean()); battleship.SetPosition(10 + rnd.nextInt(90), 10 + rnd.nextInt(90), 800, 500 - 75); - speedLabel.setText("Speed: " + battleship.Battleship.GetSpeed()); - weightLabel.setText("Weight: " + battleship.Battleship.GetWeight()); - colorLabel.setText("Color: " + battleship.Battleship.GetBodyColor().getRed() + " " + battleship.Battleship.GetBodyColor().getGreen() + " " + battleship.Battleship.GetBodyColor().getBlue() ); + speedLabel.setText("Скорость: " + battleship.Battleship.GetSpeed()); + weightLabel.setText("Вес: " + battleship.Battleship.GetWeight()); + colorLabel.setText("Цвет: " + battleship.Battleship.GetBodyColor().getRed() + " " + battleship.Battleship.GetBodyColor().getGreen() + " " + battleship.Battleship.GetBodyColor().getBlue() ); if (_abstractMap != null) bufferedImage = _abstractMap.CreateMap(1000, 490, new DrawningObjectBattleship(battleship)); repaint(); }); diff --git a/SeaMap.java b/SeaMap.java index f35f2a7..501ba8f 100644 --- a/SeaMap.java +++ b/SeaMap.java @@ -33,8 +33,6 @@ public class SeaMap extends AbstractMap { g.setColor(Color.BLUE); g.fillRect((int) (i * _size_x), (int) (j * _size_y), (int)(i * (_size_x + 1)), (int)(j * (_size_y + 1))); - - } @Override