сделал сущность и рисовалку
This commit is contained in:
parent
5cae31af03
commit
9d85732740
8
src/main/java/kvr/missilecruiser_hard/DirectionType.java
Normal file
8
src/main/java/kvr/missilecruiser_hard/DirectionType.java
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
package kvr.missilecruiser_hard;
|
||||||
|
|
||||||
|
public enum DirectionType {
|
||||||
|
Up,
|
||||||
|
Down,
|
||||||
|
Left,
|
||||||
|
Right
|
||||||
|
}
|
195
src/main/java/kvr/missilecruiser_hard/DrawingMissileCruiser.java
Normal file
195
src/main/java/kvr/missilecruiser_hard/DrawingMissileCruiser.java
Normal file
@ -0,0 +1,195 @@
|
|||||||
|
package kvr.missilecruiser_hard;
|
||||||
|
|
||||||
|
import javafx.scene.canvas.GraphicsContext;
|
||||||
|
import javafx.scene.image.Image;
|
||||||
|
import javafx.scene.paint.Color;
|
||||||
|
|
||||||
|
public class DrawingMissileCruiser {
|
||||||
|
/// Класс-сущность
|
||||||
|
private EntityMissileCruiser entityMissileCruiser;
|
||||||
|
|
||||||
|
public EntityMissileCruiser getEntityMissileCruiser(){
|
||||||
|
return entityMissileCruiser;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Ширина окна
|
||||||
|
private int pictureWidth;
|
||||||
|
|
||||||
|
/// Высота окна
|
||||||
|
private int pictureHeight;
|
||||||
|
|
||||||
|
/// X координата прорисовки
|
||||||
|
private int posX;
|
||||||
|
|
||||||
|
/// Y координата прорисовки
|
||||||
|
private int posY;
|
||||||
|
|
||||||
|
/// Ширина прорисовки
|
||||||
|
private final int entityWidth = 150;
|
||||||
|
|
||||||
|
/// Высота прорисовки
|
||||||
|
private final int entityHeight = 35;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Инициализация свойств
|
||||||
|
/// </summary>
|
||||||
|
/// @param speed Скорость
|
||||||
|
/// @param weight Вес крейсера
|
||||||
|
/// @param primaryColor Основной цвет
|
||||||
|
/// @param secondaryColor Дополнительный цвет
|
||||||
|
/// @param vls_sides Признак наличия боковых установок вертикального пуска
|
||||||
|
/// @param vls_center Признак наличия центральных установок вертикального пуска
|
||||||
|
/// @param helipad Признак наличия вертолётной площадки
|
||||||
|
public void Init(int speed, int weight, Color primaryColor, Color secondaryColor, boolean vls_sides, boolean vls_center, boolean helipad)
|
||||||
|
{
|
||||||
|
entityMissileCruiser = new EntityMissileCruiser();
|
||||||
|
entityMissileCruiser.Init(speed, weight, primaryColor, secondaryColor, vls_sides, vls_center, helipad);
|
||||||
|
pictureWidth = 0;
|
||||||
|
pictureHeight = 0;
|
||||||
|
posX = 0;
|
||||||
|
posY = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Установка границ поля
|
||||||
|
/// </summary>
|
||||||
|
/// @param width Ширина поля
|
||||||
|
/// @param height Высота поля
|
||||||
|
/// <returns>true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах</returns>
|
||||||
|
public boolean SetPictureSize(int width, int height)
|
||||||
|
{
|
||||||
|
if (entityMissileCruiser == null || width <= 0 || height <= 0)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (entityWidth < width && entityHeight < height)
|
||||||
|
{
|
||||||
|
pictureWidth = width;
|
||||||
|
pictureHeight = height;
|
||||||
|
|
||||||
|
posX = Math.clamp(posX, 0, pictureWidth - entityWidth);
|
||||||
|
posY = Math.clamp(posY, 0, pictureHeight - entityHeight);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Установка позиции
|
||||||
|
/// </summary>
|
||||||
|
/// @param x Координата X
|
||||||
|
/// @param y Координата Y
|
||||||
|
public void SetPosition(int x, int y)
|
||||||
|
{
|
||||||
|
if (pictureWidth == 0 || pictureHeight == 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
posX = Math.clamp(x, 0, pictureWidth - entityWidth);
|
||||||
|
posY = Math.clamp(y, 0, pictureHeight - entityHeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Перемещение объекта в заданную сторону
|
||||||
|
/// </summary>
|
||||||
|
/// @param direction Направление
|
||||||
|
/// @return true - перемещене выполнено, false - перемещение невозможно
|
||||||
|
public boolean MoveTransport(DirectionType direction)
|
||||||
|
{
|
||||||
|
if (entityMissileCruiser == null || pictureWidth <= 0 || pictureHeight <= 0)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int step = entityMissileCruiser.getStep();
|
||||||
|
switch (direction)
|
||||||
|
{
|
||||||
|
case DirectionType.Left:
|
||||||
|
if (posX - step >= 0)
|
||||||
|
{
|
||||||
|
posX -= step;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
case DirectionType.Up:
|
||||||
|
if (posY - step >= 0)
|
||||||
|
{
|
||||||
|
posY -= step;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
case DirectionType.Right:
|
||||||
|
if (posX + step < pictureWidth - entityWidth)
|
||||||
|
{
|
||||||
|
posX += step;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
case DirectionType.Down:
|
||||||
|
if (posY + step < pictureHeight - entityHeight)
|
||||||
|
{
|
||||||
|
posY += step;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private final Image cruiserContourImg = new Image("images/cruiser_contour.png");
|
||||||
|
private final Image vlsSideImg = new Image("images/cruiser_vls_sides.png");
|
||||||
|
private final Image vlsCenterImg = new Image("images/cruiser_vls_center.png");
|
||||||
|
private final Image helipadImg = new Image("images/cruiser_helipad.png");
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Прорисовка объекта
|
||||||
|
/// </summary>
|
||||||
|
/// @param gc Объект GDI+
|
||||||
|
public void DrawTransport(GraphicsContext gc)
|
||||||
|
{
|
||||||
|
if (entityMissileCruiser == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
double[][] contourPolygon = new double[][] {
|
||||||
|
{posX + 11, posY},
|
||||||
|
{posX + 116, posY},
|
||||||
|
{posX + 149, posY + 17},
|
||||||
|
{posX + 116, posY + 34},
|
||||||
|
{posX + 10, posY + 34},
|
||||||
|
{posX, posY + 29},
|
||||||
|
{posX, posY + 5}
|
||||||
|
};
|
||||||
|
|
||||||
|
gc.clearRect(0, 0, pictureWidth, pictureHeight);
|
||||||
|
|
||||||
|
gc.setFill(entityMissileCruiser.getPrimaryColor());
|
||||||
|
gc.fillPolygon(contourPolygon[0], contourPolygon[1], contourPolygon.length);
|
||||||
|
|
||||||
|
if (entityMissileCruiser.getVLS_Sides())
|
||||||
|
{
|
||||||
|
gc.setFill(entityMissileCruiser.getSecondaryColor());
|
||||||
|
gc.fillRect(posX + 44, posY + 5, 24, 6);
|
||||||
|
gc.fillRect(posX + 44, posY + 23, 24, 6);
|
||||||
|
gc.drawImage(vlsSideImg, posX, posY, entityWidth, entityHeight);
|
||||||
|
}
|
||||||
|
if (entityMissileCruiser.getVLS_Center())
|
||||||
|
{
|
||||||
|
gc.setFill(entityMissileCruiser.getSecondaryColor());
|
||||||
|
gc.fillRect(posX + 44, posY + 14, 24, 6);
|
||||||
|
gc.drawImage(vlsCenterImg, posX, posY, entityWidth, entityHeight);
|
||||||
|
}
|
||||||
|
if (entityMissileCruiser.getHelipad())
|
||||||
|
{
|
||||||
|
gc.setFill(entityMissileCruiser.getSecondaryColor());
|
||||||
|
gc.fillOval(posX + 2, posY + 9, 16, 16);
|
||||||
|
gc.drawImage(helipadImg, posX, posY, entityWidth, entityHeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
gc.drawImage(cruiserContourImg, posX, posY, entityWidth, entityHeight);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,81 @@
|
|||||||
|
package kvr.missilecruiser_hard;
|
||||||
|
|
||||||
|
import javafx.scene.paint.Color;
|
||||||
|
|
||||||
|
public class EntityMissileCruiser {
|
||||||
|
|
||||||
|
/// Скорость
|
||||||
|
private int speed;
|
||||||
|
|
||||||
|
public int getSpeed(){
|
||||||
|
return speed;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Вес
|
||||||
|
private double weight;
|
||||||
|
|
||||||
|
public double getWeight(){
|
||||||
|
return weight;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Основной цвет
|
||||||
|
private Color primaryColor;
|
||||||
|
|
||||||
|
public Color getPrimaryColor(){
|
||||||
|
return primaryColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Дополнительный цвет (для опциональных элементов)
|
||||||
|
private Color secondaryColor;
|
||||||
|
|
||||||
|
public Color getSecondaryColor(){
|
||||||
|
return secondaryColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Боковые установки вертикального пуска
|
||||||
|
private boolean vls_sides;
|
||||||
|
|
||||||
|
public boolean getVLS_Sides(){
|
||||||
|
return vls_sides;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Центральные установки вертикального пуска
|
||||||
|
private boolean vls_center;
|
||||||
|
|
||||||
|
public boolean getVLS_Center() {
|
||||||
|
return vls_center;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Вертолётная площадка
|
||||||
|
private boolean helipad;
|
||||||
|
|
||||||
|
public boolean getHelipad(){
|
||||||
|
return helipad;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Шаг перемещения
|
||||||
|
public int getStep() {
|
||||||
|
return (int)(speed * 100 / weight);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Инициализация полей объекта-класса ракетного крейсера
|
||||||
|
* @param Speed Скорость
|
||||||
|
* @param Weight Вес крейсера
|
||||||
|
* @param PrimaryColor Основной цвет
|
||||||
|
* @param SecondaryColor Дополнительный цвет
|
||||||
|
* @param VLS_Sides Признак наличия боковых установок вертикального пуска
|
||||||
|
* @param VLS_Center Признак наличия центральных установок вертикального пуска
|
||||||
|
* @param Helipad Признак наличия вертолётной площадки
|
||||||
|
*/
|
||||||
|
public void Init(int Speed, int Weight, Color PrimaryColor, Color SecondaryColor, boolean VLS_Sides, boolean VLS_Center, boolean Helipad)
|
||||||
|
{
|
||||||
|
speed = Speed;
|
||||||
|
weight = Weight;
|
||||||
|
primaryColor = PrimaryColor;
|
||||||
|
secondaryColor = SecondaryColor;
|
||||||
|
vls_sides = VLS_Sides;
|
||||||
|
vls_center = VLS_Center;
|
||||||
|
helipad = Helipad;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user