Коммит
This commit is contained in:
parent
df4d079c07
commit
e71eaf0f2d
@ -91,7 +91,6 @@ public abstract class AbstractMap {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (isMove)
|
if (isMove)
|
||||||
{
|
{
|
||||||
_drawningObject.MoveObject(direction);
|
_drawningObject.MoveObject(direction);
|
||||||
|
@ -3,40 +3,10 @@ import java.awt.*;
|
|||||||
public class DrawningBlocks implements IDrawningBlocks {
|
public class DrawningBlocks implements IDrawningBlocks {
|
||||||
private DirectionBlocksOnDeck blocksCount = DirectionBlocksOnDeck.Two;
|
private DirectionBlocksOnDeck blocksCount = DirectionBlocksOnDeck.Two;
|
||||||
private Color color;
|
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){
|
public DrawningBlocks(int count, Color color){
|
||||||
SetBlocks(count);
|
SetBlocks(count);
|
||||||
this.color = color;
|
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
|
@Override
|
||||||
public void DrawBlocks(Graphics g, int x, int y, Color bodyColor) {
|
public void DrawBlocks(Graphics g, int x, int y, Color bodyColor) {
|
||||||
g.setColor(color != null ? color : Color.BLACK);
|
g.setColor(color != null ? color : Color.BLACK);
|
||||||
|
@ -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+5, 23, 7);
|
||||||
g.fillRect((int)_startPosX + 20,(int) _startPosY + 37, 23, 7);
|
g.fillRect((int)_startPosX + 20,(int) _startPosY + 37, 23, 7);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
if (entityLinkor.missileBay)
|
if (entityLinkor.missileBay)
|
||||||
{
|
{
|
||||||
@ -37,8 +36,6 @@ public class DrawningLinkor extends DrawningBattleship {
|
|||||||
g.setColor(entityLinkor.dopColor);
|
g.setColor(entityLinkor.dopColor);
|
||||||
g.fillOval((int)_startPosX+5,(int) _startPosY + 20, 10, 10);
|
g.fillOval((int)_startPosX+5,(int) _startPosY + 20, 10, 10);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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 + 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.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 -> {
|
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 + 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 + 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.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);
|
|
||||||
|
|
||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,5 @@ public class EntityLinkor extends EntityBattleship {
|
|||||||
dopColor = DopColor;
|
dopColor = DopColor;
|
||||||
missileBay = MissileBay;
|
missileBay = MissileBay;
|
||||||
turret = Turret;
|
turret = Turret;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
33
FormMap.java
33
FormMap.java
@ -19,25 +19,6 @@ public class FormMap extends JComponent {
|
|||||||
form.setSize(1000, 500);
|
form.setSize(1000, 500);
|
||||||
form.setVisible(true);
|
form.setVisible(true);
|
||||||
form.setLocationRelativeTo(null);
|
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();
|
Panel statusPanel = new Panel();
|
||||||
statusPanel.setBackground(Color.WHITE);
|
statusPanel.setBackground(Color.WHITE);
|
||||||
statusPanel.setLayout(new FlowLayout());
|
statusPanel.setLayout(new FlowLayout());
|
||||||
@ -48,8 +29,8 @@ public class FormMap extends JComponent {
|
|||||||
Label colorLabel = new Label("Цвет: ");
|
Label colorLabel = new Label("Цвет: ");
|
||||||
|
|
||||||
String[] maps = {
|
String[] maps = {
|
||||||
"Simple Map",
|
"Простая карта",
|
||||||
"Sea Map"
|
"Морская карта"
|
||||||
|
|
||||||
};
|
};
|
||||||
JComboBox mapSelectComboBox = new JComboBox(maps);
|
JComboBox mapSelectComboBox = new JComboBox(maps);
|
||||||
@ -60,10 +41,10 @@ public class FormMap extends JComponent {
|
|||||||
String item = (String)mapSelectComboBox.getSelectedItem();
|
String item = (String)mapSelectComboBox.getSelectedItem();
|
||||||
if (item == null) return;
|
if (item == null) return;
|
||||||
switch (item) {
|
switch (item) {
|
||||||
case ("Simple Map"):
|
case ("Простая карта"):
|
||||||
_abstractMap = new SimpleMap();
|
_abstractMap = new SimpleMap();
|
||||||
break;
|
break;
|
||||||
case ("Sea Map"):
|
case ("Морская карта"):
|
||||||
_abstractMap = new SeaMap();
|
_abstractMap = new SeaMap();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -99,9 +80,9 @@ public class FormMap extends JComponent {
|
|||||||
rnd.nextBoolean(),
|
rnd.nextBoolean(),
|
||||||
rnd.nextBoolean());
|
rnd.nextBoolean());
|
||||||
battleship.SetPosition(10 + rnd.nextInt(90), 10 + rnd.nextInt(90), 800, 500 - 75);
|
battleship.SetPosition(10 + rnd.nextInt(90), 10 + rnd.nextInt(90), 800, 500 - 75);
|
||||||
speedLabel.setText("Speed: " + battleship.Battleship.GetSpeed());
|
speedLabel.setText("Скорость: " + battleship.Battleship.GetSpeed());
|
||||||
weightLabel.setText("Weight: " + battleship.Battleship.GetWeight());
|
weightLabel.setText("Вес: " + battleship.Battleship.GetWeight());
|
||||||
colorLabel.setText("Color: " + battleship.Battleship.GetBodyColor().getRed() + " " + battleship.Battleship.GetBodyColor().getGreen() + " " + battleship.Battleship.GetBodyColor().getBlue() );
|
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));
|
if (_abstractMap != null) bufferedImage = _abstractMap.CreateMap(1000, 490, new DrawningObjectBattleship(battleship));
|
||||||
repaint();
|
repaint();
|
||||||
});
|
});
|
||||||
|
@ -33,8 +33,6 @@ public class SeaMap extends AbstractMap {
|
|||||||
g.setColor(Color.BLUE);
|
g.setColor(Color.BLUE);
|
||||||
g.fillRect((int) (i * _size_x), (int) (j * _size_y), (int)(i * (_size_x + 1)), (int)(j * (_size_y + 1)));
|
g.fillRect((int) (i * _size_x), (int) (j * _size_y), (int)(i * (_size_x + 1)), (int)(j * (_size_y + 1)));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user