Реализованы классы от интерфейса ИнтерДоп
This commit is contained in:
parent
759245f4f2
commit
45f014ceae
@ -2,9 +2,10 @@ package ProjectStormtrooper;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawingEngines {
|
||||
public class DrawingEngines implements IDrawingEngines {
|
||||
private EnumEnginesCount _enumEnginesCount;
|
||||
|
||||
@Override
|
||||
public void SetEnumEnginesCount(int enginesCount) {
|
||||
for (EnumEnginesCount val : EnumEnginesCount.values()) {
|
||||
if (val.count == enginesCount) {
|
||||
@ -15,7 +16,13 @@ public class DrawingEngines {
|
||||
this._enumEnginesCount = EnumEnginesCount.Two;
|
||||
}
|
||||
|
||||
private void DrawEngine(Graphics2D g2d, Color color, int x, int y, int w, int h) {
|
||||
@Override
|
||||
public EnumEnginesCount GetEnumEnginesCount() {
|
||||
return _enumEnginesCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void DrawEngine(Graphics2D g2d, Color color, int x, int y, int w, int h) {
|
||||
g2d.setColor(Color.WHITE);
|
||||
g2d.fillRect(x, y, w, h);
|
||||
g2d.setColor(Color.BLACK);
|
||||
@ -23,63 +30,4 @@ public class DrawingEngines {
|
||||
g2d.setColor(color);
|
||||
g2d.fillRect(x, y, 6, h);
|
||||
}
|
||||
|
||||
public void DrawEngines(Graphics g, Color color, int startPosX, int startPosY, int drawingWidth, int drawingHeight) {
|
||||
if (_enumEnginesCount == null) {
|
||||
return;
|
||||
}
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
|
||||
int engineWidth = 20;
|
||||
int engineHeight = 6;
|
||||
|
||||
if (_enumEnginesCount.count >= EnumEnginesCount.Two.count) {
|
||||
DrawEngine(
|
||||
g2d, color,
|
||||
startPosX + drawingWidth - drawingWidth / 5,
|
||||
startPosY + drawingHeight / 2 - drawingHeight / 6,
|
||||
engineWidth,
|
||||
engineHeight
|
||||
);
|
||||
DrawEngine(
|
||||
g2d, color,
|
||||
startPosX + drawingWidth - drawingWidth / 5,
|
||||
startPosY + drawingHeight / 2 + drawingHeight / 6 - engineHeight,
|
||||
engineWidth,
|
||||
engineHeight
|
||||
);
|
||||
}
|
||||
if (_enumEnginesCount.count >= EnumEnginesCount.Four.count) {
|
||||
DrawEngine(
|
||||
g2d, color,
|
||||
startPosX + drawingWidth - drawingWidth / 5 + 5,
|
||||
startPosY + drawingHeight / 2 - drawingHeight / 6 - 10,
|
||||
engineWidth - 5,
|
||||
engineHeight
|
||||
);
|
||||
DrawEngine(
|
||||
g2d, color,
|
||||
startPosX + drawingWidth - drawingWidth / 5 + 5,
|
||||
startPosY + drawingHeight / 2 + drawingHeight / 6 - engineHeight + 10,
|
||||
engineWidth - 5,
|
||||
engineHeight
|
||||
);
|
||||
}
|
||||
if (_enumEnginesCount.count >= EnumEnginesCount.Six.count) {
|
||||
DrawEngine(
|
||||
g2d, color,
|
||||
startPosX + drawingWidth / 2 - 10,
|
||||
startPosY + drawingHeight / 2 - drawingHeight / 6 - 10,
|
||||
engineWidth,
|
||||
engineHeight
|
||||
);
|
||||
DrawEngine(
|
||||
g2d, color,
|
||||
startPosX + drawingWidth / 2 - 10,
|
||||
startPosY + drawingHeight / 2 + drawingHeight / 6 + 3,
|
||||
engineWidth,
|
||||
engineHeight
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
39
ProjectStormtrooper/DrawingEnginesEllipse.java
Normal file
39
ProjectStormtrooper/DrawingEnginesEllipse.java
Normal file
@ -0,0 +1,39 @@
|
||||
package ProjectStormtrooper;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawingEnginesEllipse implements IDrawingEngines {
|
||||
private EnumEnginesCount _enumEnginesCount;
|
||||
|
||||
@Override
|
||||
public void SetEnumEnginesCount(int enginesCount) {
|
||||
for (EnumEnginesCount val : EnumEnginesCount.values()) {
|
||||
if (val.count == enginesCount) {
|
||||
this._enumEnginesCount = val;
|
||||
return;
|
||||
}
|
||||
}
|
||||
this._enumEnginesCount = EnumEnginesCount.Two;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumEnginesCount GetEnumEnginesCount() {
|
||||
return _enumEnginesCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void DrawEngine(Graphics2D g2d, Color color, int x, int y, int w, int h) {
|
||||
Polygon enginePolygon = new Polygon();
|
||||
enginePolygon.addPoint(x, y + h / 2);
|
||||
enginePolygon.addPoint(x + w / 10, y);
|
||||
enginePolygon.addPoint(x + w - w / 2, y + h / 2);
|
||||
enginePolygon.addPoint(x + w, y);
|
||||
enginePolygon.addPoint(x + w, y + h);
|
||||
enginePolygon.addPoint(x + w - w / 2, y + h / 2);
|
||||
enginePolygon.addPoint(x + w / 10, y + h);
|
||||
g2d.setColor(Color.WHITE);
|
||||
g2d.fillPolygon(enginePolygon);
|
||||
g2d.setColor(Color.BLACK);
|
||||
g2d.drawPolygon(enginePolygon);
|
||||
}
|
||||
}
|
31
ProjectStormtrooper/DrawingEnginesWithFlame.java
Normal file
31
ProjectStormtrooper/DrawingEnginesWithFlame.java
Normal file
@ -0,0 +1,31 @@
|
||||
package ProjectStormtrooper;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawingEnginesWithFlame implements IDrawingEngines {
|
||||
private EnumEnginesCount _enumEnginesCount;
|
||||
|
||||
@Override
|
||||
public void SetEnumEnginesCount(int enginesCount) {
|
||||
for (EnumEnginesCount val : EnumEnginesCount.values()) {
|
||||
if (val.count == enginesCount) {
|
||||
this._enumEnginesCount = val;
|
||||
return;
|
||||
}
|
||||
}
|
||||
this._enumEnginesCount = EnumEnginesCount.Two;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumEnginesCount GetEnumEnginesCount() {
|
||||
return _enumEnginesCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void DrawEngine(Graphics2D g2d, Color color, int x, int y, int w, int h) {
|
||||
g2d.setColor(Color.WHITE);
|
||||
g2d.fillOval(x, y, w, h);
|
||||
g2d.setColor(Color.BLACK);
|
||||
g2d.drawOval(x, y, w, h);
|
||||
}
|
||||
}
|
@ -1,10 +1,11 @@
|
||||
package ProjectStormtrooper;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.Random;
|
||||
|
||||
public class DrawingPlane {
|
||||
public EntityPlane EntityPlane;
|
||||
protected DrawingEngines _drawingEngines;
|
||||
protected IDrawingEngines _drawingEngines;
|
||||
protected int _pictureWidth;
|
||||
protected int _pictureHeight;
|
||||
protected int _startPosX;
|
||||
@ -35,20 +36,21 @@ public class DrawingPlane {
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
EntityPlane = new EntityPlane(speed, weight, bodyColor);
|
||||
_drawingEngines = new DrawingEngines();
|
||||
Random random = new Random();
|
||||
int drawingEnginesType = random.nextInt(0, 3);
|
||||
if (drawingEnginesType == 0)
|
||||
_drawingEngines = new DrawingEngines();
|
||||
else if (drawingEnginesType == 1)
|
||||
_drawingEngines = new DrawingEnginesEllipse();
|
||||
else if (drawingEnginesType == 2)
|
||||
_drawingEngines = new DrawingEnginesWithFlame();
|
||||
}
|
||||
|
||||
protected DrawingPlane(int speed, double weight, Color bodyColor,
|
||||
int width, int height, int planeWidth, int planeHeight) {
|
||||
if (width < planeWidth && height < planeHeight) {
|
||||
return;
|
||||
}
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
this(speed, weight, bodyColor, width, height);
|
||||
_planeWidth = planeWidth;
|
||||
_planeHeight = planeHeight;
|
||||
EntityPlane = new EntityPlane(speed, weight, bodyColor);
|
||||
_drawingEngines = new DrawingEngines();
|
||||
}
|
||||
public void SetEnginesCount(int enginesCount) {
|
||||
_drawingEngines.SetEnumEnginesCount(enginesCount);
|
||||
|
71
ProjectStormtrooper/IDrawingEngines.java
Normal file
71
ProjectStormtrooper/IDrawingEngines.java
Normal file
@ -0,0 +1,71 @@
|
||||
package ProjectStormtrooper;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public interface IDrawingEngines {
|
||||
void SetEnumEnginesCount(int enginesCount);
|
||||
|
||||
EnumEnginesCount GetEnumEnginesCount();
|
||||
|
||||
void DrawEngine(Graphics2D g2d, Color color, int x, int y, int w, int h);
|
||||
|
||||
default void DrawEngines(Graphics g, Color color, int startPosX, int startPosY, int drawingWidth, int drawingHeight) {
|
||||
EnumEnginesCount enginesCount = GetEnumEnginesCount();
|
||||
if (enginesCount == null) {
|
||||
return;
|
||||
}
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
|
||||
int engineWidth = 20;
|
||||
int engineHeight = 6;
|
||||
|
||||
if (enginesCount.count >= EnumEnginesCount.Two.count) {
|
||||
DrawEngine(
|
||||
g2d, color,
|
||||
startPosX + drawingWidth - drawingWidth / 5,
|
||||
startPosY + drawingHeight / 2 - drawingHeight / 6,
|
||||
engineWidth,
|
||||
engineHeight
|
||||
);
|
||||
DrawEngine(
|
||||
g2d, color,
|
||||
startPosX + drawingWidth - drawingWidth / 5,
|
||||
startPosY + drawingHeight / 2 + drawingHeight / 6 - engineHeight,
|
||||
engineWidth,
|
||||
engineHeight
|
||||
);
|
||||
}
|
||||
if (enginesCount.count >= EnumEnginesCount.Four.count) {
|
||||
DrawEngine(
|
||||
g2d, color,
|
||||
startPosX + drawingWidth - drawingWidth / 5 + 5,
|
||||
startPosY + drawingHeight / 2 - drawingHeight / 6 - 10,
|
||||
engineWidth - 5,
|
||||
engineHeight
|
||||
);
|
||||
DrawEngine(
|
||||
g2d, color,
|
||||
startPosX + drawingWidth - drawingWidth / 5 + 5,
|
||||
startPosY + drawingHeight / 2 + drawingHeight / 6 - engineHeight + 10,
|
||||
engineWidth - 5,
|
||||
engineHeight
|
||||
);
|
||||
}
|
||||
if (enginesCount.count >= EnumEnginesCount.Six.count) {
|
||||
DrawEngine(
|
||||
g2d, color,
|
||||
startPosX + drawingWidth / 2 - 10,
|
||||
startPosY + drawingHeight / 2 - drawingHeight / 6 - 10,
|
||||
engineWidth,
|
||||
engineHeight
|
||||
);
|
||||
DrawEngine(
|
||||
g2d, color,
|
||||
startPosX + drawingWidth / 2 - 10,
|
||||
startPosY + drawingHeight / 2 + drawingHeight / 6 + 3,
|
||||
engineWidth,
|
||||
engineHeight
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user