This commit is contained in:
DavidMakarov 2023-12-15 22:51:08 +04:00
parent 4e293da393
commit 77371f66bf
17 changed files with 872 additions and 17 deletions

View File

@ -1,5 +1,10 @@
package AirplaneWithRadar;
import AirplaneWithRadar.MovementStrategy.Movement;
import AirplaneWithRadar.MovementStrategy.*;
import AirplaneWithRadar.PaintObjects.PaintAirplane;
import AirplaneWithRadar.PaintObjects.PaintAirplaneWithRadar;
import javax.swing.*;
import java.awt.*;
@ -7,7 +12,8 @@ import java.awt.event.ActionEvent;
import java.awt.image.BufferedImage;
import java.util.Random;
public class AirplaneWithRadarForm extends JFrame {
private PaintAirplaneWithRadar PaintPlanes;
private PaintAirplane PaintPlanes;
private AbstractStrategy abstractStrategy;
private void Draw()
{
@ -27,28 +33,40 @@ public class AirplaneWithRadarForm extends JFrame {
public AirplaneWithRadarForm()
{
InitializeComponent();
}
private void InitializeComponent()
{
AirplanePictureBox = new JLabel();
CreateButton = new JButton();
ButtonCreateAirplane = new JButton();
ButtonCreateAirplaneWithRadar = new JButton();
ButtonRight = new JButton();
ButtonDown = new JButton();
ButtonLeft = new JButton();
ButtonUp = new JButton();
MovementStrategyComboBox = new JComboBox<String>();
ButtonPerformMove = new JButton();
AirplanePictureBox.setBounds(0, 0, 884, 461);
//
// ButtonCreateBomberBase
//
ButtonCreateAirplane.setName("ButtonCreateBomberBase");
ButtonCreateAirplane.setBounds(12, 383, 260, 30);
ButtonCreateAirplane.setText("Создать самолёт");
ButtonCreateAirplane.setBackground(new Color(225, 225, 225));
ButtonCreateAirplane.setFont(new Font("Segoe UI", Font.PLAIN, 11));
ButtonCreateAirplane.setFocusable(false);
ButtonCreateAirplane.addActionListener(e -> ButtonCreateAirplane_Click(e));
//
// CreateButton
//
CreateButton.setName("CreateButton");
CreateButton.setBounds(12, 419, 80, 30);
CreateButton.setText("Создать");
CreateButton.setBackground(new Color(225, 225, 225));
CreateButton.setFont(new Font("Segoe UI", Font.PLAIN, 11));
CreateButton.setFocusable(false);
CreateButton.addActionListener(e -> ButtonCreate_Click(e));
ButtonCreateAirplaneWithRadar.setName("CreateButton");
ButtonCreateAirplaneWithRadar.setBounds(12, 419, 260, 30);
ButtonCreateAirplaneWithRadar.setText("Создать самолёт с радаром");
ButtonCreateAirplaneWithRadar.setBackground(new Color(225, 225, 225));
ButtonCreateAirplaneWithRadar.setFont(new Font("Segoe UI", Font.PLAIN, 11));
ButtonCreateAirplaneWithRadar.setFocusable(false);
ButtonCreateAirplaneWithRadar.addActionListener(e -> ButtonCreateAirplaneWithRadar_Click(e));
//
// ButtonRight
//
@ -90,6 +108,22 @@ public class AirplaneWithRadarForm extends JFrame {
ButtonUp.setIcon(new ImageIcon("src/AirplaneWithRadar/Resources/ArrowUp.png"));
ButtonUp.addActionListener(e -> ButtonMove_Click(e));
//
// ButtonPerformMove
//
ButtonPerformMove.setName("ButtonPerformMove");
ButtonPerformMove.setBounds(706, 50, 166, 31);
ButtonPerformMove.setText("Сделать шаг");
ButtonPerformMove.setBackground(new Color(225, 225, 225));
ButtonPerformMove.setFont(new Font("Segoe UI", Font.PLAIN, 11));
ButtonPerformMove.setFocusable(false);
ButtonPerformMove.addActionListener(e -> ButtonPerformStep_Click(e));
//
// MovementStrategyComboBox
//
MovementStrategyComboBox.setBounds(706, 12, 166, 23);
MovementStrategyComboBox.addItem("Перемещать в центр");
MovementStrategyComboBox.addItem("Перемещать вправо вниз");
//
// AirplaneWithRadarForm
//
setTitle("Самолет с радаром");
@ -102,16 +136,21 @@ public class AirplaneWithRadarForm extends JFrame {
add(ButtonLeft);
add(ButtonDown);
add(ButtonRight);
add(CreateButton);
add(ButtonCreateAirplaneWithRadar);
add(ButtonCreateAirplane);
add(ButtonPerformMove);
add(MovementStrategyComboBox);
add(AirplanePictureBox);
}
private JLabel AirplanePictureBox;
private JButton CreateButton;
private JButton ButtonCreateAirplane;
private JButton ButtonCreateAirplaneWithRadar;
private JButton ButtonRight;
private JButton ButtonDown;
private JButton ButtonLeft;
private JButton ButtonUp;
private JButton ButtonPerformMove;
private JComboBox<String> MovementStrategyComboBox;
private void ButtonMove_Click(ActionEvent e)
{
@ -141,12 +180,11 @@ public class AirplaneWithRadarForm extends JFrame {
Draw();
}
private void ButtonCreate_Click(ActionEvent e)
private void ButtonCreateAirplaneWithRadar_Click(ActionEvent e)
{
Random random = new Random();
PaintPlanes = new PaintAirplaneWithRadar();
PaintPlanes.Init(
PaintPlanes = new PaintAirplaneWithRadar(
random.nextInt(100, 300),
random.nextInt(1000, 3000),
new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256)),
@ -156,7 +194,70 @@ public class AirplaneWithRadarForm extends JFrame {
AirplanePictureBox.getWidth(),
AirplanePictureBox.getHeight()
);
PaintPlanes.SetPosition(random.nextInt(20, 100), random.nextInt(20, 100));
PaintPlanes.SetPosition(random.nextInt(10, 60), random.nextInt(10, 60));
MovementStrategyComboBox.setEnabled(true);
Draw();
}
private void ButtonCreateAirplane_Click(ActionEvent e)
{
Random random = new Random();
PaintPlanes = new PaintAirplane(
random.nextInt(100, 300),
random.nextInt(1000, 3000),
new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256)),
AirplanePictureBox.getWidth(),
AirplanePictureBox.getHeight()
);
PaintPlanes.SetPosition(random.nextInt(10, 60), random.nextInt(10, 60));
MovementStrategyComboBox.setEnabled(true);
Draw();
}
private void ButtonPerformStep_Click(ActionEvent e)
{
if (PaintPlanes == null)
return;
if (MovementStrategyComboBox.isEnabled())
{
switch (MovementStrategyComboBox.getSelectedIndex())
{
case 0:
abstractStrategy = new MoveToCenter();
break;
case 1:
abstractStrategy = new MoveToBorder();
break;
default:
abstractStrategy = null;
}
if (abstractStrategy == null)
return;
abstractStrategy.SetData(
new PaintObjectAirplane(PaintPlanes),
AirplanePictureBox.getWidth(), AirplanePictureBox.getHeight()
);
MovementStrategyComboBox.setEnabled(false);
}
if (abstractStrategy == null)
return;
System.out.println(PaintPlanes.GetPosX());
abstractStrategy.MakeStep();
System.out.println(PaintPlanes.GetPosX());
Draw();
if (abstractStrategy.GetStatus() == Status.Finish)
{
MovementStrategyComboBox.setEnabled(true);
abstractStrategy = null;
}
}
}

View File

@ -0,0 +1,42 @@
package AirplaneWithRadar.Entities;
import java.awt.*;
public class AirplaneEntity {
public int Speed;
public double Weight;
public Color BodyColor;
public double Step;
public int getSpeed() {
return Speed;
}
private void setSpeed(int speed) {
Speed = speed;
}
public double getWeight() {
return Weight;
}
private void setWeight(double weight) {
Weight = weight;
}
public Color getBodyColor() {
return BodyColor;
}
private void setBodyColor(Color bodyColor) {
BodyColor = bodyColor;
}
public AirplaneEntity(int speed, double weight, Color bodyColor)
{
Speed = speed;
Weight = weight;
BodyColor = bodyColor;
Step = (double)Speed * 100 / Weight;
}
}

View File

@ -0,0 +1,42 @@
package AirplaneWithRadar.Entities;
import java.awt.Color;
public class AirplaneWithRadarEntity extends AirplaneEntity
{
public Color AdditColor;
public boolean RadarOnBoard;
public boolean AdditFuelPod;
public Color getAdditColor() {
return AdditColor;
}
private void setAdditColor(Color additColor) {
AdditColor = additColor;
}
public boolean isRadarOnBoard() {
return RadarOnBoard;
}
private void setRadarOnBoard(boolean radarOnBoard) {
RadarOnBoard = radarOnBoard;
}
public boolean isAdditFuelPod() {
return AdditFuelPod;
}
private void setAdditFuelPod(boolean additFuelPod) {
AdditFuelPod = additFuelPod;
}
public AirplaneWithRadarEntity(int Speed, double Weight, Color BodyColor, Color additColor, boolean radarOnBoard, boolean additFuelPod)
{
super(Speed, Weight, BodyColor);
AdditColor = additColor;
RadarOnBoard = radarOnBoard;
AdditFuelPod = additFuelPod;
}
}

View File

@ -0,0 +1,89 @@
package AirplaneWithRadar.MovementStrategy;
public abstract class AbstractStrategy {
private IMoveableObject moveableObject;
private Status state = Status.NotInit;
protected int FieldWidth;
public int getFieldWidth() {
return FieldWidth;
}
public void setFieldWidth(int fieldWidth) {
FieldWidth = fieldWidth;
}
protected int FieldHeight;
public int getFieldHeight() {
return FieldHeight;
}
public void setFieldHeight(int fieldHeight) {
FieldHeight = fieldHeight;
}
public Status GetStatus() { return state; }
public void SetData(IMoveableObject moveableObject, int width, int height)
{
if (moveableObject == null)
{
state = Status.NotInit;
return;
}
state = Status.InProgress;
this.moveableObject = moveableObject;
FieldWidth = width;
FieldHeight = height;
}
public void MakeStep()
{
if (state != Status.InProgress)
{
return;
}
if (IsTargetDestinaion())
{
state = Status.Finish;
return;
}
MoveToTarget();
}
protected boolean MoveLeft() {return MoveTo(Movement.Left);}
protected boolean MoveRight() {return MoveTo(Movement.Right);}
protected boolean MoveUp() {return MoveTo(Movement.Up);}
protected boolean MoveDown() {return MoveTo(Movement.Down);}
protected ObjectParameters GetObjectParameters() {
return moveableObject != null ? moveableObject.GetObjectPosition() : null;
}
protected Integer GetStep()
{
if (state != Status.InProgress)
{
return null;
}
return moveableObject != null ? moveableObject.GetStep() : null;
}
protected abstract void MoveToTarget();
protected abstract boolean IsTargetDestinaion();
private boolean MoveTo(Movement directionType)
{
if (state != Status.InProgress)
{
return false;
}
if (moveableObject != null && moveableObject.CheckCanMove(directionType))
{
moveableObject.MoveObject(directionType);
return true;
}
return false;
}
}

View File

@ -0,0 +1,8 @@
package AirplaneWithRadar.MovementStrategy;
public interface IMoveableObject {
ObjectParameters GetObjectPosition();
int GetStep();
boolean CheckCanMove(Movement direction);
void MoveObject(Movement direction);
}

View File

@ -0,0 +1,52 @@
package AirplaneWithRadar.MovementStrategy;
public class MoveToBorder extends AbstractStrategy{
@Override
protected boolean IsTargetDestinaion()
{
var objParams = GetObjectParameters();
if (objParams == null)
{
return false;
}
return objParams.RightBorder() <= FieldWidth && objParams.RightBorder() + GetStep() >= FieldWidth &&
objParams.DownBorder() <= FieldHeight && objParams.DownBorder() + GetStep() >= FieldHeight;
}
@Override
protected void MoveToTarget()
{
var objParams = GetObjectParameters();
if (objParams == null)
{
return;
}
var diffX = objParams.RightBorder() - FieldWidth;
if (Math.abs(diffX) > GetStep())
{
if (diffX > 0)
{
MoveLeft();
}
else
{
MoveRight();
}
}
var diffY = objParams.DownBorder() - FieldHeight;
if (Math.abs(diffY) > GetStep())
{
if (diffY > 0)
{
MoveUp();
}
else
{
MoveDown();
}
}
}
}

View File

@ -0,0 +1,51 @@
package AirplaneWithRadar.MovementStrategy;
public class MoveToCenter extends AbstractStrategy {
@Override
protected boolean IsTargetDestinaion()
{
ObjectParameters objParams = GetObjectParameters();
if (objParams == null) {
return false;
}
return (objParams.ObjectMiddleHorizontal() <= FieldWidth / 2 && objParams.ObjectMiddleHorizontal() + GetStep() >= FieldWidth / 2 &&
objParams.ObjectMiddleVertical() <= FieldHeight / 2 && objParams.ObjectMiddleVertical() + GetStep() >= FieldHeight / 2);
}
@Override
protected void MoveToTarget()
{
ObjectParameters objParams = GetObjectParameters();
if (objParams == null)
{
return;
}
float diffX = objParams.ObjectMiddleHorizontal() - FieldWidth / 2;
if (Math.abs(diffX) > GetStep())
{
if (diffX > 0)
{
MoveLeft();
}
else
{
MoveRight();
}
}
float diffY = objParams.ObjectMiddleVertical() - FieldHeight / 2;
if (Math.abs(diffY) > GetStep())
{
if (diffY > 0)
{
MoveUp();
}
else
{
MoveDown();
}
}
}
}

View File

@ -0,0 +1,7 @@
package AirplaneWithRadar.MovementStrategy;
public enum Movement {
Up,
Down,
Left,
Right
}

View File

@ -0,0 +1,39 @@
package AirplaneWithRadar.MovementStrategy;
public class ObjectParameters {
private final int x;
private final int y;
private final int width;
private final int height;
public int LeftBorder() {
return x;
}
public int TopBorder() {
return y;
}
public int RightBorder() {
return x + width;
}
public int DownBorder() {
return y + height;
}
public int ObjectMiddleHorizontal() {
return x + width / 2;
}
public int ObjectMiddleVertical() {
return y + height / 2;
}
public ObjectParameters(int x, int y, int width, int height) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
}
}

View File

@ -0,0 +1,34 @@
package AirplaneWithRadar.MovementStrategy;
import AirplaneWithRadar.PaintObjects.PaintAirplane;
public class PaintObjectAirplane implements IMoveableObject {
private final PaintAirplane paintAirplane;
public PaintObjectAirplane(PaintAirplane paintAirplane) {
this.paintAirplane = paintAirplane;
}
public ObjectParameters GetObjectPosition() {
if (paintAirplane == null || paintAirplane.airplaneEntity == null) {
return null;
}
return new ObjectParameters(paintAirplane.GetPosX(), paintAirplane.GetPosY(), paintAirplane.GetWidth(), paintAirplane.GetHeight());
}
public int GetStep() {
if (paintAirplane == null || paintAirplane.airplaneEntity == null) return 0;
return (int) (paintAirplane.airplaneEntity.Step);
}
public boolean CheckCanMove(Movement dir) {
if (paintAirplane == null)
return false;
return paintAirplane.CanMove(dir);
}
public void MoveObject(Movement dir) {
if (paintAirplane != null)
paintAirplane.Move(dir);
}
}

View File

@ -0,0 +1,7 @@
package AirplaneWithRadar.MovementStrategy;
public enum Status {
NotInit,
InProgress,
Finish
}

View File

@ -0,0 +1,7 @@
package AirplaneWithRadar.PaintObjects;
import java.awt.Graphics;
import java.awt.Color;
public interface IPaintIlluminators {
public void setCount(int Count);
public void drawIlluminators(Graphics g, Color BodyColor, int StartPosX, int StartPosY);
}

View File

@ -0,0 +1,198 @@
package AirplaneWithRadar.PaintObjects;
import AirplaneWithRadar.Entities.AirplaneEntity;
import AirplaneWithRadar.MovementStrategy.Movement;
import java.awt.*;
import java.util.Random;
public class PaintAirplane {
public AirplaneEntity getAirplaneEntity() {
return airplaneEntity;
}
private void setAirplaneEntity(AirplaneEntity airplaneEntity) {
this.airplaneEntity = airplaneEntity;
}
public AirplaneEntity airplaneEntity;
private int pictWidth;
private int pictHeight;
protected int startPosX;
protected int startPosY;
protected int planeWidth = 140;
protected int planeHeight = 60;
public IPaintIlluminators paintIlluminators;
public int GetPosX() {return startPosX;}
public int GetPosY() {return startPosY;}
public int GetWidth() {return planeWidth;}
public int GetHeight() {return planeHeight;}
public boolean CanMove(Movement dir)
{
if (airplaneEntity == null)
{
return false;
}
switch (dir)
{
case Left:
return startPosX - airplaneEntity.Step > 0;
case Up:
return startPosY - airplaneEntity.Step > 0;
case Right:
return startPosX + planeWidth + airplaneEntity.Step < pictWidth;
case Down:
return startPosY + planeHeight + airplaneEntity.Step < pictHeight;
default:
return false;
}
}
public PaintAirplane(int speed, double weight, Color mainColor, int width, int height) {
if (planeWidth > width || planeHeight > height) {
return;
}
pictHeight = height;
pictWidth = width;
airplaneEntity = new AirplaneEntity(speed, weight, mainColor);
Random Random = new Random();
int paintIlluminatorsVariant = Random.nextInt(1, 4);
switch (paintIlluminatorsVariant) {
case 1:
paintIlluminators = new PaintIlluminators();
break;
case 2:
paintIlluminators = new PaintRectangleIlluminators();
break;
case 3:
paintIlluminators = new PaintRoundedRectIlluminator();
break;
default:
break;
}
paintIlluminators.setCount(Random.nextInt(6, 35));
}
protected PaintAirplane(int speed, double weight, Color bodyColor, int width, int height, int planeWidth, int planeHeight)
{
if (this.planeWidth > width || this.planeHeight > height) { return; }
pictHeight = height;
pictWidth = width;
this.planeWidth = planeWidth;
this.planeHeight = planeHeight;
airplaneEntity = new AirplaneEntity(speed, weight, bodyColor);
paintIlluminators = new PaintIlluminators();
Random rnd = new Random();
paintIlluminators.setCount(rnd.nextInt(6, 35));
}
public void SetPosition(int x, int y) {
if (x + planeWidth < pictWidth && y + planeHeight < pictHeight) {
startPosX = x;
startPosY = y;
} else {
if (x > pictWidth) {
while (x + planeWidth > pictWidth) {
x -= 1;
}
}
if (y > pictWidth) {
while (y + planeHeight > pictHeight) {
y -= 1;
}
}
}
}
public void Move(Movement dir) {
if (airplaneEntity == null) {
return;
}
switch (dir) {
case Left:
if (startPosX - airplaneEntity.Step > 0) {
startPosX -= (int) airplaneEntity.Step;
}
break;
case Up:
if (startPosY - airplaneEntity.Step > 0) {
startPosY -= (int) airplaneEntity.Step;
}
break;
case Right:
if (startPosX + planeWidth + airplaneEntity.Step < pictWidth) {
startPosX += (int) airplaneEntity.Step;
}
break;
case Down:
if (startPosY + planeHeight + airplaneEntity.Step < pictHeight) {
startPosY += (int) airplaneEntity.Step;
}
break;
}
}
public void DrawTransport(Graphics g) {
if (airplaneEntity == null) {
return;
}
//основа
g.setColor(Color.BLACK);
g.drawLine(startPosX + planeWidth / 44, startPosY + planeHeight / 2, startPosX + planeWidth - planeWidth / 6, startPosY + planeHeight / 2);
g.drawLine(startPosX + planeWidth / 44, startPosY + planeHeight - planeHeight / 8, startPosX + planeWidth - planeWidth / 6, startPosY + planeHeight - planeHeight / 8);
g.setColor(airplaneEntity.getBodyColor());
g.fillRect(startPosX + planeWidth / 44, startPosY + planeHeight / 2, planeWidth - 2 * planeWidth / 11, planeHeight / 2 - planeHeight / 8);
g.fillOval(startPosX, startPosY + planeHeight / 2, planeWidth / 24, planeHeight / 2 - planeHeight / 8);
g.setColor(Color.BLACK);
g.drawArc(startPosX, startPosY + planeHeight / 2, planeWidth / 24, planeHeight / 2 - planeHeight / 8, 90, 180);
DrawTriangle(g,
startPosX + planeWidth - planeWidth / 6, startPosY + planeHeight / 2, // 1
startPosX + planeWidth, startPosY + 5 * planeHeight / 7, // 2
startPosX + planeWidth - planeWidth / 6, startPosY + planeHeight - planeHeight / 8); // 3
DrawTriangle(g,
startPosX, startPosY, // 1
startPosX + planeWidth / 4, startPosY + planeHeight / 2, // 2
startPosX, startPosY + planeHeight / 2); // 3
g.drawLine(startPosX + planeWidth - planeWidth / 6, startPosY + 5 * planeHeight / 7,
startPosX + planeWidth, startPosY + 5 * planeHeight / 7);
// колеса
g.drawLine(startPosX + planeWidth / 4, startPosY + planeHeight - planeHeight / 8,
startPosX + planeWidth / 4, startPosY + planeHeight - planeHeight / 11);
g.drawLine(startPosX + planeWidth - 2 * planeWidth / 9, startPosY + planeHeight - planeHeight / 8,
startPosX + planeWidth - 2 * planeWidth / 9, startPosY + planeHeight - planeHeight / 11);
g.drawOval(startPosX + planeWidth / 4 - planeWidth / 23, startPosY + 11 * planeHeight / 12,
planeHeight / 12, planeHeight / 12);
g.drawOval(startPosX + planeWidth / 4 + planeWidth / 72, startPosY + 11 * planeHeight / 12,
planeHeight / 12, planeHeight / 12);
g.drawOval(startPosX + planeWidth - 5 * planeWidth / 21, startPosY + 11 * planeHeight / 12,
planeHeight / 12, planeHeight / 12);
g.setColor(Color.BLACK);
g.fillRoundRect(startPosX + 2 * planeWidth / 9, startPosY + planeHeight / 2 + planeHeight / 7, planeWidth / 2, planeHeight / 7, 5, 5);
g.fillRoundRect(startPosX, startPosY + planeHeight / 2 - planeHeight / 9, planeWidth / 5, planeHeight / 6, 5, 5);
paintIlluminators.drawIlluminators(g, airplaneEntity.getBodyColor().darker(), startPosX, startPosY);
}
private void DrawTriangle(Graphics g, int x1, int y1, int x2, int y2, int x3, int y3)
{
g.drawLine(x1, y1, x2, y2);
g.drawLine(x2, y2, x3, y3);
g.drawLine(x3, y3, x1, y1);
}
}

View File

@ -0,0 +1,39 @@
package AirplaneWithRadar.PaintObjects;
import AirplaneWithRadar.Entities.AirplaneWithRadarEntity;
import java.awt.*;
public class PaintAirplaneWithRadar extends PaintAirplane {
public PaintAirplaneWithRadar(int speed, double weight, Color mainColor, Color additColor, boolean radarOnBoard, boolean additFuelPod, int width, int height)
{
super(speed, weight, mainColor, width, height, 140, 60);
if (planeWidth > width || planeHeight > height) { return; }
if (airplaneEntity != null)
{
airplaneEntity = new AirplaneWithRadarEntity(speed, weight, mainColor, additColor, radarOnBoard, additFuelPod);
}
}
@Override
public void DrawTransport(Graphics g)
{
if (!(airplaneEntity instanceof AirplaneWithRadarEntity airplaneWithRadarEntity))
{
return;
}
super.DrawTransport(g);
g.setColor(airplaneWithRadarEntity.getAdditColor());
if (airplaneWithRadarEntity.RadarOnBoard) {
g.setColor(airplaneWithRadarEntity.getAdditColor());
g.drawLine(startPosX + planeWidth / 3, startPosY + planeHeight / 2, startPosX + planeWidth / 3, startPosY + planeHeight / 3);
g.fillArc(startPosX + planeWidth / 4, startPosY + planeHeight / 10, planeWidth / 6, planeHeight / 4, -30, -180);
}
if (airplaneWithRadarEntity.AdditFuelPod)
{
g.setColor(airplaneWithRadarEntity.getAdditColor());
g.fillRoundRect(startPosX, startPosY + planeHeight - 2*planeHeight / 5, planeWidth / 5, planeHeight / 6, 5, 5);
}
}
}

View File

@ -0,0 +1,47 @@
package AirplaneWithRadar.PaintObjects;
import AirplaneWithRadar.IlluminatorsCount;
import java.awt.Graphics;
import java.awt.Color;
public class PaintIlluminators implements IPaintIlluminators{
private IlluminatorsCount count;
public void setCount(int Count) {
if (Count <= 10)
this.count = IlluminatorsCount.Ten;
else if (Count <= 20) {
this.count = IlluminatorsCount.Twenty;
}
else
this.count = IlluminatorsCount.Thirty;
}
public void drawIlluminators(Graphics g, Color color, int startPosX, int startPosY) {
g.setColor(color);
int x = startPosX;
for (int i = 0; i < 10; i++) {
g.fillOval(x + 34, startPosY + 30, 7, 7);
x += 8;
}
if (count == IlluminatorsCount.Ten) return;
x = startPosX;
for (int i = 0; i < 10; i++) {
g.fillOval(x + 34, startPosY + 38, 7, 7);
x += 8;
}
if (count == IlluminatorsCount.Twenty) return;
x = startPosX;
for (int i = 0; i < 10; i++) {
g.fillOval(x + 34, startPosY + 46, 7, 7);
x += 8;
}
}
}

View File

@ -0,0 +1,46 @@
package AirplaneWithRadar.PaintObjects;
import AirplaneWithRadar.IlluminatorsCount;
import java.awt.*;
public class PaintRectangleIlluminators implements IPaintIlluminators {
private IlluminatorsCount count;
public void setCount(int Count) {
if (Count <= 10)
this.count = IlluminatorsCount.Ten;
else if (Count <= 20) {
this.count = IlluminatorsCount.Twenty;
}
else
this.count = IlluminatorsCount.Thirty;
}
public void drawIlluminators(Graphics g, Color color, int startPosX, int startPosY) {
g.setColor(color);
int x = startPosX;
for (int i = 0; i < 10; i++) {
g.fillRect(x + 34, startPosY + 30, 6, 5);
x += 7;
}
if (count == IlluminatorsCount.Ten) return;
x = startPosX;
for (int i = 0; i < 10; i++) {
g.fillRect(x + 34, startPosY + 38, 6, 5);
x += 7;
}
if (count == IlluminatorsCount.Twenty) return;
x = startPosX;
for (int i = 0; i < 10; i++) {
g.fillRect(x + 34, startPosY + 46, 6, 5);
x += 7;
}
}
}

View File

@ -0,0 +1,46 @@
package AirplaneWithRadar.PaintObjects;
import AirplaneWithRadar.IlluminatorsCount;
import java.awt.*;
public class PaintRoundedRectIlluminator implements IPaintIlluminators {
private IlluminatorsCount count;
public void setCount(int Count) {
if (Count <= 10)
this.count = IlluminatorsCount.Ten;
else if (Count <= 20) {
this.count = IlluminatorsCount.Twenty;
}
else
this.count = IlluminatorsCount.Thirty;
}
public void drawIlluminators(Graphics g, Color color, int startPosX, int startPosY) {
g.setColor(color);
int x = startPosX;
for (int i = 0; i < 10; i++) {
g.fillRoundRect(x + 34, startPosY + 30, 6, 6,2,2);
x += 8;
}
if (count == IlluminatorsCount.Ten) return;
x = startPosX;
for (int i = 0; i < 10; i++) {
g.fillRoundRect(x + 34, startPosY + 38, 6, 6,2,2);
x += 8;
}
if (count == IlluminatorsCount.Twenty) return;
x = startPosX;
for (int i = 0; i < 10; i++) {
g.fillRoundRect(x + 34, startPosY + 46, 6, 6,2,2);
x += 8;
}
}
}