готово
This commit is contained in:
parent
6c8db7840d
commit
1703457b15
@ -27,13 +27,13 @@ public abstract class AbstractMap {
|
|||||||
return DrawMapWithObject();
|
return DrawMapWithObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean CanMove(Direction direction, float[] position) //Проверка на возможность шага
|
private boolean CanMove(float[] position) //Проверка на возможность шага
|
||||||
{
|
{
|
||||||
for (int i = (int)(position[2] / _size_y); i <= (int)(position[3] / _size_y); ++i)
|
for (int i = (int)(position[2] / _size_y); i <= (int)(position[3] / _size_y); ++i)
|
||||||
{
|
{
|
||||||
for (int j = (int)(position[0] / _size_x); j <= (int)(position[1] / _size_x); ++j)
|
for (int j = (int)(position[0] / _size_x); j <= (int)(position[1] / _size_x); ++j)
|
||||||
{
|
{
|
||||||
if (i >= 0 && j >= 0 && i < _map.length && j < _map[0].length && _map[i][j] == _barrier) return false;
|
if (_map[i][j] == _barrier) return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -59,7 +59,7 @@ public abstract class AbstractMap {
|
|||||||
position[3] += _drawningObject.getStep();
|
position[3] += _drawningObject.getStep();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CanMove(direction, position))
|
if (CanMove(position))
|
||||||
{
|
{
|
||||||
_drawningObject.MoveObject(direction);
|
_drawningObject.MoveObject(direction);
|
||||||
}
|
}
|
||||||
@ -91,22 +91,22 @@ public abstract class AbstractMap {
|
|||||||
{
|
{
|
||||||
return bmp;
|
return bmp;
|
||||||
}
|
}
|
||||||
Graphics gr = bmp.getGraphics();
|
Graphics g = bmp.getGraphics();
|
||||||
for (int i = 0; i < _map.length; ++i)
|
for (int i = 0; i < _map.length; ++i)
|
||||||
{
|
{
|
||||||
for (int j = 0; j < _map[0].length; ++j)
|
for (int j = 0; j < _map[0].length; ++j)
|
||||||
{
|
{
|
||||||
if (_map[i][j] == _freeRoad)
|
if (_map[i][j] == _freeRoad)
|
||||||
{
|
{
|
||||||
DrawRoadPart(gr, i, j);
|
DrawRoadPart(g, i, j);
|
||||||
}
|
}
|
||||||
else if (_map[i][j] == _barrier)
|
else if (_map[i][j] == _barrier)
|
||||||
{
|
{
|
||||||
DrawBarrierPart(gr, i, j);
|
DrawBarrierPart(g, i, j);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_drawningObject.DrawningObject(gr);
|
_drawningObject.DrawningObject(g);
|
||||||
return bmp;
|
return bmp;
|
||||||
}
|
}
|
||||||
protected abstract void GenerateMap();
|
protected abstract void GenerateMap();
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
public enum Direction {
|
public enum Direction {
|
||||||
|
None(0), //None
|
||||||
Left(1), //Влево
|
Left(1), //Влево
|
||||||
Up(2), //Вверх
|
Up(2), //Вверх
|
||||||
Right(3), //Вправо
|
Right(3), //Вправо
|
||||||
|
@ -1,12 +1,14 @@
|
|||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
|
||||||
public class DrawDeck {
|
public class DrawDeck implements IDrawningDeck {
|
||||||
private Deck deckCount;
|
private Deck deckCount;
|
||||||
|
|
||||||
|
@Override
|
||||||
public void SetDeckCount(int count){
|
public void SetDeckCount(int count){
|
||||||
deckCount = Deck.GetDeck(count);
|
deckCount = Deck.GetDeck(count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void DrawningDeck(float _startPosX, float _startPosY, int _warmlyShipWidth, Graphics2D g2d, Color bodyColor){
|
public void DrawningDeck(float _startPosX, float _startPosY, int _warmlyShipWidth, Graphics2D g2d, Color bodyColor){
|
||||||
switch (deckCount)
|
switch (deckCount)
|
||||||
{
|
{
|
||||||
|
32
DrawGuns.java
Normal file
32
DrawGuns.java
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class DrawGuns implements IDrawningDeck {
|
||||||
|
private Deck gunsCount;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void SetDeckCount(int count) {
|
||||||
|
gunsCount = Deck.GetDeck(count);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void DrawningDeck(float _startPosX, float _startPosY, int _warmlyShipWidth, Graphics2D g2d, Color bodyColor) {
|
||||||
|
int count = 1;
|
||||||
|
switch (gunsCount)
|
||||||
|
{
|
||||||
|
case One:
|
||||||
|
break;
|
||||||
|
case Two:
|
||||||
|
count = 2;
|
||||||
|
break;
|
||||||
|
case Three:
|
||||||
|
count = 3;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
g2d.setColor(Color.DARK_GRAY);
|
||||||
|
for (int i = 0; i < count; ++i)
|
||||||
|
{
|
||||||
|
g2d.fillPolygon(new Polygon(new int[]{(int)(_startPosX + _warmlyShipWidth / 5 * (i + 1)) + 10, (int)(_startPosX + _warmlyShipWidth / 5 * (i + 1)) + 25, (int)(_startPosX + _warmlyShipWidth / 5 * (i + 1)) + 40, (int)(_startPosX + _warmlyShipWidth / 5 * (i + 1)) + 25}, new int[]{(int)_startPosY - 20, (int)_startPosY - 10, (int)_startPosY - 30, (int)_startPosY - 40}, 4));
|
||||||
|
g2d.fillOval((int)(_startPosX + _warmlyShipWidth / 5 * (i + 1)), (int)_startPosY - 20, 25, 20);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
32
DrawOvalDeck.java
Normal file
32
DrawOvalDeck.java
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class DrawOvalDeck implements IDrawningDeck{
|
||||||
|
private Deck deckCount;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void SetDeckCount(int count) {
|
||||||
|
deckCount = Deck.GetDeck(count);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void DrawningDeck(float _startPosX, float _startPosY, int _warmlyShipWidth, Graphics2D g2d, Color bodyColor) {
|
||||||
|
int count = 1;
|
||||||
|
switch (deckCount)
|
||||||
|
{
|
||||||
|
case One:
|
||||||
|
break;
|
||||||
|
case Two:
|
||||||
|
count = 2;
|
||||||
|
break;
|
||||||
|
case Three:
|
||||||
|
count = 3;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
for (int i = 1; i < count; ++i){
|
||||||
|
g2d.setColor(bodyColor);
|
||||||
|
g2d.fillOval((int)(_startPosX + _warmlyShipWidth / 5), (int)_startPosY - 20 * i, _warmlyShipWidth * 3 / 5, 20);
|
||||||
|
g2d.setColor(Color.BLACK);
|
||||||
|
g2d.drawOval((int)(_startPosX + _warmlyShipWidth / 5), (int)_startPosY - 20 * i, _warmlyShipWidth * 3 / 5, 20);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -13,14 +13,26 @@ public class DrawingShip extends JPanel {
|
|||||||
protected int _warmlyShipHeight = 50; //Высота отрисовки корабля
|
protected int _warmlyShipHeight = 50; //Высота отрисовки корабля
|
||||||
|
|
||||||
private int deckCount = 1;
|
private int deckCount = 1;
|
||||||
private DrawDeck dd = new DrawDeck();
|
private IDrawningDeck idd;
|
||||||
|
|
||||||
//Инициализация
|
//Инициализация
|
||||||
public DrawingShip(int speed, float weight, Color bodyColor)
|
public DrawingShip(int speed, float weight, Color bodyColor)
|
||||||
{
|
{
|
||||||
warmlyShip = new EntityWarmlyShip(speed, weight, bodyColor);
|
warmlyShip = new EntityWarmlyShip(speed, weight, bodyColor);
|
||||||
Random random = new Random();
|
Random random = new Random();
|
||||||
dd.SetDeckCount(random.nextInt(1, 4));
|
switch (random.nextInt(3))
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
idd = new DrawDeck();
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
idd = new DrawGuns();
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
idd = new DrawOvalDeck();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
idd.SetDeckCount(random.nextInt(1, 4));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected DrawingShip(int speed, float weight, Color bodyColor, int warmlyWidth, int warmlyHeight)
|
protected DrawingShip(int speed, float weight, Color bodyColor, int warmlyWidth, int warmlyHeight)
|
||||||
@ -88,7 +100,7 @@ public class DrawingShip extends JPanel {
|
|||||||
g2d.drawOval((int)(_startPosX + _warmlyShipWidth / 5), (int)_startPosY + 25, 20, 20);
|
g2d.drawOval((int)(_startPosX + _warmlyShipWidth / 5), (int)_startPosY + 25, 20, 20);
|
||||||
g2d.drawOval((int)(_startPosX + _warmlyShipWidth * 3 / 5 + 5), (int)_startPosY + 25, 20, 20);
|
g2d.drawOval((int)(_startPosX + _warmlyShipWidth * 3 / 5 + 5), (int)_startPosY + 25, 20, 20);
|
||||||
g2d.drawOval((int)(_startPosX + _warmlyShipWidth * 2 / 5 + 2.5f), (int)_startPosY + 25, 20, 20);
|
g2d.drawOval((int)(_startPosX + _warmlyShipWidth * 2 / 5 + 2.5f), (int)_startPosY + 25, 20, 20);
|
||||||
dd.DrawningDeck(_startPosX, _startPosY, _warmlyShipWidth, g2d, warmlyShip.GetBodyColor());
|
idd.DrawningDeck(_startPosX, _startPosY, _warmlyShipWidth, g2d, warmlyShip.GetBodyColor());
|
||||||
}
|
}
|
||||||
|
|
||||||
//Изменение границ отрисовки
|
//Изменение границ отрисовки
|
||||||
|
133
FormMap.form
Normal file
133
FormMap.form
Normal file
@ -0,0 +1,133 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormMap">
|
||||||
|
<grid id="27dc6" binding="JPanel" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||||
|
<margin top="0" left="0" bottom="0" right="0"/>
|
||||||
|
<constraints>
|
||||||
|
<xy x="20" y="20" width="500" height="400"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children>
|
||||||
|
<grid id="bd11a" binding="Mainpanel" layout-manager="GridLayoutManager" row-count="4" column-count="6" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||||
|
<margin top="0" left="0" bottom="0" right="0"/>
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<opaque value="true"/>
|
||||||
|
<preferredSize width="800" height="600"/>
|
||||||
|
</properties>
|
||||||
|
<border type="none"/>
|
||||||
|
<children>
|
||||||
|
<component id="aa94c" class="javax.swing.JButton" binding="buttonDown">
|
||||||
|
<constraints>
|
||||||
|
<grid row="2" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||||
|
<minimum-size width="30" height="30"/>
|
||||||
|
<preferred-size width="30" height="30"/>
|
||||||
|
<maximum-size width="30" height="30"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value=""/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="579c4" class="javax.swing.JButton" binding="buttonRight">
|
||||||
|
<constraints>
|
||||||
|
<grid row="2" column="5" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||||
|
<minimum-size width="30" height="30"/>
|
||||||
|
<preferred-size width="30" height="30"/>
|
||||||
|
<maximum-size width="30" height="30"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<horizontalAlignment value="0"/>
|
||||||
|
<text value=""/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="43c16" class="javax.swing.JButton" binding="buttonUp">
|
||||||
|
<constraints>
|
||||||
|
<grid row="1" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||||
|
<minimum-size width="30" height="30"/>
|
||||||
|
<preferred-size width="30" height="30"/>
|
||||||
|
<maximum-size width="30" height="30"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value=""/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<toolbar id="595a9" binding="statusStrip">
|
||||||
|
<constraints>
|
||||||
|
<grid row="3" column="0" row-span="1" col-span="6" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||||
|
<minimum-size width="-1" height="20"/>
|
||||||
|
<preferred-size width="-1" height="20"/>
|
||||||
|
<maximum-size width="-1" height="20"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<enabled value="false"/>
|
||||||
|
</properties>
|
||||||
|
<border type="none"/>
|
||||||
|
<children/>
|
||||||
|
</toolbar>
|
||||||
|
<component id="769a2" class="javax.swing.JButton" binding="buttonCreate">
|
||||||
|
<constraints>
|
||||||
|
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||||
|
<preferred-size width="122" height="30"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Создать"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="b0694" class="javax.swing.JButton" binding="buttonLeft">
|
||||||
|
<constraints>
|
||||||
|
<grid row="2" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||||
|
<minimum-size width="30" height="30"/>
|
||||||
|
<preferred-size width="30" height="30"/>
|
||||||
|
<maximum-size width="30" height="30"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value=""/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<grid id="55dd2" binding="GraphicsOutput" layout-manager="FlowLayout" hgap="5" vgap="5" flow-align="1">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="0" row-span="1" col-span="6" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children/>
|
||||||
|
</grid>
|
||||||
|
<component id="b8384" class="javax.swing.JButton" binding="buttonCreateModif">
|
||||||
|
<constraints>
|
||||||
|
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||||
|
<preferred-size width="122" height="30"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Модификация"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="a36c3" class="javax.swing.JComboBox" binding="comboBoxSelectorMap">
|
||||||
|
<constraints>
|
||||||
|
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
</component>
|
||||||
|
<hspacer id="c0027">
|
||||||
|
<constraints>
|
||||||
|
<grid row="2" column="1" row-span="1" col-span="2" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
</hspacer>
|
||||||
|
<hspacer id="7e42b">
|
||||||
|
<constraints>
|
||||||
|
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
</hspacer>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
</form>
|
159
FormMap.java
Normal file
159
FormMap.java
Normal file
@ -0,0 +1,159 @@
|
|||||||
|
import javax.imageio.ImageIO;
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.*;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class FormMap extends JFrame {
|
||||||
|
|
||||||
|
private AbstractMap _abstractMap;
|
||||||
|
|
||||||
|
private JPanel JPanel;
|
||||||
|
private JButton buttonDown;
|
||||||
|
private JButton buttonRight;
|
||||||
|
private JButton buttonUp;
|
||||||
|
private JToolBar statusStrip;
|
||||||
|
private JButton buttonCreate;
|
||||||
|
private JButton buttonLeft;
|
||||||
|
private JPanel GraphicsOutput;
|
||||||
|
private JButton buttonCreateModif;
|
||||||
|
public JPanel Mainpanel;
|
||||||
|
private JComboBox comboBoxSelectorMap;
|
||||||
|
private JLabel JLabelSpeed = new JLabel();
|
||||||
|
private JLabel JLabelWeight = new JLabel();
|
||||||
|
private JLabel JLabelColor = new JLabel();
|
||||||
|
|
||||||
|
private void SetData(DrawingShip ship)
|
||||||
|
{
|
||||||
|
Random random = new Random();
|
||||||
|
GraphicsOutput.removeAll();
|
||||||
|
ship.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100), GraphicsOutput.getWidth(), GraphicsOutput.getHeight());
|
||||||
|
JLabelSpeed.setText("Cкорость: " + ship.GetWarmlyShip().GetSpeed() + " ");
|
||||||
|
JLabelWeight.setText("Вес: " + ship.GetWarmlyShip().GetWeight() + " ");
|
||||||
|
JLabelColor.setText(("Цвет: " + ship.GetWarmlyShip().GetBodyColor() + " "));
|
||||||
|
JLabel imageOfShip = new JLabel();
|
||||||
|
imageOfShip.setPreferredSize(GraphicsOutput.getSize());
|
||||||
|
imageOfShip.setMinimumSize(new Dimension(1, 1));
|
||||||
|
imageOfShip.setIcon(new ImageIcon(_abstractMap.CreateMap(GraphicsOutput.getWidth(), GraphicsOutput.getHeight(), new DrawningObjectShip(ship))));
|
||||||
|
GraphicsOutput.add(imageOfShip,BorderLayout.CENTER);
|
||||||
|
GraphicsOutput.revalidate();
|
||||||
|
GraphicsOutput.repaint();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonMove_Click(String name)
|
||||||
|
{
|
||||||
|
if (_abstractMap == null) return;
|
||||||
|
Direction direction = Direction.None;
|
||||||
|
switch (name)
|
||||||
|
{
|
||||||
|
case "buttonLeft":
|
||||||
|
direction = Direction.Left;
|
||||||
|
break;
|
||||||
|
case "buttonUp":
|
||||||
|
direction = Direction.Up;
|
||||||
|
break;
|
||||||
|
case "buttonRight":
|
||||||
|
direction = Direction.Right;
|
||||||
|
break;
|
||||||
|
case "buttonDown":
|
||||||
|
direction = Direction.Down;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
GraphicsOutput.removeAll();
|
||||||
|
JLabel imageOfShip = new JLabel();
|
||||||
|
imageOfShip.setPreferredSize(GraphicsOutput.getSize());
|
||||||
|
imageOfShip.setMinimumSize(new Dimension(1, 1));
|
||||||
|
imageOfShip.setIcon(new ImageIcon(_abstractMap.MoveObject(direction)));
|
||||||
|
GraphicsOutput.add(imageOfShip,BorderLayout.CENTER);
|
||||||
|
GraphicsOutput.revalidate();
|
||||||
|
GraphicsOutput.repaint();
|
||||||
|
}
|
||||||
|
|
||||||
|
public FormMap() {
|
||||||
|
Box LabelBox = Box.createHorizontalBox();
|
||||||
|
LabelBox.setMinimumSize(new Dimension(1, 20));
|
||||||
|
LabelBox.add(JLabelSpeed);
|
||||||
|
LabelBox.add(JLabelWeight);
|
||||||
|
LabelBox.add(JLabelColor);
|
||||||
|
statusStrip.add(LabelBox);
|
||||||
|
comboBoxSelectorMap.addItem("Простая карта");
|
||||||
|
comboBoxSelectorMap.addItem("Вторая карта");
|
||||||
|
comboBoxSelectorMap.addItem("Последняя карта");
|
||||||
|
|
||||||
|
_abstractMap = new SimpleMap();
|
||||||
|
|
||||||
|
try {
|
||||||
|
Image img = ImageIO.read(FormShip.class.getResource("/Images/totop.png"));
|
||||||
|
buttonUp.setIcon(new ImageIcon(img));
|
||||||
|
img = ImageIO.read(FormShip.class.getResource("/Images/toleft.png"));
|
||||||
|
buttonLeft.setIcon(new ImageIcon(img));
|
||||||
|
img = ImageIO.read(FormShip.class.getResource("/Images/todown.png"));
|
||||||
|
buttonDown.setIcon(new ImageIcon(img));
|
||||||
|
img = ImageIO.read(FormShip.class.getResource("/Images/toright.png"));
|
||||||
|
buttonRight.setIcon(new ImageIcon(img));
|
||||||
|
} catch (Exception ex) {
|
||||||
|
System.out.println(ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
buttonCreate.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
Random random = new Random();
|
||||||
|
var ship = new DrawingShip(random.nextInt(100, 300), random.nextInt(1000, 2000), new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256)));
|
||||||
|
SetData(ship);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
buttonUp.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
ButtonMove_Click("buttonUp");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
buttonLeft.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
ButtonMove_Click("buttonLeft");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
buttonDown.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
ButtonMove_Click("buttonDown");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
buttonRight.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
ButtonMove_Click("buttonRight");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
buttonCreateModif.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
Random random = new Random();
|
||||||
|
var ship = new DrawningMotorShip(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.nextBoolean(), random.nextBoolean());
|
||||||
|
SetData(ship);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
comboBoxSelectorMap.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
switch (comboBoxSelectorMap.getSelectedItem().toString())
|
||||||
|
{
|
||||||
|
case "Простая карта":
|
||||||
|
_abstractMap = new SimpleMap();
|
||||||
|
break;
|
||||||
|
case "Вторая карта":
|
||||||
|
_abstractMap = new SecondMap();
|
||||||
|
break;
|
||||||
|
case "Последняя карта":
|
||||||
|
_abstractMap = new LastMap();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
6
IDrawningDeck.java
Normal file
6
IDrawningDeck.java
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public interface IDrawningDeck {
|
||||||
|
void SetDeckCount(int count);
|
||||||
|
void DrawningDeck(float _startPosX, float _startPosY, int _warmlyShipWidth, Graphics2D g2d, Color bodyColor);
|
||||||
|
}
|
56
LastMap.java
Normal file
56
LastMap.java
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class LastMap extends AbstractMap{
|
||||||
|
|
||||||
|
private Color barrierColor = Color.RED;
|
||||||
|
private Color roadColor = Color.GREEN;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void DrawBarrierPart(Graphics g, int i, int j)
|
||||||
|
{
|
||||||
|
Graphics2D g2d = (Graphics2D) g;
|
||||||
|
g2d.setPaint(barrierColor);
|
||||||
|
g2d.fillRect((int)Math.floor(j * _size_x), (int)Math.floor(i * _size_y),(int)Math.ceil(_size_x), (int)Math.ceil(_size_y));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void DrawRoadPart(Graphics g, int i, int j)
|
||||||
|
{
|
||||||
|
Graphics2D g2d = (Graphics2D) g;
|
||||||
|
g2d.setPaint(roadColor);
|
||||||
|
g2d.fillRect((int)Math.floor(j * _size_x), (int)Math.floor(i * _size_y),(int)Math.ceil(_size_x), (int)Math.ceil(_size_y));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void GenerateMap()
|
||||||
|
{
|
||||||
|
_map = new int[100][100];
|
||||||
|
_size_x = (float)_width / _map.length;
|
||||||
|
_size_y = (float)_height / _map[0].length;
|
||||||
|
int counter = 0;
|
||||||
|
for (int i = 0; i < _map.length; ++i)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < _map[0].length; ++j)
|
||||||
|
{
|
||||||
|
_map[i][j] = _freeRoad;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (counter < 45)
|
||||||
|
{
|
||||||
|
int x = _random.nextInt(0, 100);
|
||||||
|
int y = _random.nextInt(0, 100);
|
||||||
|
if (_map[x][y] == _freeRoad)
|
||||||
|
{
|
||||||
|
_map[x][y] = _barrier;
|
||||||
|
if (x > 0 && y > 0 && x < _map.length - 1 && y < _map[0].length - 1)
|
||||||
|
{
|
||||||
|
_map[x - 1][y] = _barrier;
|
||||||
|
_map[x + 1][y] = _barrier;
|
||||||
|
_map[x][y - 1] = _barrier;
|
||||||
|
_map[x][y + 1] = _barrier;
|
||||||
|
}
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -3,7 +3,7 @@ import javax.swing.*;
|
|||||||
public class Main {
|
public class Main {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
JFrame frame = new JFrame("Hard №1");
|
JFrame frame = new JFrame("Hard №1");
|
||||||
frame.setContentPane(new FormShip().Mainpanel);
|
frame.setContentPane(new FormMap().Mainpanel);
|
||||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
frame.setLocation(500, 200);
|
frame.setLocation(500, 200);
|
||||||
frame.pack();
|
frame.pack();
|
||||||
|
58
SecondMap.java
Normal file
58
SecondMap.java
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class SecondMap extends AbstractMap{
|
||||||
|
|
||||||
|
private Color barrierColor = Color.ORANGE;
|
||||||
|
private Color roadColor = Color.BLACK;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void DrawBarrierPart(Graphics g, int i, int j)
|
||||||
|
{
|
||||||
|
Graphics2D g2d = (Graphics2D) g;
|
||||||
|
g2d.setPaint(barrierColor);
|
||||||
|
g2d.fillRect((int)Math.floor(j * _size_x), (int)Math.floor(i * _size_y),(int)Math.ceil(_size_x), (int)Math.ceil(_size_y));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void DrawRoadPart(Graphics g, int i, int j)
|
||||||
|
{
|
||||||
|
Graphics2D g2d = (Graphics2D) g;
|
||||||
|
g2d.setPaint(roadColor);
|
||||||
|
g2d.fillRect((int)Math.floor(j * _size_x), (int)Math.floor(i * _size_y),(int)Math.ceil(_size_x), (int)Math.ceil(_size_y));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void GenerateMap()
|
||||||
|
{
|
||||||
|
_map = new int[100][100];
|
||||||
|
_size_x = (float)_width / _map.length;
|
||||||
|
_size_y = (float)_height / _map[0].length;
|
||||||
|
int counter = 0;
|
||||||
|
for (int i = 0; i < _map.length; ++i)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < _map[0].length; ++j)
|
||||||
|
{
|
||||||
|
_map[i][j] = _freeRoad;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (int i = 0; i < _map.length; ++i)
|
||||||
|
{
|
||||||
|
_map[i][_map[0].length / 2] = _barrier;
|
||||||
|
_map[i][_map[0].length - 1] = _barrier;
|
||||||
|
}
|
||||||
|
for (int j = 0; j < _map[0].length; ++j)
|
||||||
|
{
|
||||||
|
_map[_map.length - 1][j] = _barrier;
|
||||||
|
}
|
||||||
|
while (counter < 45)
|
||||||
|
{
|
||||||
|
int x = _random.nextInt(0, 100);
|
||||||
|
int y = _random.nextInt(0, 100);
|
||||||
|
if (_map[x][y] == _freeRoad)
|
||||||
|
{
|
||||||
|
_map[x][y] = _barrier;
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
49
SimpleMap.java
Normal file
49
SimpleMap.java
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class SimpleMap extends AbstractMap{
|
||||||
|
|
||||||
|
private Color barrierColor = Color.BLACK;
|
||||||
|
private Color roadColor = Color.GRAY;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void GenerateMap()
|
||||||
|
{
|
||||||
|
_map = new int[100][100];
|
||||||
|
_size_x = (float)_width / _map.length;
|
||||||
|
_size_y = (float)_height / _map[0].length;
|
||||||
|
int counter = 0;
|
||||||
|
for (int i = 0; i < _map.length; ++i)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < _map[0].length; ++j)
|
||||||
|
{
|
||||||
|
_map[i][j] = _freeRoad;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (counter < 50)
|
||||||
|
{
|
||||||
|
int x = _random.nextInt(0, 100);
|
||||||
|
int y = _random.nextInt(0, 100);
|
||||||
|
if (_map[x][y] == _freeRoad)
|
||||||
|
{
|
||||||
|
_map[x][y] = _barrier;
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
protected void DrawBarrierPart(Graphics g, int i, int j)
|
||||||
|
{
|
||||||
|
Graphics2D g2d = (Graphics2D) g;
|
||||||
|
g2d.setPaint(barrierColor);
|
||||||
|
g2d.fillRect((int)Math.floor(j * _size_x), (int)Math.floor(i * _size_y),(int)Math.ceil(_size_x), (int)Math.ceil(_size_y));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void DrawRoadPart(Graphics g, int i, int j)
|
||||||
|
{
|
||||||
|
Graphics2D g2d = (Graphics2D) g;
|
||||||
|
g2d.setPaint(roadColor);
|
||||||
|
g2d.fillRect((int)Math.floor(j * _size_x), (int)Math.floor(i * _size_y),(int)Math.ceil(_size_x), (int)Math.ceil(_size_y));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user