Добавление интерфейсов и абстрактного класса.
This commit is contained in:
parent
dfd332987d
commit
6bdd753c33
@ -2,7 +2,9 @@
|
|||||||
<module type="JAVA_MODULE" version="4">
|
<module type="JAVA_MODULE" version="4">
|
||||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||||
<exclude-output />
|
<exclude-output />
|
||||||
<content url="file://$MODULE_DIR$" />
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
|
||||||
|
</content>
|
||||||
<orderEntry type="inheritedJdk" />
|
<orderEntry type="inheritedJdk" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
</component>
|
</component>
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ProjectRootManager">
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_X" default="true" project-jdk-name="openjdk-18" project-jdk-type="JavaSDK">
|
||||||
<output url="file://$PROJECT_DIR$/out" />
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_X" default="true" project-jdk-name="openjdk-18" project-jdk-type="JavaSDK">
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" project-jdk-name="openjdk-18" project-jdk-type="JavaSDK">
|
||||||
<output url="file://$PROJECT_DIR$/out" />
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
3
Project/src/.idea/.gitignore
vendored
Normal file
3
Project/src/.idea/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
6
Project/src/.idea/misc.xml
Normal file
6
Project/src/.idea/misc.xml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_X" default="true" project-jdk-name="openjdk-18" project-jdk-type="JavaSDK">
|
||||||
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
|
</component>
|
||||||
|
</project>
|
8
Project/src/.idea/modules.xml
Normal file
8
Project/src/.idea/modules.xml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/Project.iml" filepath="$PROJECT_DIR$/Project.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
6
Project/src/.idea/vcs.xml
Normal file
6
Project/src/.idea/vcs.xml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$/../.." vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
167
Project/src/AbstractMap.java
Normal file
167
Project/src/AbstractMap.java
Normal file
@ -0,0 +1,167 @@
|
|||||||
|
import java.awt.*;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public abstract class AbstractMap
|
||||||
|
{
|
||||||
|
private IDrawningObject _drawingObject = null;
|
||||||
|
protected int[][] _map = null;
|
||||||
|
protected int _width;
|
||||||
|
protected int _height;
|
||||||
|
protected float _size_x;
|
||||||
|
protected float _size_y;
|
||||||
|
protected float[] position;
|
||||||
|
protected Random _random = new Random();
|
||||||
|
protected int _freeRoad = 0;
|
||||||
|
protected int _barrier = 1;
|
||||||
|
|
||||||
|
public BufferedImage CreateMap(int width, int height, IDrawningObject drawningObject)
|
||||||
|
{
|
||||||
|
_width = width;
|
||||||
|
_height = height;
|
||||||
|
_drawingObject = drawningObject;
|
||||||
|
|
||||||
|
GenerateMap();
|
||||||
|
while (!SetObjectOnMap())
|
||||||
|
{
|
||||||
|
GenerateMap();
|
||||||
|
}
|
||||||
|
|
||||||
|
return DrawMapWithObject();
|
||||||
|
}
|
||||||
|
|
||||||
|
//проверка на "накладывание"
|
||||||
|
protected boolean CheckPosition(float Left, float Right, float Top, float Bottom)
|
||||||
|
{
|
||||||
|
int x_start = (int)(Left / _size_x);
|
||||||
|
int y_start = (int)(Right / _size_y);
|
||||||
|
int x_end = (int)(Top / _size_x);
|
||||||
|
int y_end = (int)(Bottom / _size_y);
|
||||||
|
|
||||||
|
for(int i = x_start; i <= x_end; i++)
|
||||||
|
{
|
||||||
|
for(int j = y_start; j <= y_end; j++)
|
||||||
|
{
|
||||||
|
if (_map[i][j] == _barrier)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BufferedImage MoveObject(Direction direction)
|
||||||
|
{
|
||||||
|
position = _drawingObject.GetCurrentPosition();
|
||||||
|
|
||||||
|
for (int i = 0; i < _map.length; ++i)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < _map[i].length; ++j)
|
||||||
|
{
|
||||||
|
if (_map[i][j] == _barrier)
|
||||||
|
{
|
||||||
|
switch (direction)
|
||||||
|
{
|
||||||
|
case Up:
|
||||||
|
if(_size_y * (j+1) >= position[0] - _drawingObject.Step() && _size_y * (j+1) < position[0] && _size_x * (i + 1) > position[3]
|
||||||
|
&& _size_x * (i + 1) <= position[1])
|
||||||
|
{
|
||||||
|
return DrawMapWithObject();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case Down:
|
||||||
|
if (_size_y * j <= position[2] + _drawingObject.Step() && _size_y * j > position[2] && _size_x * (i+1) > position[3]
|
||||||
|
&& _size_x * (i+1) <= position[1])
|
||||||
|
{
|
||||||
|
return DrawMapWithObject();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case Left:
|
||||||
|
if (_size_x * (i+1) >= position[3] - _drawingObject.Step() && _size_x * (i + 1) < position[3] && _size_y * (j + 1) < position[2]
|
||||||
|
&& _size_y * (j + 1) >= position[0])
|
||||||
|
{
|
||||||
|
return DrawMapWithObject();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case Right:
|
||||||
|
if (_size_x * i <= position[1] + _drawingObject.Step() && _size_x * i > position[3] && _size_y * (j + 1) < position[2]
|
||||||
|
&& _size_y * (j + 1) >= position[0])
|
||||||
|
{
|
||||||
|
return DrawMapWithObject();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_drawingObject.MoveObject(direction);
|
||||||
|
return DrawMapWithObject();
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean SetObjectOnMap()
|
||||||
|
{
|
||||||
|
if(_drawingObject == null || _map == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int x = _random.nextInt(10);
|
||||||
|
int y = _random.nextInt(10);
|
||||||
|
_drawingObject.SetObject(x, y, _width, _height);
|
||||||
|
|
||||||
|
for (int i = 0; i < _map.length; ++i)
|
||||||
|
{
|
||||||
|
for(int j = 0; j < _map[0].length; ++j)
|
||||||
|
{
|
||||||
|
if(i * _size_x >= x && j * _size_y >= y &&
|
||||||
|
i * _size_x <= x + _drawingObject.GetCurrentPosition()[1] &&
|
||||||
|
j * _size_y <= j + _drawingObject.GetCurrentPosition()[2])
|
||||||
|
{
|
||||||
|
if (_map[i][j] == _barrier)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
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[i].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);
|
||||||
|
}
|
7
Project/src/IAdditionalDrawingObject.java
Normal file
7
Project/src/IAdditionalDrawingObject.java
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public interface IAdditionalDrawingObject
|
||||||
|
{
|
||||||
|
void SetAddEnum(int airplaneWindow);
|
||||||
|
void DrawAirplaneWindow(Color colorAirplaneWindow, Graphics g, float _startPosX, float _startPosY);
|
||||||
|
}
|
18
Project/src/IDrawningObject.java
Normal file
18
Project/src/IDrawningObject.java
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public interface IDrawningObject {
|
||||||
|
//шаг перемещения объекта
|
||||||
|
public float Step();
|
||||||
|
|
||||||
|
//установка позиции объекта
|
||||||
|
void SetObject(int x, int y, int width, int height);
|
||||||
|
|
||||||
|
//изменение направления перемещения объекта
|
||||||
|
void MoveObject(Direction direction);
|
||||||
|
|
||||||
|
//отрисовка объекта
|
||||||
|
void DrawningObject(Graphics g);
|
||||||
|
|
||||||
|
//получение текущей позиции объекта
|
||||||
|
float[] GetCurrentPosition();
|
||||||
|
}
|
11
Project/src/Project.iml
Normal file
11
Project/src/Project.iml
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="JAVA_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||||
|
<exclude-output />
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
Loading…
Reference in New Issue
Block a user