Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
f22e833972 | |||
ba8046949c | |||
b88d9dd7f7 | |||
565bfd8dd7 | |||
e65faf2146 | |||
489964eb09 |
5
.idea/AircraftCarrier_Hard.iml
generated
5
.idea/AircraftCarrier_Hard.iml
generated
@ -1,9 +1,12 @@
|
||||
<?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" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/out" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
|
8
.idea/compiler.xml
generated
Normal file
8
.idea/compiler.xml
generated
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="JavacSettings">
|
||||
<option name="ADDITIONAL_OPTIONS_OVERRIDE">
|
||||
<module name="AircraftCarrier_Hard" options="--add-modules java.datatransfer,java.desktop --add-exports java.datatransfer/java.awt=ALL-UNNAMED" />
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11.0.5" project-jdk-type="JavaSDK">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_19" default="true" project-jdk-name="openjdk-19" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/../../../ирино, не трогат/!/!/!/!/RPP/ProjectAircraftCarrierHard/out" />
|
||||
</component>
|
||||
</project>
|
155
src/AbstractMap.java
Normal file
155
src/AbstractMap.java
Normal file
@ -0,0 +1,155 @@
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.Random;
|
||||
|
||||
public abstract class AbstractMap {
|
||||
private IDrawingObject _drawingObject = null;
|
||||
protected int[][] _map = null;
|
||||
protected int _width;
|
||||
protected int _height;
|
||||
protected float _size_x;
|
||||
protected float _size_y;
|
||||
protected final Random _random = new Random();
|
||||
protected final int _freeRoad = 0;
|
||||
protected final int _barrier = 1;
|
||||
|
||||
public BufferedImage CreateMap(int width, int height, IDrawingObject drawningObject)
|
||||
{
|
||||
_width = width;
|
||||
_height = height;
|
||||
_drawingObject = drawningObject;
|
||||
GenerateMap();
|
||||
while (!SetObjectOnMap())
|
||||
{
|
||||
GenerateMap();
|
||||
}
|
||||
return DrawMapWithObject();
|
||||
}
|
||||
|
||||
public BufferedImage MoveObject(Direction direction)
|
||||
{
|
||||
if (_drawingObject != null)
|
||||
{
|
||||
if (true)
|
||||
{
|
||||
_drawingObject.MoveObject(direction);
|
||||
}
|
||||
float[] cortege = _drawingObject.GetCurrentPosition();
|
||||
if (Check(cortege[0],cortege[1],cortege[2],cortege[3])!= 0)
|
||||
{
|
||||
_drawingObject.MoveObject(GetOpositDirection(direction));
|
||||
}
|
||||
return DrawMapWithObject();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private Direction GetOpositDirection(Direction dir)
|
||||
{
|
||||
switch (dir)
|
||||
{
|
||||
case None:
|
||||
return Direction.None;
|
||||
case Up:
|
||||
return Direction.Down;
|
||||
case Down:
|
||||
return Direction.Up;
|
||||
case Left:
|
||||
return Direction.Right;
|
||||
case Right:
|
||||
return Direction.Left;
|
||||
}
|
||||
return Direction.None;
|
||||
}
|
||||
|
||||
private boolean SetObjectOnMap()
|
||||
{
|
||||
if (_drawingObject == null || _map == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
int x = _random.nextInt(0, 10);
|
||||
int y = _random.nextInt(0, 10);
|
||||
_drawingObject.SetObject(x, y, _width, _height);
|
||||
float[] cortege = _drawingObject.GetCurrentPosition();
|
||||
float nowX = cortege[0];
|
||||
float nowY = cortege[1];
|
||||
float lenX = cortege[2]-cortege[0];
|
||||
float lenY = cortege[3] - cortege[1];
|
||||
while (Check(nowX, nowY, nowX + lenX, nowY + lenY) != 2)
|
||||
{
|
||||
int result;
|
||||
do
|
||||
{
|
||||
result = Check(nowX, nowY, nowX + lenX, nowY + lenY);
|
||||
if (result == 0)
|
||||
{
|
||||
_drawingObject.SetObject((int)nowX, (int)nowY, _width, _height);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
nowX += _size_x;
|
||||
}
|
||||
} while (result != 2);
|
||||
nowX = x;
|
||||
nowY += _size_y;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private int Check(float Left, float Right, float Top, float Bottom)
|
||||
{
|
||||
int startX = (int)(Left / _size_x);
|
||||
int startY = (int)(Right / _size_y);
|
||||
int endX = (int)(Top / _size_x);
|
||||
int endY = (int)(Bottom / _size_y);
|
||||
if (startX < 0 || startY < 0 || endX >= _map[0].length || endY >= _map.length)
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
for (int i = startX; i <= endX; i++)
|
||||
{
|
||||
for (int j = startY; j <= endY; j++)
|
||||
{
|
||||
if (_map[i][j] == _barrier)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private BufferedImage DrawMapWithObject()
|
||||
{
|
||||
BufferedImage bmp = new BufferedImage(_width,_height,BufferedImage.TYPE_INT_RGB);
|
||||
if (_drawingObject == null || _map == null)
|
||||
{
|
||||
return bmp;
|
||||
}
|
||||
Graphics gr = bmp.getGraphics();
|
||||
for (int i = 0; i < _map.length; ++i)
|
||||
{
|
||||
for (int j = 0; j < _map.length; ++j)
|
||||
{
|
||||
if (_map[i][j] == _freeRoad)
|
||||
{
|
||||
DrawRoadPart(gr, i, j);
|
||||
}
|
||||
else if (_map[i][j] == _barrier)
|
||||
{
|
||||
DrawBarrierPart(gr, i, j);
|
||||
}
|
||||
}
|
||||
}
|
||||
_drawingObject.DrawningObject(gr);
|
||||
return bmp;
|
||||
}
|
||||
|
||||
protected abstract void GenerateMap();
|
||||
protected abstract void DrawRoadPart(Graphics g, int i, int j);
|
||||
protected abstract void DrawBarrierPart(Graphics g, int i, int j);
|
||||
}
|
||||
|
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,4 +1,5 @@
|
||||
public enum Direction {
|
||||
None,
|
||||
Up,
|
||||
Down,
|
||||
Left,
|
||||
|
82
src/DrawingAircraftCarrier.java
Normal file
82
src/DrawingAircraftCarrier.java
Normal file
@ -0,0 +1,82 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawingAircraftCarrier extends DrawingWarship{
|
||||
|
||||
public DrawingAircraftCarrier(int speed, float weight, Color bodyColor, Color dopColor, boolean bodyKit, boolean cabin, boolean superEngine)
|
||||
{
|
||||
super(speed, weight, bodyColor, 114, 40);
|
||||
Warship = new EntityAircraftCarrier(speed, weight, bodyColor, dopColor, bodyKit, cabin, superEngine);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void DrawTransport(Graphics gr){
|
||||
if(!(Warship instanceof EntityAircraftCarrier))
|
||||
{
|
||||
return;
|
||||
}
|
||||
Graphics2D g2 = (Graphics2D) gr;
|
||||
EntityAircraftCarrier aircraftCarrier = (EntityAircraftCarrier) Warship;
|
||||
|
||||
if (aircraftCarrier.GetBodyKit())
|
||||
{
|
||||
//боковая площадка
|
||||
int[] pointXArea = {_startPosX + 94, _startPosX + 74, _startPosX + 24, _startPosX + 4};
|
||||
int[] pointYArea = {_startPosY + 40, _startPosY + 60, _startPosY + 60, _startPosY + 40};
|
||||
g2.setColor(Warship.GetBodyColor());
|
||||
g2.fillPolygon(pointXArea, pointYArea, 4);
|
||||
g2.setColor(Color.BLACK);
|
||||
g2.drawPolygon(pointXArea, pointYArea, 4);
|
||||
|
||||
//полоса
|
||||
int[] pointXLine = {_startPosX + 4, _startPosX + 15, _startPosX + 74, _startPosX + 59};
|
||||
int[] pointYLine = {_startPosY, _startPosY, _startPosY + 60, _startPosY + 60};
|
||||
g2.setColor(Color.GRAY);
|
||||
g2.fillPolygon(pointXLine, pointYLine, 4);
|
||||
g2.setColor(Color.BLACK);
|
||||
g2.drawPolygon(pointXLine, pointYLine, 4);
|
||||
}
|
||||
|
||||
if (aircraftCarrier.GetSuperEngine())
|
||||
{
|
||||
g2.setColor(Color.RED);
|
||||
g2.fillOval(_startPosX, _startPosY, 10, 10);
|
||||
g2.setColor(Color.BLACK);
|
||||
g2.drawOval(_startPosX, _startPosY, 10, 10);
|
||||
|
||||
g2.setColor(Color.RED);
|
||||
g2.fillOval(_startPosX, _startPosY + 10, 10, 10);
|
||||
g2.setColor(Color.BLACK);
|
||||
g2.drawOval(_startPosX, _startPosY + 10, 10, 10);
|
||||
|
||||
g2.setColor(Color.RED);
|
||||
g2.fillOval(_startPosX, _startPosY + 18, 10, 10);
|
||||
g2.setColor(Color.BLACK);
|
||||
g2.drawOval(_startPosX, _startPosY + 18, 10, 10);
|
||||
|
||||
g2.setColor(Color.RED);
|
||||
g2.fillOval(_startPosX, _startPosY + 30, 10, 10);
|
||||
g2.setColor(Color.BLACK);
|
||||
g2.drawOval(_startPosX, _startPosY + 30, 10, 10);
|
||||
}
|
||||
|
||||
super.DrawTransport(g2);
|
||||
|
||||
if (aircraftCarrier.GetCabin())
|
||||
{
|
||||
g2.setColor(Color.GRAY);
|
||||
g2.fillOval(_startPosX + 80, _startPosY + 13, 10, 14);
|
||||
g2.setColor(Color.BLACK);
|
||||
g2.drawOval(_startPosX + 80, _startPosY + 13, 10, 14);
|
||||
|
||||
g2.setColor(Color.GRAY);
|
||||
g2.fillOval(_startPosX + 90, _startPosY + 13, 10, 14);
|
||||
g2.setColor(Color.BLACK);
|
||||
g2.drawOval(_startPosX + 90, _startPosY + 13, 10, 14);
|
||||
|
||||
g2.setColor(Color.GRAY);
|
||||
g2.fillRect(_startPosX + 85, _startPosY + 13, 10, 14);
|
||||
g2.setColor(Color.BLACK);
|
||||
g2.drawRect(_startPosX + 85, _startPosY + 13, 10, 14);
|
||||
}
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,22 +0,0 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawingComponents extends JComponent {
|
||||
public DrawingWarship warship;
|
||||
public DrawingComponents(){
|
||||
super();
|
||||
}
|
||||
public void SetDrawingWarship(DrawingWarship warship){
|
||||
this.warship = warship;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paintComponent(Graphics g){
|
||||
super.paintComponent(g);
|
||||
Graphics2D g2 = (Graphics2D) g;
|
||||
if(warship != null){
|
||||
warship.DrawTransport(g2);
|
||||
}
|
||||
repaint();
|
||||
}
|
||||
}
|
71
src/DrawingMap.java
Normal file
71
src/DrawingMap.java
Normal file
@ -0,0 +1,71 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.Random;
|
||||
|
||||
public class DrawingMap extends JPanel{
|
||||
private final FormMap Map;
|
||||
private AbstractMap _abstractMap;
|
||||
BufferedImage bufferedImage;
|
||||
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();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.drawImage(bufferedImage,0,0,null);
|
||||
}
|
||||
|
||||
private void SetData(DrawingWarship warship) {
|
||||
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 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 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);
|
||||
}
|
||||
}
|
||||
|
||||
public void ComboBoxSelectorMapAction(String name){
|
||||
switch (name){
|
||||
case "Простая карта":
|
||||
_abstractMap = new SimpleMap();
|
||||
break;
|
||||
case "Вторая карта":
|
||||
_abstractMap = new LineMap();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void DrawMap(Graphics g){
|
||||
g.drawImage(bufferedImage,0,0,null);
|
||||
}
|
||||
}
|
37
src/DrawingObjectWarship.java
Normal file
37
src/DrawingObjectWarship.java
Normal file
@ -0,0 +1,37 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawingObjectWarship implements IDrawingObject {
|
||||
private DrawingWarship _warship = null;
|
||||
|
||||
public DrawingObjectWarship(DrawingWarship warship)
|
||||
{
|
||||
_warship = warship;
|
||||
}
|
||||
|
||||
public float Step(){
|
||||
if(_warship !=null && _warship.Warship != null)
|
||||
return _warship.Warship.Step;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void SetObject(int x, int y, int width, int height) {
|
||||
_warship.SetPosition(x, y, width, height);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void MoveObject(Direction direction) {
|
||||
_warship.MoveTransport(direction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void DrawningObject(Graphics g) {
|
||||
_warship.DrawTransport(g);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float[] GetCurrentPosition() {
|
||||
if(_warship != null) return _warship.GetCurrentPosition();
|
||||
return null;
|
||||
}
|
||||
}
|
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);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,25 +1,32 @@
|
||||
import java.awt.*;
|
||||
import java.util.Random;
|
||||
public class DrawingWarship {
|
||||
private EntityWarship Warship;
|
||||
protected EntityWarship Warship;
|
||||
public EntityWarship GetWarship(){return Warship;}
|
||||
public DrawingBlocks Blocks;
|
||||
|
||||
private int _startPosX;
|
||||
private int _startPosY;
|
||||
protected int _startPosX;
|
||||
protected int _startPosY;
|
||||
|
||||
private Integer _pictureWidth = null;
|
||||
private Integer _pictureHeight = null;
|
||||
|
||||
private final int _warshipWidth = 114;
|
||||
private final int _warshipHeight = 40;
|
||||
private int _warshipWidth = 114;
|
||||
private int _warshipHeight = 40;
|
||||
|
||||
public void Init(int speed, float weight, Color bodyColor)
|
||||
public DrawingWarship(int speed, float weight, Color bodyColor)
|
||||
{
|
||||
Warship = new EntityWarship();
|
||||
Warship.Init(speed, weight, bodyColor);
|
||||
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)
|
||||
@ -32,6 +39,7 @@ public class DrawingWarship {
|
||||
_pictureHeight = height;
|
||||
}
|
||||
}
|
||||
|
||||
public void MoveTransport(Direction direction)
|
||||
{
|
||||
if (_pictureWidth == null || _pictureHeight == null)
|
||||
@ -70,11 +78,13 @@ public class DrawingWarship {
|
||||
break;
|
||||
}
|
||||
}
|
||||
public void DrawTransport(Graphics2D g2){
|
||||
|
||||
public void DrawTransport(Graphics gr){
|
||||
if (_startPosX < 0 || _startPosY < 0 || _pictureHeight == null || _pictureWidth == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Graphics2D g2 = (Graphics2D) gr;
|
||||
//главная палуба
|
||||
int[] pointXWarship = {_startPosX + 4, _startPosX + 94, _startPosX + 114, _startPosX + 94, _startPosX + 4};
|
||||
int[] pointYWarship = {_startPosY, _startPosY, _startPosY + 20, _startPosY + 40, _startPosY + 40};
|
||||
@ -107,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;
|
||||
@ -135,4 +136,13 @@ public class DrawingWarship {
|
||||
_startPosY = _pictureHeight - _warshipHeight;
|
||||
}
|
||||
}
|
||||
|
||||
public float[] GetCurrentPosition(){
|
||||
float[] cortege = new float[4];
|
||||
cortege[0] = _startPosX;
|
||||
cortege[1] =_startPosY;
|
||||
cortege[2] = _startPosX + _warshipWidth;
|
||||
cortege[3] = _startPosY + _warshipHeight;
|
||||
return cortege;
|
||||
}
|
||||
}
|
||||
|
24
src/EntityAircraftCarrier.java
Normal file
24
src/EntityAircraftCarrier.java
Normal file
@ -0,0 +1,24 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class EntityAircraftCarrier extends EntityWarship {
|
||||
private Color DopColor;
|
||||
public Color GetDopColor(){return DopColor;}
|
||||
|
||||
private boolean BodyKit;
|
||||
public boolean GetBodyKit(){return BodyKit;}
|
||||
|
||||
private boolean Cabin;
|
||||
public boolean GetCabin(){return Cabin;}
|
||||
|
||||
private boolean SuperEngine;
|
||||
public boolean GetSuperEngine(){return SuperEngine;}
|
||||
|
||||
public EntityAircraftCarrier(int speed, float weight, Color bodyColor, Color dopColor, boolean bodyKit, boolean cabin, boolean superEngine)
|
||||
{
|
||||
super(speed, weight, bodyColor);
|
||||
DopColor = dopColor;
|
||||
BodyKit = bodyKit;
|
||||
Cabin = cabin;
|
||||
SuperEngine = superEngine;
|
||||
}
|
||||
}
|
@ -11,11 +11,12 @@ public class EntityWarship {
|
||||
public Color GetBodyColor (){return BodyColor;}
|
||||
|
||||
public float Step;
|
||||
public void Init(int speed, float weight, Color bodyColor)
|
||||
|
||||
public EntityWarship(int speed, float weight, Color bodyColor)
|
||||
{
|
||||
Random rnd = new Random();
|
||||
Speed = speed <= 0 ? rnd.nextInt(100) + 50 : speed;
|
||||
Weight = weight <= 0 ? rnd.nextInt(30)+40 : weight;
|
||||
Speed = speed <= 0 ? rnd.nextInt(50, 150) : speed;
|
||||
Weight = weight <= 0 ? rnd.nextInt(40, 70) : weight;
|
||||
BodyColor= bodyColor;
|
||||
Step = Speed * 100 / Weight;
|
||||
}
|
||||
|
137
src/FormMap.form
Normal file
137
src/FormMap.form
Normal file
@ -0,0 +1,137 @@
|
||||
<?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="mainPanel" layout-manager="GridLayoutManager" row-count="3" 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="897" height="504"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<toolbar id="ced8" binding="toolBar">
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="-1" height="20"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="7c17c" class="javax.swing.JLabel" binding="toolBarLabelSpeed">
|
||||
<constraints/>
|
||||
<properties>
|
||||
<text value="Speed"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="a7229" class="javax.swing.JLabel" binding="toolBarLabelWieght">
|
||||
<constraints/>
|
||||
<properties>
|
||||
<text value="Weight"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="7c70" class="javax.swing.JLabel" binding="toolBarLabelColor">
|
||||
<constraints/>
|
||||
<properties>
|
||||
<text value="Color"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</toolbar>
|
||||
<grid id="3b625" binding="drawPanel" 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="2" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="c54f8" class="javax.swing.JButton" binding="buttonCreate">
|
||||
<constraints>
|
||||
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Create"/>
|
||||
</properties>
|
||||
</component>
|
||||
<hspacer id="a1d54">
|
||||
<constraints>
|
||||
<grid row="3" 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>
|
||||
<vspacer id="4c365">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
<component id="aaec9" class="javax.swing.JButton" binding="buttonCreateModif">
|
||||
<constraints>
|
||||
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Modificarion"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="c7660" class="javax.swing.JButton" binding="buttonRight">
|
||||
<constraints>
|
||||
<grid row="3" 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>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="e0470" class="javax.swing.JButton" binding="buttonDown">
|
||||
<constraints>
|
||||
<grid row="3" 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="a6de2" class="javax.swing.JButton" binding="buttonLeft">
|
||||
<constraints>
|
||||
<grid row="3" 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>
|
||||
<component id="633e1" class="javax.swing.JButton" binding="buttonUp">
|
||||
<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="e1523" class="javax.swing.JComboBox" binding="ComboBoxSelectorMap">
|
||||
<constraints>
|
||||
<grid row="0" column="3" row-span="1" col-span="3" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<model>
|
||||
<item value="Простая карта"/>
|
||||
<item value="Карта-Линии"/>
|
||||
</model>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
84
src/FormMap.java
Normal file
84
src/FormMap.java
Normal file
@ -0,0 +1,84 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.Objects;
|
||||
|
||||
public class FormMap extends JFrame{
|
||||
DrawingMap map = new DrawingMap(this, this.getWidth(), this.getHeight());
|
||||
private JPanel mainPanel;
|
||||
private JToolBar toolBar;
|
||||
public JLabel toolBarLabelSpeed;
|
||||
public JLabel toolBarLabelWieght;
|
||||
public JLabel toolBarLabelColor;
|
||||
private JButton buttonCreate;
|
||||
private JButton buttonCreateModif;
|
||||
private JButton buttonRight;
|
||||
private JButton buttonUp;
|
||||
private JButton buttonDown;
|
||||
private JButton buttonLeft;
|
||||
private JComboBox ComboBoxSelectorMap;
|
||||
private JPanel drawPanel;
|
||||
|
||||
public FormMap(){
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void InitializeComponent() {
|
||||
setContentPane(mainPanel);
|
||||
setTitle("Warship");
|
||||
setSize(900, 700);
|
||||
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
||||
setVisible(true);
|
||||
|
||||
Icon iconUp = new ImageIcon("src\\Images\\ArrowUp.jpg");
|
||||
buttonUp.setIcon(iconUp);
|
||||
Icon iconDown = new ImageIcon("src\\Images\\ArrowDown.jpg");
|
||||
buttonDown.setIcon(iconDown);
|
||||
Icon iconLeft = new ImageIcon("src\\Images\\ArrowLeft.jpg");
|
||||
buttonLeft.setIcon(iconLeft);
|
||||
Icon iconRight = new ImageIcon("src\\Images\\ArrowRight.jpg");
|
||||
buttonRight.setIcon(iconRight);
|
||||
|
||||
buttonCreate.addActionListener(e -> {
|
||||
map.CreateButtonAction();
|
||||
ReDraw();
|
||||
});
|
||||
|
||||
buttonCreateModif.addActionListener(e -> {
|
||||
map.CreateModifButtonAction();
|
||||
ReDraw();
|
||||
});
|
||||
|
||||
buttonUp.addActionListener(e -> {
|
||||
map.DirectionButtonAction(Direction.Up);
|
||||
ReDraw();
|
||||
});
|
||||
|
||||
buttonLeft.addActionListener(e -> {
|
||||
map.DirectionButtonAction(Direction.Left);
|
||||
ReDraw();
|
||||
});
|
||||
|
||||
buttonRight.addActionListener(e -> {
|
||||
map.DirectionButtonAction(Direction.Right);
|
||||
ReDraw();
|
||||
});
|
||||
|
||||
buttonDown.addActionListener(e -> {
|
||||
map.DirectionButtonAction(Direction.Down);
|
||||
ReDraw();
|
||||
});
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
@ -1,41 +1,101 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormWarship">
|
||||
<grid id="27dc6" binding="mainPanel" layout-manager="GridLayoutManager" row-count="4" column-count="5" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<grid id="27dc6" 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>
|
||||
<xy x="23" y="20" width="961" height="517"/>
|
||||
<xy x="49" y="20" width="935" height="482"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="80b72" class="javax.swing.JButton" binding="buttonCreate">
|
||||
<grid id="dfecd" binding="drawPanel" layout-manager="GridLayoutManager" row-count="3" 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="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
<grid row="0" column="0" row-span="3" col-span="6" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Create"/>
|
||||
</properties>
|
||||
</component>
|
||||
<hspacer id="3f3da">
|
||||
<constraints>
|
||||
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
<component id="32714" class="javax.swing.JButton" binding="buttonLeft">
|
||||
<constraints>
|
||||
<grid row="2" column="2" 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>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="80b72" class="javax.swing.JButton" binding="buttonCreate">
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Create"/>
|
||||
</properties>
|
||||
</component>
|
||||
<hspacer id="667bb">
|
||||
<constraints>
|
||||
<grid row="2" 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>
|
||||
<vspacer id="e8c93">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
<component id="34645" class="javax.swing.JButton" binding="buttonCreateModif">
|
||||
<constraints>
|
||||
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Modification"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="55933" 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>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="bb79e" 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>
|
||||
<enabled value="true"/>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="82cc1" 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>
|
||||
<component id="32714" 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>
|
||||
</children>
|
||||
</grid>
|
||||
<toolbar id="3697c" binding="toolBar">
|
||||
<constraints>
|
||||
<grid row="3" column="0" row-span="1" col-span="5" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<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">
|
||||
<preferred-size width="-1" height="20"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
@ -62,51 +122,6 @@
|
||||
</component>
|
||||
</children>
|
||||
</toolbar>
|
||||
<component id="55933" class="javax.swing.JButton" binding="buttonRight">
|
||||
<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="82cc1" class="javax.swing.JButton" binding="buttonUp">
|
||||
<constraints>
|
||||
<grid row="1" 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>
|
||||
<component id="bb79e" class="javax.swing.JButton" binding="buttonDown">
|
||||
<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>
|
||||
<enabled value="true"/>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<grid id="dfecd" binding="drawPanel" layout-manager="BorderLayout" hgap="0" vgap="0">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="5" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
||||
|
@ -4,12 +4,13 @@ import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ComponentAdapter;
|
||||
import java.awt.event.ComponentEvent;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.Random;
|
||||
|
||||
public class FormWarship extends JFrame {
|
||||
private DrawingWarship _warship;
|
||||
public DrawingComponents drawingComponents;
|
||||
private JPanel mainPanel;
|
||||
private JPanel drawPanel;
|
||||
private JButton buttonCreate;
|
||||
private JButton buttonLeft;
|
||||
private JButton buttonUp;
|
||||
@ -19,19 +20,37 @@ public class FormWarship extends JFrame {
|
||||
private JLabel toolBarLabelSpeed;
|
||||
private JLabel toolBarLabelWieght;
|
||||
private JLabel toolBarLabelColor;
|
||||
private JPanel drawPanel;
|
||||
private JButton buttonCreateModif;
|
||||
|
||||
public FormWarship(){
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void Draw(){
|
||||
drawingComponents.repaint();
|
||||
Graphics2D graphics = (Graphics2D) drawPanel.getGraphics();
|
||||
graphics.clearRect(0, 0, drawPanel.getWidth(), drawPanel.getHeight());
|
||||
drawPanel.paintComponents(graphics);
|
||||
_warship.DrawTransport(graphics);
|
||||
}
|
||||
|
||||
private void InitializeComponent(){
|
||||
private void SetData(){
|
||||
Random rnd = new Random();
|
||||
_warship.SetPosition(rnd.nextInt(10, 100), rnd.nextInt(10, 100), mainPanel.getWidth(), mainPanel.getHeight());
|
||||
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() {
|
||||
setContentPane(mainPanel);
|
||||
setTitle("Warship");
|
||||
setSize(900,700);
|
||||
setSize(900, 700);
|
||||
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
||||
setVisible(true);
|
||||
|
||||
@ -44,21 +63,28 @@ public class FormWarship extends JFrame {
|
||||
Icon iconRight = new ImageIcon("src\\Images\\ArrowRight.jpg");
|
||||
buttonRight.setIcon(iconRight);
|
||||
|
||||
drawingComponents = new DrawingComponents();
|
||||
drawPanel.add(drawingComponents);
|
||||
//кнопка добавления объекта
|
||||
buttonCreate.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Random rnd = new Random();
|
||||
_warship = new DrawingWarship();
|
||||
_warship.Init(rnd.nextInt(200) + 100, rnd.nextInt(1000) + 1000,
|
||||
new Color(rnd.nextInt(256),rnd.nextInt(256),rnd.nextInt(256)));
|
||||
_warship.SetPosition(rnd.nextInt(90) + 10, rnd.nextInt(90) + 10, drawPanel.getWidth(), drawPanel.getHeight());
|
||||
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());
|
||||
drawingComponents.SetDrawingWarship(_warship);
|
||||
_warship = new DrawingWarship(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000),
|
||||
new Color(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)));
|
||||
SetData();
|
||||
Draw();
|
||||
}
|
||||
});
|
||||
|
||||
//добавление модифицированного объекта
|
||||
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();
|
||||
}
|
||||
});
|
||||
@ -66,7 +92,7 @@ public class FormWarship extends JFrame {
|
||||
buttonLeft.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if(_warship != null) _warship.MoveTransport(Direction.Left);
|
||||
if (_warship != null) _warship.MoveTransport(Direction.Left);
|
||||
Draw();
|
||||
}
|
||||
});
|
||||
@ -74,7 +100,7 @@ public class FormWarship extends JFrame {
|
||||
buttonRight.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if(_warship != null) _warship.MoveTransport(Direction.Right);
|
||||
if (_warship != null) _warship.MoveTransport(Direction.Right);
|
||||
Draw();
|
||||
}
|
||||
});
|
||||
@ -82,7 +108,7 @@ public class FormWarship extends JFrame {
|
||||
buttonUp.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if(_warship != null) _warship.MoveTransport(Direction.Up);
|
||||
if (_warship != null) _warship.MoveTransport(Direction.Up);
|
||||
Draw();
|
||||
}
|
||||
});
|
||||
@ -90,16 +116,16 @@ public class FormWarship extends JFrame {
|
||||
buttonDown.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if(_warship != null) _warship.MoveTransport(Direction.Down);
|
||||
if (_warship != null) _warship.MoveTransport(Direction.Down);
|
||||
Draw();
|
||||
}
|
||||
});
|
||||
|
||||
drawPanel.addComponentListener(new ComponentAdapter() {
|
||||
mainPanel.addComponentListener(new ComponentAdapter() {
|
||||
@Override
|
||||
public void componentResized(ComponentEvent e) {
|
||||
_warship.ChangeBorders(drawPanel.getWidth(),drawPanel.getHeight());
|
||||
Draw();
|
||||
super.componentResized(e);
|
||||
resizeWindow();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
15
src/IDrawingObject.java
Normal file
15
src/IDrawingObject.java
Normal file
@ -0,0 +1,15 @@
|
||||
import java.awt.*;
|
||||
|
||||
public interface IDrawingObject {
|
||||
// Шаг перемещения объекта
|
||||
public float Step = 0;
|
||||
// Установка позиции объекта
|
||||
void SetObject(int x, int y, int width, int height);
|
||||
// Изменение направления пермещения объекта
|
||||
void MoveObject(Direction direction);
|
||||
// Отрисовка объекта
|
||||
void DrawningObject(Graphics g);
|
||||
// Получение текущей позиции объекта
|
||||
// /Left, Right, Top, Bottom)
|
||||
float[] GetCurrentPosition();
|
||||
}
|
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);
|
||||
}
|
53
src/LineMap.java
Normal file
53
src/LineMap.java
Normal file
@ -0,0 +1,53 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class LineMap extends AbstractMap{
|
||||
@Override
|
||||
protected void DrawBarrierPart(Graphics g, int i, int j)
|
||||
{
|
||||
Graphics2D g2 = (Graphics2D) g;
|
||||
g2.setColor(Color.gray);
|
||||
g2.fillRect((int) (i * _size_x), (int) (j * _size_y), (int) (i * (_size_x + 1)), (int) (j * (_size_y + 1)));
|
||||
}
|
||||
@Override
|
||||
protected void DrawRoadPart(Graphics g, int i, int j)
|
||||
{
|
||||
Graphics2D g2 = (Graphics2D) g;
|
||||
g2.setColor(Color.BLUE);
|
||||
g2.fillRect((int) (i * _size_x), (int) (j * _size_y), (int) (i * (_size_x + 1)), (int) (j * (_size_y + 1)));
|
||||
}
|
||||
@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[i].length; ++j)
|
||||
{
|
||||
_map[i][j] = _freeRoad;
|
||||
}
|
||||
}
|
||||
boolean flag = true;
|
||||
while (counter < 20)
|
||||
{
|
||||
int lineX = _random.nextInt(11, 89);
|
||||
int lineY = _random.nextInt(11, 89);
|
||||
|
||||
if (flag)
|
||||
{
|
||||
for (int i = lineY; i <= lineY + 10; i++)
|
||||
_map[lineX][i] = _barrier;
|
||||
flag = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = lineX; i <= lineX + 10; i++)
|
||||
_map[i][lineY] = _barrier;
|
||||
flag = true;
|
||||
}
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
new FormWarship();
|
||||
new FormMap();
|
||||
}
|
||||
|
||||
}
|
||||
|
43
src/SimpleMap.java
Normal file
43
src/SimpleMap.java
Normal file
@ -0,0 +1,43 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class SimpleMap extends AbstractMap{
|
||||
@Override
|
||||
protected void DrawBarrierPart(Graphics g, int i, int j)
|
||||
{
|
||||
Graphics2D g2 = (Graphics2D) g;
|
||||
g2.setColor(Color.gray);
|
||||
g2.fillRect((int) (i * _size_x), (int) (j * _size_y), (int) (i * (_size_x + 1)), (int) (j * (_size_y + 1)));
|
||||
}
|
||||
@Override
|
||||
protected void DrawRoadPart(Graphics g, int i, int j)
|
||||
{
|
||||
Graphics2D g2 = (Graphics2D) g;
|
||||
g2.setColor(Color.BLUE);
|
||||
g2.fillRect((int) (i * _size_x), (int) (j * _size_y), (int) (i * (_size_x + 1)), (int) (j * (_size_y + 1)));
|
||||
}
|
||||
@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[i].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++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user