некоторые изменения
This commit is contained in:
parent
ba8046949c
commit
f22e833972
@ -1,6 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<component name="NewModuleRootManager">
|
||||
<output url="file://$MODULE_DIR$/out/production/AircraftCarrier_Hard" />
|
||||
<output-test url="file://$MODULE_DIR$/../../../ирино, не трогат/!/!/!/!/RPP/ProjectAircraftCarrierHard/out/test/AircraftCarrier_Hard" />
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
|
13
src/BlockCount.java
Normal file
13
src/BlockCount.java
Normal file
@ -0,0 +1,13 @@
|
||||
public enum BlockCount {
|
||||
TwoBlocks(2),
|
||||
FourBlocks(4),
|
||||
SixBlocks(6);
|
||||
|
||||
private final int Value;
|
||||
BlockCount(int count){
|
||||
Value=count;
|
||||
}
|
||||
public int GetBlockCount(){
|
||||
return Value;
|
||||
}
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
public enum BlockDirection {
|
||||
TwoBlocks,
|
||||
FourBlocks,
|
||||
SixBlocks;
|
||||
}
|
9
src/BlockForm.java
Normal file
9
src/BlockForm.java
Normal file
@ -0,0 +1,9 @@
|
||||
public enum BlockForm {
|
||||
Rect(0),
|
||||
Round(1),
|
||||
Triangle(2);
|
||||
public final int Value;
|
||||
BlockForm(int i) {
|
||||
Value=i;
|
||||
}
|
||||
}
|
@ -1,45 +1,40 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawingBlocks {
|
||||
BlockDirection blockDirection;
|
||||
public class DrawingBlocks implements IDrawingObjectBlock{
|
||||
private BlockCount _block = null;
|
||||
@Override
|
||||
public void SetBlockCount(int count){
|
||||
for (BlockCount temp: BlockCount.values())
|
||||
if (temp.GetBlockCount() == count){
|
||||
_block=temp;
|
||||
return;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void DrawBlocks(Graphics2D g2, int _startPosX, int _startPosY){
|
||||
switch(blockDirection){
|
||||
case TwoBlocks:
|
||||
g2.setColor(Color.GRAY);
|
||||
g2.fillRect(_startPosX + 15, _startPosY + 10, 10, 10);
|
||||
g2.fillRect(_startPosX + 15, _startPosY + 20, 10, 10);
|
||||
g2.setColor(Color.BLACK);
|
||||
g2.drawRect(_startPosX + 15, _startPosY + 10, 10, 10);
|
||||
g2.drawRect(_startPosX + 15, _startPosY + 20, 10, 10);
|
||||
break;
|
||||
case FourBlocks:
|
||||
g2.setColor(Color.GRAY);
|
||||
g2.fillRect(_startPosX + 15, _startPosY + 10, 10, 10);
|
||||
g2.fillRect(_startPosX + 15, _startPosY + 20, 10, 10);
|
||||
g2.fillRect(_startPosX + 25, _startPosY + 10, 10, 10);
|
||||
g2.fillRect(_startPosX + 25, _startPosY + 20, 10, 10);
|
||||
g2.setColor(Color.BLACK);
|
||||
g2.drawRect(_startPosX + 15, _startPosY + 10, 10, 10);
|
||||
g2.drawRect(_startPosX + 15, _startPosY + 20, 10, 10);
|
||||
g2.drawRect(_startPosX + 25, _startPosY + 10, 10, 10);
|
||||
g2.drawRect(_startPosX + 25, _startPosY + 20, 10, 10);
|
||||
break;
|
||||
case SixBlocks:
|
||||
g2.setColor(Color.GRAY);
|
||||
g2.fillRect(_startPosX + 15, _startPosY + 10, 10, 10);
|
||||
g2.fillRect(_startPosX + 15, _startPosY + 20, 10, 10);
|
||||
g2.fillRect(_startPosX + 25, _startPosY + 10, 10, 10);
|
||||
g2.fillRect(_startPosX + 25, _startPosY + 20, 10, 10);
|
||||
g2.fillRect(_startPosX + 35, _startPosY + 10, 10, 10);
|
||||
g2.fillRect(_startPosX + 35, _startPosY + 20, 10, 10);
|
||||
g2.setColor(Color.BLACK);
|
||||
g2.drawRect(_startPosX + 15, _startPosY + 10, 10, 10);
|
||||
g2.drawRect(_startPosX + 15, _startPosY + 20, 10, 10);
|
||||
g2.drawRect(_startPosX + 25, _startPosY + 10, 10, 10);
|
||||
g2.drawRect(_startPosX + 25, _startPosY + 20, 10, 10);
|
||||
g2.drawRect(_startPosX + 35, _startPosY + 10, 10, 10);
|
||||
g2.drawRect(_startPosX + 35, _startPosY + 20, 10, 10);
|
||||
break;
|
||||
if (_block.GetBlockCount() >= 2) {
|
||||
g2.setColor(Color.GRAY);
|
||||
g2.fillRect(_startPosX + 15, _startPosY + 10, 10, 10);
|
||||
g2.fillRect(_startPosX + 15, _startPosY + 20, 10, 10);
|
||||
g2.setColor(Color.BLACK);
|
||||
g2.drawRect(_startPosX + 15, _startPosY + 10, 10, 10);
|
||||
g2.drawRect(_startPosX + 15, _startPosY + 20, 10, 10);
|
||||
}
|
||||
if (_block.GetBlockCount() >= 4) {
|
||||
g2.setColor(Color.GRAY);
|
||||
g2.fillRect(_startPosX + 25, _startPosY + 10, 10, 10);
|
||||
g2.fillRect(_startPosX + 25, _startPosY + 20, 10, 10);
|
||||
g2.setColor(Color.BLACK);
|
||||
g2.drawRect(_startPosX + 25, _startPosY + 10, 10, 10);
|
||||
g2.drawRect(_startPosX + 25, _startPosY + 20, 10, 10);
|
||||
}
|
||||
if (_block.GetBlockCount() >= 6) {
|
||||
g2.setColor(Color.GRAY);
|
||||
g2.fillRect(_startPosX + 35, _startPosY + 10, 10, 10);
|
||||
g2.fillRect(_startPosX + 35, _startPosY + 20, 10, 10);
|
||||
g2.setColor(Color.BLACK);
|
||||
g2.drawRect(_startPosX + 35, _startPosY + 10, 10, 10);
|
||||
g2.drawRect(_startPosX + 35, _startPosY + 20, 10, 10);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,9 +7,12 @@ public class DrawingMap extends JPanel{
|
||||
private final FormMap Map;
|
||||
private AbstractMap _abstractMap;
|
||||
BufferedImage bufferedImage;
|
||||
|
||||
public DrawingMap(FormMap map){
|
||||
Map=map;
|
||||
private int Width;
|
||||
private int Height;
|
||||
public DrawingMap(FormMap map, int drawPanelWidth, int drawPanelHeight){
|
||||
Map = map;
|
||||
this.Width = drawPanelWidth;
|
||||
this.Height = drawPanelHeight;
|
||||
_abstractMap = new SimpleMap();
|
||||
}
|
||||
|
||||
@ -20,33 +23,31 @@ public class DrawingMap extends JPanel{
|
||||
}
|
||||
|
||||
private void SetData(DrawingWarship warship) {
|
||||
Random rand=new Random();
|
||||
warship.SetPosition(rand.nextInt(100)+10,rand.nextInt(100)+10,getWidth(),getHeight());
|
||||
Map.SpeedLabel.setText("Скорость: "+warship.GetWarship().GetSpeed());
|
||||
Map.WeightLabel.setText("Вес: "+warship.GetWarship().GetWeight());
|
||||
Map.BodyColorLabel.setText("Цвет: "+Integer.toHexString(warship.GetWarship().GetBodyColor().getRGB()).substring(2));
|
||||
Random rnd = new Random();
|
||||
warship.SetPosition(rnd.nextInt(10, 100), rnd.nextInt(10, 100), Width, Height);
|
||||
Map.toolBarLabelSpeed.setText("Color: " + warship.GetWarship().GetSpeed() + " ");
|
||||
Map.toolBarLabelWieght.setText("Weight: " + warship.GetWarship().GetWeight() + " ");
|
||||
Map.toolBarLabelColor.setText("Color: " + warship.GetWarship().GetBodyColor().getRed() + " " +
|
||||
warship.GetWarship().GetBodyColor().getGreen() + " " + warship.GetWarship().GetBodyColor().getBlue());
|
||||
bufferedImage = _abstractMap.CreateMap(700,550,new DrawingObjectWarship(warship));
|
||||
}
|
||||
//Создание обычного корабля
|
||||
public void CreateButtonAction(){
|
||||
Random rand=new Random();
|
||||
Color color1 = JColorChooser.showDialog(Map, "Выберите цвет тела корабля", null);
|
||||
if(color1==null)
|
||||
color1=new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256));
|
||||
DrawingWarship warship=new DrawingWarship(rand.nextInt(50)+10,rand.nextInt(3000)+20000,color1,rand.nextInt(3));
|
||||
Random rnd=new Random();
|
||||
DrawingWarship warship=new DrawingWarship(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000),
|
||||
new Color(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)));
|
||||
SetData(warship);
|
||||
}
|
||||
//Создание модифицированного корабля
|
||||
public void CreateModifButtonAction(){
|
||||
Random rand=new Random();
|
||||
Color color1=JColorChooser.showDialog(Map, "Выберите цвет тела корабля",null);
|
||||
Color color2=JColorChooser.showDialog(Map, "Выборите цвет модификаций корабля",null);
|
||||
if(color1==null)
|
||||
color1=new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256));
|
||||
if (color2==null)
|
||||
color2=new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256));
|
||||
DrawingWarship warship = new DrawingAdvancedWarship(rand.nextInt(50) + 10, rand.nextInt(3000) + 20000, color1,
|
||||
color2, rand.nextBoolean(), rand.nextBoolean(), rand.nextBoolean(),rand.nextInt(3));
|
||||
Random rnd = new Random();
|
||||
DrawingWarship warship = new DrawingAircraftCarrier(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000),
|
||||
new Color(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)),
|
||||
new Color(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)),
|
||||
rnd.nextBoolean(), rnd.nextBoolean(), rnd.nextBoolean());
|
||||
SetData(warship);
|
||||
}
|
||||
|
||||
public void DirectionButtonAction(Direction side){
|
||||
if(_abstractMap != null){
|
||||
bufferedImage = _abstractMap.MoveObject(side);
|
||||
@ -59,7 +60,7 @@ public class DrawingMap extends JPanel{
|
||||
_abstractMap = new SimpleMap();
|
||||
break;
|
||||
case "Вторая карта":
|
||||
_abstractMap = new SecondMap();
|
||||
_abstractMap = new LineMap();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
40
src/DrawingRoundBlocks.java
Normal file
40
src/DrawingRoundBlocks.java
Normal file
@ -0,0 +1,40 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawingRoundBlocks implements IDrawingObjectBlock{
|
||||
private BlockCount _block = null;
|
||||
@Override
|
||||
public void SetBlockCount(int count){
|
||||
for (BlockCount temp: BlockCount.values())
|
||||
if (temp.GetBlockCount() == count){
|
||||
_block=temp;
|
||||
return;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void DrawBlocks(Graphics2D g2, int _startPosX, int _startPosY){
|
||||
if (_block.GetBlockCount() >= 2) {
|
||||
g2.setColor(Color.GRAY);
|
||||
g2.fillRect(_startPosX + 15, _startPosY + 10, 10, 10);
|
||||
g2.fillRect(_startPosX + 15, _startPosY + 20, 10, 10);
|
||||
g2.setColor(Color.BLACK);
|
||||
g2.drawRect(_startPosX + 15, _startPosY + 10, 10, 10);
|
||||
g2.drawRect(_startPosX + 15, _startPosY + 20, 10, 10);
|
||||
}
|
||||
if (_block.GetBlockCount() >= 4) {
|
||||
g2.setColor(Color.GRAY);
|
||||
g2.fillRect(_startPosX + 25, _startPosY + 10, 10, 10);
|
||||
g2.fillRect(_startPosX + 25, _startPosY + 20, 10, 10);
|
||||
g2.setColor(Color.BLACK);
|
||||
g2.drawRect(_startPosX + 25, _startPosY + 10, 10, 10);
|
||||
g2.drawRect(_startPosX + 25, _startPosY + 20, 10, 10);
|
||||
}
|
||||
if (_block.GetBlockCount() >= 6) {
|
||||
g2.setColor(Color.GRAY);
|
||||
g2.fillRect(_startPosX + 35, _startPosY + 10, 10, 10);
|
||||
g2.fillRect(_startPosX + 35, _startPosY + 20, 10, 10);
|
||||
g2.setColor(Color.BLACK);
|
||||
g2.drawRect(_startPosX + 35, _startPosY + 10, 10, 10);
|
||||
g2.drawRect(_startPosX + 35, _startPosY + 20, 10, 10);
|
||||
}
|
||||
}
|
||||
}
|
@ -18,13 +18,15 @@ public class DrawingWarship {
|
||||
{
|
||||
Warship = new EntityWarship(speed, weight, bodyColor);
|
||||
Blocks = new DrawingBlocks();
|
||||
Blocks.blockDirection = BlockRandom();
|
||||
Random rnd = new Random();
|
||||
Blocks.SetBlockCount(rnd.nextInt(0,6));
|
||||
}
|
||||
protected DrawingWarship(int speed, float weight, Color bodyColor, int warshipWidth, int warshipHeight)
|
||||
{
|
||||
this(speed, weight, bodyColor);
|
||||
_warshipWidth = warshipWidth;
|
||||
_warshipHeight = warshipHeight;
|
||||
|
||||
}
|
||||
|
||||
public void SetPosition(int x, int y, int width, int height)
|
||||
@ -115,15 +117,6 @@ public class DrawingWarship {
|
||||
Blocks.DrawBlocks(g2,_startPosX, _startPosY);
|
||||
}
|
||||
|
||||
public BlockDirection BlockRandom(){
|
||||
Random rand = new Random();
|
||||
int resRand = rand.nextInt(3);
|
||||
if(resRand == 0) return BlockDirection.TwoBlocks;
|
||||
if(resRand == 1) return BlockDirection.FourBlocks;
|
||||
if(resRand == 2) return BlockDirection.SixBlocks;
|
||||
return null;
|
||||
}
|
||||
|
||||
public void ChangeBorders(int width, int height)
|
||||
{
|
||||
_pictureWidth = width;
|
||||
|
126
src/FormMap.java
126
src/FormMap.java
@ -1,19 +1,14 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ComponentAdapter;
|
||||
import java.awt.event.ComponentEvent;
|
||||
import java.util.Objects;
|
||||
import java.util.Random;
|
||||
|
||||
public class FormMap extends JFrame{
|
||||
private AbstractMap _abstractMap;
|
||||
DrawingMap map = new DrawingMap(this, this.getWidth(), this.getHeight());
|
||||
private JPanel mainPanel;
|
||||
private JToolBar toolBar;
|
||||
private JLabel toolBarLabelSpeed;
|
||||
private JLabel toolBarLabelWieght;
|
||||
private JLabel toolBarLabelColor;
|
||||
public JLabel toolBarLabelSpeed;
|
||||
public JLabel toolBarLabelWieght;
|
||||
public JLabel toolBarLabelColor;
|
||||
private JButton buttonCreate;
|
||||
private JButton buttonCreateModif;
|
||||
private JButton buttonRight;
|
||||
@ -25,23 +20,6 @@ public class FormMap extends JFrame{
|
||||
|
||||
public FormMap(){
|
||||
InitializeComponent();
|
||||
_abstractMap = new SimpleMap();
|
||||
}
|
||||
|
||||
private void SetData(DrawingWarship warship){
|
||||
Graphics2D graphics = (Graphics2D) drawPanel.getGraphics();
|
||||
graphics.clearRect(0, 0, drawPanel.getWidth(), drawPanel.getHeight());
|
||||
drawPanel.paintComponents(graphics);
|
||||
graphics.drawImage(_abstractMap.CreateMap(drawPanel.getWidth(), drawPanel.getHeight(), new DrawingObjectWarship(warship)),0,0,null);
|
||||
toolBarLabelSpeed.setText("Color: " + warship.GetWarship().GetSpeed() + " ");
|
||||
toolBarLabelWieght.setText("Weight: " + warship.GetWarship().GetWeight() + " ");
|
||||
toolBarLabelColor.setText("Color: " + warship.GetWarship().GetBodyColor().getRed() + " " +
|
||||
warship.GetWarship().GetBodyColor().getGreen() + " " + warship.GetWarship().GetBodyColor().getBlue());
|
||||
}
|
||||
|
||||
private void resizeWindow() {
|
||||
_warship.ChangeBorders(drawPanel.getWidth(), drawPanel.getHeight());
|
||||
Draw();
|
||||
}
|
||||
|
||||
private void InitializeComponent() {
|
||||
@ -60,85 +38,47 @@ public class FormMap extends JFrame{
|
||||
Icon iconRight = new ImageIcon("src\\Images\\ArrowRight.jpg");
|
||||
buttonRight.setIcon(iconRight);
|
||||
|
||||
ComboBoxSelectorMap.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
String mapName = Objects.requireNonNull(ComboBoxSelectorMap.getSelectedItem()).toString();
|
||||
switch (mapName){
|
||||
case "Простая карта":
|
||||
_abstractMap = new SimpleMap();
|
||||
break;
|
||||
case "Вторая карта":
|
||||
_abstractMap = new LineMap();
|
||||
break;
|
||||
}
|
||||
}
|
||||
buttonCreate.addActionListener(e -> {
|
||||
map.CreateButtonAction();
|
||||
ReDraw();
|
||||
});
|
||||
|
||||
//кнопка добавления объекта
|
||||
buttonCreate.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Random rnd = new Random();
|
||||
var warship = new DrawingWarship(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000),
|
||||
new Color(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)));
|
||||
SetData(warship);
|
||||
Draw();
|
||||
}
|
||||
buttonCreateModif.addActionListener(e -> {
|
||||
map.CreateModifButtonAction();
|
||||
ReDraw();
|
||||
});
|
||||
|
||||
//добавление модифицированного объекта
|
||||
/*buttonCreateModif.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Random rnd = new Random();
|
||||
_warship = new DrawingAircraftCarrier(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000),
|
||||
new Color(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)),
|
||||
new Color(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)),
|
||||
rnd.nextBoolean(), rnd.nextBoolean(), rnd.nextBoolean());
|
||||
SetData();
|
||||
Draw();
|
||||
}
|
||||
buttonUp.addActionListener(e -> {
|
||||
map.DirectionButtonAction(Direction.Up);
|
||||
ReDraw();
|
||||
});
|
||||
|
||||
buttonLeft.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (_warship != null) _warship.MoveTransport(Direction.Left);
|
||||
Draw();
|
||||
}
|
||||
buttonLeft.addActionListener(e -> {
|
||||
map.DirectionButtonAction(Direction.Left);
|
||||
ReDraw();
|
||||
});
|
||||
|
||||
buttonRight.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (_warship != null) _warship.MoveTransport(Direction.Right);
|
||||
Draw();
|
||||
}
|
||||
buttonRight.addActionListener(e -> {
|
||||
map.DirectionButtonAction(Direction.Right);
|
||||
ReDraw();
|
||||
});
|
||||
|
||||
buttonUp.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (_warship != null) _warship.MoveTransport(Direction.Up);
|
||||
Draw();
|
||||
}
|
||||
buttonDown.addActionListener(e -> {
|
||||
map.DirectionButtonAction(Direction.Down);
|
||||
ReDraw();
|
||||
});
|
||||
|
||||
buttonDown.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (_warship != null) _warship.MoveTransport(Direction.Down);
|
||||
Draw();
|
||||
}
|
||||
});*/
|
||||
|
||||
mainPanel.addComponentListener(new ComponentAdapter() {
|
||||
@Override
|
||||
public void componentResized(ComponentEvent e) {
|
||||
super.componentResized(e);
|
||||
resizeWindow();
|
||||
}
|
||||
ComboBoxSelectorMap.addActionListener(e -> {
|
||||
map.ComboBoxSelectorMapAction(Objects.requireNonNull(ComboBoxSelectorMap.getSelectedItem()).toString());
|
||||
ReDraw();
|
||||
});
|
||||
}
|
||||
|
||||
private void ReDraw()
|
||||
{
|
||||
Graphics2D graphics = (Graphics2D) drawPanel.getGraphics();
|
||||
graphics.clearRect(0, 0, drawPanel.getWidth(), drawPanel.getHeight());
|
||||
drawPanel.paintComponents(graphics);
|
||||
map.DrawMap(graphics);
|
||||
}
|
||||
}
|
||||
|
6
src/IDrawingObjectBlock.java
Normal file
6
src/IDrawingObjectBlock.java
Normal file
@ -0,0 +1,6 @@
|
||||
import java.awt.*;
|
||||
|
||||
public interface IDrawingObjectBlock {
|
||||
void SetBlockCount(int count);
|
||||
void DrawBlocks(Graphics2D g, int _startPosX, int _startPosY);
|
||||
}
|
Loading…
Reference in New Issue
Block a user